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;
13 import org.mockito.ArgumentCaptor;
15 import de.spring.webservices.domain.Car;
16 import de.spring.webservices.rest.client.CarClientService;
18 public class BusinessServiceTest {
20 private CarClientService carClientService;
21 private BusinessService businessService;
24 public void createTest() {
25 carClientService = mock(CarClientService.class);
26 businessService = new BusinessService(carClientService);
30 public void whenDoSomethingWithCarsThenInvokeDoGetCars() {
31 Car expectedOne = new Car(66L, "test");
32 Car expectedTwo = new Car(99L, "example");
33 List<Car> expected = new ArrayList<>();
34 expected.add(expectedOne);
35 expected.add(expectedTwo);
36 when(carClientService.doGetCars()).thenReturn(expected);
38 businessService.doSomethingWithCars();
40 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);
56 public void whenCreateNewCarThenCreateNewOne() {
57 Car expected = new Car(66L, "test");
58 ArgumentCaptor<Car> argCar = ArgumentCaptor.forClass(Car.class);
60 when(carClientService.doNewCar(argCar.capture())).thenReturn(expected);
62 businessService.createsNewCar();
64 verify(carClientService, times(1)).doNewCar(argCar.getValue());