3910f0b4939e9a810d25e9ef49face342eff7c3c
[JavaForFun] /
1 package de.spring.webservices.rest.business;
2
3 import static org.mockito.Mockito.mock;
4 import static org.mockito.Mockito.times;
5 import static org.mockito.Mockito.verify;
6 import static org.mockito.Mockito.when;
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import org.junit.Before;
12 import org.junit.Test;
13
14 import de.spring.webservices.domain.Car;
15 import de.spring.webservices.rest.client.CarClientService;
16
17 public class BusinessServiceTest {
18
19         private CarClientService carClientService;
20         private BusinessService businessService;
21         
22     @Before
23     public void createTest() {
24         carClientService = mock(CarClientService.class);
25         businessService = new BusinessService(carClientService);        
26     }
27     
28         @Test
29         public void whenDoSomethingWithCarsThenInvokeDoGetCars() {
30                 Car expectedOne = new Car(66L, "test");
31                 Car expectedTwo = new Car(99L, "example");
32                 List<Car> expected = new ArrayList<>();
33                 expected.add(expectedOne);
34                 expected.add(expectedTwo);
35                 when(carClientService.doGetCars()).thenReturn(expected);
36                 
37                 businessService.doSomethingWithCars();
38                 
39                 verify(carClientService, times(1)).doGetCars();
40         }
41
42     
43         @Test
44         public void whenDoSomethingWithOneCarhenInvokeDoGetCar() {
45                 Long id = 66L;
46                 Car expected = new Car(66L, "test");
47                 
48                 when(carClientService.doGetCar(id)).thenReturn(expected);
49                 
50                 businessService.doSomethingWithCar(id);
51                 
52                 verify(carClientService, times(1)).doGetCar(id);
53         }
54 }