From 84489f73741c998847c86dfb142f0af4a8eaa90b Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 14:46:55 +0100 Subject: [PATCH] return_friend_trips_when_users_are_friends stops working 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 --- .../org/craftedsw/tripservicekata/trip/TripServiceShould.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java b/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java index 1151d86..09269ea 100644 --- a/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java +++ b/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java @@ -11,7 +11,9 @@ import org.craftedsw.tripservicekata.user.User; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) @@ -25,7 +27,7 @@ public class TripServiceShould { private static final Trip TO_BERLIN = new Trip(); @Mock TripDAO tripDAO; - private TripService realTripService; + @InjectMocks @Spy private TripService realTripService = new TripService(); private TripService tripService; @Before @@ -35,7 +37,7 @@ public class TripServiceShould { @Test(expected=UserNotLoggedInException.class) public void throw_an_exception_when_user_is_not_logged_in() { - tripService.getTripsByUser(UNUSED_USER, GUEST); + realTripService.getTripsByUser(UNUSED_USER, GUEST); } @Test public void @@ -45,7 +47,7 @@ public class TripServiceShould { .withTrips(TO_BRAZIL) .build(); - List friendTrips = tripService.getTripsByUser(friend, REGISTERED_USER); + List friendTrips = realTripService.getTripsByUser(friend, REGISTERED_USER); // You must always begin writing the assert. // Remember: the assert must match the unit test method's name!! // In this case, no trips must be returned. @@ -59,7 +61,7 @@ public class TripServiceShould { .withTrips(TO_BRAZIL, TO_BERLIN) .build(); - List friendTrips = tripService.getTripsByUser(friend, REGISTERED_USER); + List friendTrips = realTripService.getTripsByUser(friend, REGISTERED_USER); // You must always begin writing the assert. // Remember: the assert must match the unit test method's name!! // In this case, no trips must be returned. -- 2.1.4