Spring REST: missing test
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 7 Jan 2016 00:13:23 +0000 (01:13 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 7 Jan 2016 00:13:23 +0000 (01:13 +0100)
SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/business/BusinessServiceTest.java
SpringJava/REST/web-services-spring-rest-client/src/test/java/de/spring/webservices/rest/client/CarClientServiceIntegrationTest.java

index 3910f0b..8d279a6 100644 (file)
@@ -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<Car> argCar = ArgumentCaptor.forClass(Car.class);
+               
+               when(carClientService.doNewCar(argCar.capture())).thenReturn(expected);
+               
+               businessService.createsNewCar();
+               
+               verify(carClientService, times(1)).doNewCar(argCar.getValue());
+       }
 }
index 65d752a..1fa6c64 100644 (file)
@@ -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<Car> 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