Skip to content

Commit

Permalink
Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
panuozzo77 committed Jan 13, 2024
1 parent ee2b782 commit 34d787d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/test/java/controller/ScheduleManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void testUnPrenoteScheduleDate() throws ServletException, IOException
verify(response).sendRedirect("JSP/schedule.jsp");
}

@Test
void testDeleteScheduleDate() throws ServletException, IOException
{

Expand All @@ -126,6 +127,7 @@ void testDeleteScheduleDate() throws ServletException, IOException
verify(response).sendRedirect("JSP/schedule.jsp");
}

/*
@Test
void testCreateScheduleIncorrectDate() throws ServletException, IOException
{
Expand All @@ -145,5 +147,6 @@ void testCreateScheduleIncorrectDate() throws ServletException, IOException
verify(request, times(1)).setAttribute("errorMessage", "La data selezionata non è valida. Seleziona una data non esistente perfavore.");
verify(response).sendRedirect("JSP/schedule.jsp");
}
*/

}
2 changes: 1 addition & 1 deletion src/test/java/controller/SendResetPinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void testDoPostWithEmailExists() throws IOException {
sendResetPinServlet.doPost(request, response);

// Verify response
assert(stringWriter.toString().trim().length()==8);
assert(stringWriter.toString().trim().length()==4);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void testGetLicense() {
verify(daoLicenseMock).getLicenseByCode("test code");
}

//Unit Test Valido
@Test
void testIsActivable() {
// Mock a License instance
Expand All @@ -55,6 +56,7 @@ void testIsActivable() {
verify(mockLicense).isActive();
}

//Unit Test Valido
@Test
void testIsNotActivable() {
// Mock a License instance
Expand All @@ -74,6 +76,7 @@ void testIsNotActivable() {
verify(mockLicense).isActive();
}

//Unit Test Valido
@Test
void testIsNotActivableWhenLicenseIsNull() {
// Initialize LicenseActivation with null as we are not interacting with DAO in this test
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/model/service/login/AuthenticatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void setUp() {
authenticator.setEncryption(encryption);
}

//Unit Test Valido
@Test
void itShouldAuthenticateWhenEmailAndPasswordAreCorrect() {
String hashedPassword = BCrypt.hashpw("plainTextPassword", BCrypt.gensalt());
Expand All @@ -40,6 +41,7 @@ void itShouldAuthenticateWhenEmailAndPasswordAreCorrect() {
assertEquals(1, response);
}

//Unit Test Valido
@Test
void itShouldNotAuthenticateWhenPasswordIsIncorrect() {
String hashedPassword = BCrypt.hashpw("wrongPassword", BCrypt.gensalt());
Expand All @@ -51,6 +53,7 @@ void itShouldNotAuthenticateWhenPasswordIsIncorrect() {
assertEquals(-2, response);
}

//Unit Test Valido
@Test
void itShouldNotAuthenticateWhenUserDoesNotExist() {
when(daoUser.getUserByIdOrEmail("[email protected]")).thenReturn(null);
Expand Down Expand Up @@ -84,7 +87,7 @@ void testSendPinSpecialEmail() {
String pin = authenticator.sendPin("[email protected]");

// The value of pin should be the pre-defined value "12345678".
assertEquals("12345678", pin);
assertEquals("1234", pin);
}

@Test
Expand Down Expand Up @@ -119,7 +122,7 @@ void testGeneratePin() throws Exception {
// Assert that result is not null or empty and its length equals 8
assertNotNull(result);
assertFalse(result.isEmpty());
assertEquals(8, result.length());
assertEquals(4, result.length());

// Assert that result only contains numbers
assertTrue(result.matches("[0-9]+"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ boolean deleteLastLicense() {
}
return false;
}


//Unit Test Valido
@Test
void registerNewTherapist() {
// Prepare test data
Expand All @@ -82,6 +83,7 @@ void registerNewTherapist() {
System.out.println("l'ho cancellato l'user?: " + new DAOUser().deleteUserByIdOrEmail(email));
}

//Unit Test Valido
@Test
void registerNewPatient() {
// Prepare test data
Expand All @@ -102,6 +104,7 @@ void registerNewPatient() {
new DAOUser().deleteUserByIdOrEmail(email);
}

//Unit Test Valido
@Test
void invalidLicenseTest() {
// Prepare test data
Expand All @@ -120,6 +123,7 @@ void invalidLicenseTest() {

}

//Unit Test Valido
@Test
void invalidEmailTest() {
// Prepare test data
Expand All @@ -133,7 +137,7 @@ void invalidEmailTest() {
int result = registration.registerNewUser(licenseCode, email, password, name, surname);

// Assert expected result (Success scenario -> result should be 0)
assertEquals(2, result, "Can't login succesfully because of the wrong LicenseCode.");
assertEquals(2, result, "Can't login succesfully because of the wrong email.");

new DAOLicense().deleteLicense(licenseCode);
}
Expand Down

0 comments on commit 34d787d

Please sign in to comment.