Skip to content

Commit

Permalink
started course creation tests (cannot get presenter not controller to…
Browse files Browse the repository at this point in the history
… work rip), still need to test for persistence as well as the enrolment tests too
  • Loading branch information
jltng committed Dec 7, 2022
1 parent cfcdcc2 commit d567611
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 118 deletions.
6 changes: 4 additions & 2 deletions src/main/java/screens/course_features/InMemoryCourse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import entities.Course;
import use_cases.course_features.course_creation_use_case.CourseCreationDsGateway;
import use_cases.course_features.course_creation_use_case.CourseCreationRequestModel;
import use_cases.course_features.course_enrolment_use_case.CourseEnrolmentDsGateway;


Expand All @@ -13,8 +12,11 @@
import java.util.HashMap;
import java.util.Map;

/**
* gateway for testing purposes
*/
public class InMemoryCourse implements CourseCreationDsGateway, CourseEnrolmentDsGateway {
private Map<String, Course> courses;
private Map<String, Course> courses = new HashMap<>();

public InMemoryCourse() {
this.courses = new HashMap<>();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,64 +1,19 @@
package test_course_features;

//import entities.Course;
//import entities.StudentUser;
//import org.junit.jupiter.api.Assertions;
//import org.junit.jupiter.api.Test;
//import screens.course_features.InMemoryCourse;
//import screens.login_registration.InMemoryUser;
//import use_cases.course_features.course_creation_use_case.CourseCreationDsGateway;
//import use_cases.login_registration.user_register_usecase.UserRegGateway;
//
//import use_cases.course_features.course_enrolment_use_case.*;
//
//import java.util.ArrayList;
//
//import static org.junit.Assert.*;
//
///**
// * TODO: NEED TO ADD THE TASK PART
// */
//class CourseEnrolmentInteractorTest {
//
// @Test
// public void enrol() {
// // well technically interactor not done so ......
//
// CourseEnrolmentDsGateway courseGateway = new InMemoryCourse();
// CourseCreationDsGateway courseRepository = new InMemoryCourse();
// UserRegGateway userRepository = new InMemoryUser();
//
// CourseEnrolmentOutputBoundary outputBoundary = new CourseEnrolmentOutputBoundary() {
// @Override
// public CourseEnrolmentResponseModel prepareSuccessView(CourseEnrolmentResponseModel newStudent) {
// Assertions.assertEquals("course1inst1", newStudent.getCourseID());
// Assertions.assertEquals("user1", newStudent.getStudentID());
// Assertions.assertTrue(courseRepository.existsByCourseID("course1inst1"));
// Assertions.assertTrue(userRepository.existsByName("user1"));
// return null;
// }
//
// @Override
// public CourseEnrolmentResponseModel prepareFailView(String error) {
// fail("Use case failure is unexpected.");
// return null;
// }
// };
//
// // make course
// ArrayList<String> tasks = new ArrayList<>();
// tasks.add("task1");
// tasks.add("task2");
// Course course = new Course("course1", "inst1", tasks);
//
// // make student
// StudentUser student = new StudentUser("user1", "pass1");
//
// CourseEnrolmentInputBoundary interactor = new CourseEnrolmentInteractor(courseGateway, outputBoundary);
//
// CourseEnrolmentRequestModel inputData = new CourseEnrolmentRequestModel(
// "course1", "inst1", "user1");
//
// interactor.enrol(inputData);
// }
//}
import entities.Course;
import org.junit.jupiter.api.Test;
import screens.course_features.InMemoryCourse;
import use_cases.course_features.course_creation_use_case.*;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;

/**
* testing the components of a course enrolment
* which is basically every line of code in my interactor because clearly there are buuuuugs
* acc maybe this is why i should be doing tests while i code oop
*/
public class CourseEnrolmentInteractorTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package test_course_features.course_creation;

import entities.Course;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import screens.course_features.CourseCreationController;
import screens.course_features.CourseCreationFailed;
import screens.course_features.CourseCreationPresenter;
import use_cases.course_features.course_creation_use_case.*;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

public class CourseCreationControllerTest {
private CourseCreationController controller;

@BeforeAll
static void setUp() {
CourseCreationDsGateway gateway = new CourseCreationDsGateway() {
@Override
public boolean existsByCourseID(String courseIdentifier) {
return false;
}

@Override
public void saveCourse(Course requestModel) throws IOException {

}
};
CourseCreationOutputBoundary presenter = new CourseCreationPresenter();
CourseCreationInputBoundary interactor = new CourseCreationInteractor(gateway, presenter);
CourseCreationController controller = new CourseCreationController(interactor);
}

@Test
void what() {
Exception e;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package test_course_features.course_creation;

import entities.Course;
import org.junit.jupiter.api.Test;
import screens.course_features.InMemoryCourse;
import use_cases.course_features.course_creation_use_case.*;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;


/**
* testing the creation of a new course
*/
class CourseCreationInteractorTest {
@Test
void createCourse() {
InMemoryCourse courseGateway = new InMemoryCourse();

CourseCreationOutputBoundary outputBoundary = new CourseCreationOutputBoundary() {
@Override
public CourseCreationResponseModel prepareSuccessView(CourseCreationResponseModel newCourse) {
ArrayList<String> tasks = new ArrayList<>();
tasks.add("task1");
tasks.add("task2");
tasks.add("task3");
Course course1 = new Course("course1", "inst1", tasks);

assertEquals("course1inst1", course1.getCourseID());
assertEquals(course1.getTasks(), tasks);
assertNotNull(course1.getTasks());
assertTrue(courseGateway.existsByCourseID(course1.getCourseID()));
return null;
}

@Override
public CourseCreationResponseModel prepareFailView(String error) {
fail("Use case failure is unexpected.");
return null;
}
};
ArrayList<String> requestTask = new ArrayList<>();

requestTask.add("task1,task2,task3");
CourseCreationRequestModel request = new CourseCreationRequestModel(
"course1", "inst1", requestTask);
CourseCreationInputBoundary interactor = new CourseCreationInteractor(courseGateway, outputBoundary);

interactor.create(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package test_course_features.course_creation;

//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//import screens.course_features.CourseCreationFailed;
//import screens.course_features.CourseCreationPresenter;
//import use_cases.course_features.course_creation_use_case.CourseCreationResponseModel;
//
//import java.util.ArrayList;
//
//import static org.junit.jupiter.api.Assertions.*;
//
///**
// * testing presenter fail and success views
// * currently failing oop
// */
//class CourseCreationPresenterTest {
// private CourseCreationPresenter presenter;
//
// @BeforeAll
// static void setUp() {
// CourseCreationPresenter presenter = new CourseCreationPresenter();
//
// ArrayList<String> tasks = new ArrayList<>();
// tasks.add("1");
// tasks.add("2");
// tasks.add("3");
// presenter.prepareSuccessView(new CourseCreationResponseModel("id", tasks));
// }
//
// @Test
// void prepareSuccessView() {
// ArrayList<String> tasks = new ArrayList<>();
// tasks.add("1");
// tasks.add("2");
// tasks.add("3");
// CourseCreationResponseModel response = new CourseCreationResponseModel("id", tasks);
// assertEquals(response, presenter.prepareSuccessView(response));
// }
//
// @Test
// void prepareFailView() {
// String error = "hm what should i put here";
// Exception e = assertThrows(CourseCreationFailed.class, () -> presenter.prepareFailView(error));
// assertEquals(error, e.getMessage());
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package test_course_features.course_creation;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import use_cases.course_features.course_creation_use_case.CourseCreationRequestModel;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;

/**
* testing the methods of the request model
*/
class CourseCreationRequestModelTest {
static CourseCreationRequestModel courseCreationRequestModel;

@BeforeAll
static void beforeAll() {
ArrayList<String> badTasks = new ArrayList<>();
badTasks.add("task1,task2,task3");
courseCreationRequestModel = new CourseCreationRequestModel(
"course1", "inst1", badTasks);
}

@Test
void getCourseName() {
assertEquals("course1", courseCreationRequestModel.getCourseName());
}

@Test
void getInstructorName() {
assertEquals("inst1", courseCreationRequestModel.getCourseInstructor());
}

@Test
void getCourseID() {
assertEquals("course1inst1", courseCreationRequestModel.getCourseID());
}

@Test
void getTasks() {
ArrayList<String> goodTasks = new ArrayList<>();
goodTasks.add("task1");
goodTasks.add("task2");
goodTasks.add("task3");
assertEquals(courseCreationRequestModel.getTasks(), goodTasks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package test_course_features.course_creation;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import use_cases.course_features.course_creation_use_case.CourseCreationResponseModel;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;

/**
* testing methods of the response model
*/
public class CourseCreationResponseModelTest {
static CourseCreationResponseModel response;

@BeforeAll
static void beforeAll() {
ArrayList<String> tasks = new ArrayList<>();
tasks.add("task1");
tasks.add("task2");
tasks.add("task3");
response = new CourseCreationResponseModel("id", tasks);
}

@Test
void getCourseID() {
assertEquals("id", response.getCourseID());
}

@Test
void getTasks() {
ArrayList<String> taskTesting = new ArrayList<>();
taskTesting.add("task1");
taskTesting.add("task2");
taskTesting.add("task3");
assertEquals(response.getTasks(), taskTesting);
}
}

0 comments on commit d567611

Please sign in to comment.