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
}\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
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
\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