blob: 17c0a4744c584653ced5ac170656a3abb9cc37bf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
}
}
|