return_friend_trips_when_users_are_friends stops working
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 13:46:55 +0000 (14:46 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 13:46:55 +0000 (14:46 +0100)
When a test fails we have a reason for refactoring our legacy code!!!
In this case the problema is related to using the static method of TripDAO

TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java

index 1151d86..09269ea 100644 (file)
@@ -11,7 +11,9 @@ import org.craftedsw.tripservicekata.user.User;
 import org.junit.Before;\r
 import org.junit.Test;\r
 import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
 import org.mockito.Mock;\r
+import org.mockito.Spy;\r
 import org.mockito.runners.MockitoJUnitRunner;\r
 \r
 @RunWith(MockitoJUnitRunner.class)\r
@@ -25,7 +27,7 @@ public class TripServiceShould {
        private static final Trip TO_BERLIN = new Trip();\r
        \r
        @Mock TripDAO tripDAO;\r
-       private TripService realTripService;\r
+       @InjectMocks @Spy private TripService realTripService = new TripService();\r
        private TripService tripService;\r
        \r
        @Before\r
@@ -35,7 +37,7 @@ public class TripServiceShould {
 \r
        @Test(expected=UserNotLoggedInException.class) public void\r
        throw_an_exception_when_user_is_not_logged_in() {               \r
-               tripService.getTripsByUser(UNUSED_USER, GUEST);\r
+               realTripService.getTripsByUser(UNUSED_USER, GUEST);\r
        }\r
        \r
        @Test public void\r
@@ -45,7 +47,7 @@ public class TripServiceShould {
                                                .withTrips(TO_BRAZIL)\r
                                                .build();\r
                \r
-               List<Trip> friendTrips = tripService.getTripsByUser(friend, REGISTERED_USER); \r
+               List<Trip> friendTrips = realTripService.getTripsByUser(friend, REGISTERED_USER); \r
                // You must always begin writing the assert.\r
                // Remember: the assert must match the unit test method's name!!\r
                // In this case, no trips must be returned.\r
@@ -59,7 +61,7 @@ public class TripServiceShould {
                                                .withTrips(TO_BRAZIL, TO_BERLIN)\r
                                                .build();\r
                \r
-               List<Trip> friendTrips = tripService.getTripsByUser(friend, REGISTERED_USER); \r
+               List<Trip> friendTrips = realTripService.getTripsByUser(friend, REGISTERED_USER); \r
                // You must always begin writing the assert.\r
                // Remember: the assert must match the unit test method's name!!\r
                // In this case, no trips must be returned.\r