|
1 | 1 | package org.baeldung.demo.boottest; |
2 | 2 |
|
3 | | -import org.baeldung.demo.boottest.Employee; |
4 | | -import org.baeldung.demo.boottest.EmployeeRepository; |
5 | | -import org.baeldung.demo.boottest.EmployeeService; |
6 | | -import org.baeldung.demo.boottest.EmployeeServiceImpl; |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Optional; |
| 8 | + |
7 | 9 | import org.junit.Before; |
8 | 10 | import org.junit.Test; |
9 | 11 | import org.junit.runner.RunWith; |
|
15 | 17 | import org.springframework.context.annotation.Bean; |
16 | 18 | import org.springframework.test.context.junit4.SpringRunner; |
17 | 19 |
|
18 | | -import java.util.Arrays; |
19 | | -import java.util.List; |
20 | | - |
21 | | -import static org.assertj.core.api.Assertions.assertThat; |
22 | | - |
23 | 20 | @RunWith(SpringRunner.class) |
24 | 21 | public class EmployeeServiceImplIntegrationTest { |
25 | 22 |
|
@@ -50,9 +47,9 @@ public void setUp() { |
50 | 47 | Mockito.when(employeeRepository.findByName(john.getName())).thenReturn(john); |
51 | 48 | Mockito.when(employeeRepository.findByName(alex.getName())).thenReturn(alex); |
52 | 49 | Mockito.when(employeeRepository.findByName("wrong_name")).thenReturn(null); |
53 | | - Mockito.when(employeeRepository.findById(john.getId()).orElse(null)).thenReturn(john); |
| 50 | + Mockito.when(employeeRepository.findById(john.getId())).thenReturn(Optional.of(john)); |
54 | 51 | Mockito.when(employeeRepository.findAll()).thenReturn(allEmployees); |
55 | | - Mockito.when(employeeRepository.findById(-99L).orElse(null)).thenReturn(null); |
| 52 | + Mockito.when(employeeRepository.findById(-99L)).thenReturn(Optional.empty()); |
56 | 53 | } |
57 | 54 |
|
58 | 55 | @Test |
|
0 commit comments