From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 13:46:55 +0000 (+0100) Subject: return_friend_trips_when_users_are_friends stops working X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=84489f73741c998847c86dfb142f0af4a8eaa90b;p=JavaForFun 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 --- 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.