From 4d49ae66ce21bafc61ea288a297902b66a100d48 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 14:55:53 +0100 Subject: [PATCH] return_friend_trips_when_users_are_friends fails Now test is using my Mock but it keeps failing with a different error :) --- .../org/craftedsw/tripservicekata/trip/TripService.java | 13 ++++++++++--- .../craftedsw/tripservicekata/trip/TripServiceShould.java | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) 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(); -- 2.1.4