1 package de.spring.webservices.rest.business;
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;
8 import java.util.ArrayList;
11 import org.junit.Before;
12 import org.junit.Test;
14 import de.spring.webservices.domain.Car;
15 import de.spring.webservices.rest.client.CarClientService;
17 public class BusinessServiceTest {
19 private CarClientService carClientService;
20 private BusinessService businessService;
23 public void createTest() {
24 carClientService = mock(CarClientService.class);
25 businessService = new BusinessService(carClientService);
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);
37 businessService.doSomethingWithCars();
39 verify(carClientService, times(1)).doGetCars();
44 public void whenDoSomethingWithOneCarhenInvokeDoGetCar() {
46 Car expected = new Car(66L, "test");
48 when(carClientService.doGetCar(id)).thenReturn(expected);
50 businessService.doSomethingWithCar(id);
52 verify(carClientService, times(1)).doGetCar(id);