return_friend_trips_when_users_are_friends fails
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 13:55:53 +0000 (14:55 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 13:55:53 +0000 (14:55 +0100)
Now test is using my Mock but it keeps failing with a different error :)

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

index e2aced9..cffc596 100644 (file)
@@ -3,10 +3,19 @@ package org.craftedsw.tripservicekata.trip;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
+import javax.inject.Inject;\r
+\r
 import org.craftedsw.tripservicekata.exception.UserNotLoggedInException;\r
 import org.craftedsw.tripservicekata.user.User;\r
 \r
 public class TripService {\r
+       \r
+       private final TripDAO tripDAO;\r
+\r
+       @Inject\r
+       public TripService(TripDAO tripDAO) {\r
+               this.tripDAO = tripDAO;\r
+       }\r
 \r
        public List<Trip> getTripsByUser(User user, User loggedInUser) throws UserNotLoggedInException {\r
                if (loggedInUser == null) {\r
@@ -23,8 +32,6 @@ public class TripService {
        }\r
 \r
        protected List<Trip> tripsBy(User user) {\r
-               List<Trip> tripList;\r
-               tripList = TripDAO.findTripsByUser(user);\r
-               return tripList;\r
+               return tripDAO.tripsBy(user);\r
        }\r
 }\r
index 09269ea..e9ac3ea 100644 (file)
@@ -27,11 +27,12 @@ public class TripServiceShould {
        private static final Trip TO_BERLIN = new Trip();\r
        \r
        @Mock TripDAO tripDAO;\r
-       @InjectMocks @Spy private TripService realTripService = new TripService();\r
+       @InjectMocks @Spy private TripService realTripService;\r
        private TripService tripService;\r
        \r
        @Before\r
        public void setUp() {\r
+               realTripService = new TripService(tripDAO);\r
                tripService = new TesteableTripService();\r
        }\r
 \r
@@ -70,6 +71,10 @@ public class TripServiceShould {
        \r
        private class TesteableTripService extends TripService {\r
 \r
+               public TesteableTripService() {\r
+                       super(new TripDAO());\r
+               }\r
+\r
                @Override\r
                protected List<Trip> tripsBy(User user) {\r
                        return user.trips();\r