From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 13:55:53 +0000 (+0100) Subject: return_friend_trips_when_users_are_friends fails X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=4d49ae66ce21bafc61ea288a297902b66a100d48;p=JavaForFun return_friend_trips_when_users_are_friends fails Now test is using my Mock but it keeps failing with a different error :) --- diff --git a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java index e2aced9..cffc596 100644 --- a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java +++ b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java @@ -3,10 +3,19 @@ package org.craftedsw.tripservicekata.trip; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; + import org.craftedsw.tripservicekata.exception.UserNotLoggedInException; import org.craftedsw.tripservicekata.user.User; public class TripService { + + private final TripDAO tripDAO; + + @Inject + public TripService(TripDAO tripDAO) { + this.tripDAO = tripDAO; + } public List getTripsByUser(User user, User loggedInUser) throws UserNotLoggedInException { if (loggedInUser == null) { @@ -23,8 +32,6 @@ public class TripService { } protected List tripsBy(User user) { - List tripList; - tripList = TripDAO.findTripsByUser(user); - return tripList; + return tripDAO.tripsBy(user); } } 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 09269ea..e9ac3ea 100644 --- a/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java +++ b/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java @@ -27,11 +27,12 @@ public class TripServiceShould { private static final Trip TO_BERLIN = new Trip(); @Mock TripDAO tripDAO; - @InjectMocks @Spy private TripService realTripService = new TripService(); + @InjectMocks @Spy private TripService realTripService; private TripService tripService; @Before public void setUp() { + realTripService = new TripService(tripDAO); tripService = new TesteableTripService(); } @@ -70,6 +71,10 @@ public class TripServiceShould { private class TesteableTripService extends TripService { + public TesteableTripService() { + super(new TripDAO()); + } + @Override protected List tripsBy(User user) { return user.trips();