From 9247db2826dc52f6b3a95a13daa1b72d2174429d Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Thu, 7 Jan 2016 01:13:23 +0100 Subject: [PATCH] Spring REST: missing test --- .../webservices/rest/business/BusinessServiceTest.java | 14 +++++++++++++- .../rest/client/CarClientServiceIntegrationTest.java | 5 +---- 2 files changed, 14 insertions(+), 5 deletions(-) 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 -- 2.1.4