diff --git a/CACoding.iml b/CACoding.iml
index 69623856..b3e930f2 100644
--- a/CACoding.iml
+++ b/CACoding.iml
@@ -4,9 +4,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/entity/CommonUserTest.java b/test/entity/CommonUserTest.java
new file mode 100644
index 00000000..763a3496
--- /dev/null
+++ b/test/entity/CommonUserTest.java
@@ -0,0 +1,27 @@
+package entity;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import java.time.LocalDateTime;
+import static org.junit.jupiter.api.Assertions.*;
+
+class CommonUserTest {
+
+ private CommonUser user;
+
+ @BeforeEach
+ void init() {
+ user = new CommonUser("Paul", "password", LocalDateTime.now());
+ }
+
+ @Test
+ void getNameTest() {
+ assertEquals("Paul", user.getName());
+ }
+
+ @Test
+ void getPasswordTest() {
+ assertEquals("password", user.getPassword());
+ }
+
+}
\ No newline at end of file
diff --git a/test/entity/ExceptionDemoTest.java b/test/entity/ExceptionDemoTest.java
new file mode 100644
index 00000000..ef17367d
--- /dev/null
+++ b/test/entity/ExceptionDemoTest.java
@@ -0,0 +1,28 @@
+package entity;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDateTime;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class Calculator {
+ public void divide(int i, int j) {
+ int result = i / j;
+ }
+}
+class ExceptionDemoTest {
+ @Test
+ void exceptionTest() {
+ Calculator calculator = new Calculator();
+ // Assert that the calculator.divide call throws an exception
+ Exception exception = assertThrows(
+ ArithmeticException.class,
+ // This is an anonymous method that gets called by the assertThrows method
+ () -> calculator.divide(1, 0)
+ );
+ assertEquals("/ by zero", exception.getMessage());
+ }
+}
\ No newline at end of file
diff --git a/test/use_case/signup/SignupInteractorTest.java b/test/use_case/signup/SignupInteractorTest.java
new file mode 100644
index 00000000..d2c2b36e
--- /dev/null
+++ b/test/use_case/signup/SignupInteractorTest.java
@@ -0,0 +1,90 @@
+package use_case.signup;
+
+import data_access.InMemoryUserDataAccessObject;
+import entity.CommonUserFactory;
+import entity.User;
+import entity.UserFactory;
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDateTime;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class SignupInteractorTest {
+
+ @Test
+ void successTest() {
+ SignupInputData inputData = new SignupInputData("Paul", "password", "password");
+ SignupUserDataAccessInterface userRepository = new InMemoryUserDataAccessObject();
+
+ // This creates a successPresenter that tests whether the test case is as we expect.
+ SignupOutputBoundary successPresenter = new SignupOutputBoundary() {
+ @Override
+ public void prepareSuccessView(SignupOutputData user) {
+ // 2 things to check: the output data is correct, and the user has been created in the DAO.
+ assertEquals("Paul", user.getUsername());
+ assertNotNull(user.getCreationTime()); // any creation time is fine.
+ assertTrue(userRepository.existsByName("Paul"));
+ }
+
+ @Override
+ public void prepareFailView(String error) {
+ fail("Use case failure is unexpected.");
+ }
+ };
+
+ SignupInputBoundary interactor = new SignupInteractor(userRepository, successPresenter, new CommonUserFactory());
+ interactor.execute(inputData);
+ }
+
+ @Test
+ void failurePasswordMismatchTest() {
+ SignupInputData inputData = new SignupInputData("Paul", "password", "wrong");
+ SignupUserDataAccessInterface userRepository = new InMemoryUserDataAccessObject();
+
+ // This creates a presenter that tests whether the test case is as we expect.
+ SignupOutputBoundary failurePresenter = new SignupOutputBoundary() {
+ @Override
+ public void prepareSuccessView(SignupOutputData user) {
+ // 2 things to check: the output data is correct, and the user has been created in the DAO.
+ fail("Use case success is unexpected.");
+ }
+
+ @Override
+ public void prepareFailView(String error) {
+ assertEquals("Passwords don't match.", error);
+ }
+ };
+
+ SignupInputBoundary interactor = new SignupInteractor(userRepository, failurePresenter, new CommonUserFactory());
+ interactor.execute(inputData);
+ }
+
+ @Test
+ void failureUserExistsTest() {
+ SignupInputData inputData = new SignupInputData("Paul", "password", "wrong");
+ SignupUserDataAccessInterface userRepository = new InMemoryUserDataAccessObject();
+
+ // Add Paul to the repo so that when we check later they already exist
+ UserFactory factory = new CommonUserFactory();
+ User user = factory.create("Paul", "pwd", LocalDateTime.now());
+ userRepository.save(user);
+
+ // This creates a presenter that tests whether the test case is as we expect.
+ SignupOutputBoundary failurePresenter = new SignupOutputBoundary() {
+ @Override
+ public void prepareSuccessView(SignupOutputData user) {
+ // 2 things to check: the output data is correct, and the user has been created in the DAO.
+ fail("Use case success is unexpected.");
+ }
+
+ @Override
+ public void prepareFailView(String error) {
+ assertEquals("User already exists.", error);
+ }
+ };
+
+ SignupInputBoundary interactor = new SignupInteractor(userRepository, failurePresenter, new CommonUserFactory());
+ interactor.execute(inputData);
+ }
+}
\ No newline at end of file