diff options
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java')
-rw-r--r-- | src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java new file mode 100644 index 0000000..17c0a47 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java @@ -0,0 +1,67 @@ +package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service; + +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDAO; +import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDatabaseDAO; +import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee.EducationLevel; +import java.time.LocalDate; +import org.junit.Assert; +import org.junit.Test; + +public class EmployeeServiceTest { + + private final EmployeeDAO employeePersistence = mock(EmployeeDatabaseDAO.class); + private final EmployeeService employeeService = new EmployeeServiceImpl(employeePersistence); + + private final Employee.Builder employeeBuilder = + Employee.builder() + .name("Testperson") + .birthday(LocalDate.parse("1996-10-10")) + .educationLevel(EducationLevel.NKA) + .isDriver(true) + .isPilot(false); + + public EmployeeServiceTest() throws PersistenceException { + when(employeePersistence.add(any())).thenReturn(1L); + } + + @Test + public void testAddValidEmployee() throws ServiceException, InvalidEmployeeException { + + Employee employee = employeeBuilder.build(); + Assert.assertThat(employeeService.add(employee), is(1L)); + } + + @Test(expected = InvalidEmployeeException.class) + public void testAddInvalidEmployee() throws InvalidEmployeeException, ServiceException { + + Employee employee = employeeBuilder.name("").build(); + employeeService.add(employee); + } + + @Test + public void testUpdateValidEmployee() throws ElementNotFoundException, PersistenceException { + + Employee employee = employeeBuilder.build(); + employeePersistence.update(employee); + } + + @Test(expected = ElementNotFoundException.class) + public void testUpdateNonExistentEmployee() + throws ElementNotFoundException, PersistenceException { + + doThrow(ElementNotFoundException.class).when(employeePersistence).update(any()); + Employee employee = employeeBuilder.id(1000).build(); + employeePersistence.update(employee); + } +} |