import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import de.spring.webservices.domain.Car;
import de.spring.webservices.rest.client.CarClientService;
verify(carClientService, times(1)).doGetCars();
}
-
@Test
public void whenDoSomethingWithOneCarhenInvokeDoGetCar() {
verify(carClientService, times(1)).doGetCar(id);
}
+
+ @Test
+ public void whenCreateNewCarThenCreateNewOne() {
+ Car expected = new Car(66L, "test");
+ ArgumentCaptor<Car> argCar = ArgumentCaptor.forClass(Car.class);
+
+ when(carClientService.doNewCar(argCar.capture())).thenReturn(expected);
+
+ businessService.createsNewCar();
+
+ verify(carClientService, times(1)).doNewCar(argCar.getValue());
+ }
}
@Test
public void whenGetAllCarsThenRetrieveRequestedCars() throws JsonProcessingException {
Car expectedOne = new Car(66L, "test");
- Car expectedTwo = new Car(99L, "example");
List<Car> expected = new ArrayList<>();
expected.add(expectedOne);
- expected.add(expectedTwo);
mockServer.expect(requestTo(apiCarsUrl))
.andExpect(method(HttpMethod.GET))
mockServer.verify();
- assertEquals(2, cars.size());
+ assertEquals(1, cars.size());
assertEquals(expectedOne, cars.get(0));
- assertEquals(expectedTwo, cars.get(1));
}
@Test