From: Gustavo Martin Morcuende Date: Thu, 7 Jan 2016 00:13:23 +0000 (+0100) Subject: Spring REST: missing test X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=b880d6b6d0a42e991e18e6d0f0a356da013f3998;p=JavaForFun Spring REST: missing test --- diff --git a/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/business/BusinessServiceTest.java b/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/business/BusinessServiceTest.java index 3910f0b..8d279a6 100644 --- a/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/business/BusinessServiceTest.java +++ b/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/business/BusinessServiceTest.java @@ -10,6 +10,7 @@ import java.util.List; 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; @@ -38,7 +39,6 @@ public class BusinessServiceTest { verify(carClientService, times(1)).doGetCars(); } - @Test public void whenDoSomethingWithOneCarhenInvokeDoGetCar() { @@ -51,4 +51,16 @@ public class BusinessServiceTest { verify(carClientService, times(1)).doGetCar(id); } + + @Test + public void whenCreateNewCarThenCreateNewOne() { + Car expected = new Car(66L, "test"); + ArgumentCaptor argCar = ArgumentCaptor.forClass(Car.class); + + when(carClientService.doNewCar(argCar.capture())).thenReturn(expected); + + businessService.createsNewCar(); + + verify(carClientService, times(1)).doNewCar(argCar.getValue()); + } } diff --git a/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/client/CarClientServiceIntegrationTest.java b/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/client/CarClientServiceIntegrationTest.java index 65d752a..1fa6c64 100644 --- a/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/client/CarClientServiceIntegrationTest.java +++ b/SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/client/CarClientServiceIntegrationTest.java @@ -53,10 +53,8 @@ public class CarClientServiceIntegrationTest { @Test public void whenGetAllCarsThenRetrieveRequestedCars() throws JsonProcessingException { Car expectedOne = new Car(66L, "test"); - Car expectedTwo = new Car(99L, "example"); List expected = new ArrayList<>(); expected.add(expectedOne); - expected.add(expectedTwo); mockServer.expect(requestTo(apiCarsUrl)) .andExpect(method(HttpMethod.GET)) @@ -66,9 +64,8 @@ public class CarClientServiceIntegrationTest { mockServer.verify(); - assertEquals(2, cars.size()); + assertEquals(1, cars.size()); assertEquals(expectedOne, cars.get(0)); - assertEquals(expectedTwo, cars.get(1)); } @Test