\r
public class TripService {\r
\r
- public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException {\r
- if (getLoggedInUser() == null) {\r
+ public List<Trip> getTripsByUser(User user, User loggedInUser) throws UserNotLoggedInException {\r
+ if (loggedInUser == null) {\r
throw new UserNotLoggedInException();\r
}\r
\r
- return user.isFriendsWith(getLoggedInUser())\r
+ return user.isFriendsWith(loggedInUser)\r
? tripsBy(user)\r
: noTrips();\r
}\r
tripList = TripDAO.findTripsByUser(user);\r
return tripList;\r
}\r
-\r
- // In MVC the Model layer should know nothing about the view.\r
- // Service is in Model layer, so we have to get rid of this method.\r
- protected User getLoggedInUser() {\r
- User loggedUser = UserSession.getInstance().getLoggedUser();\r
- return loggedUser;\r
- }\r
- \r
}\r
throw_an_exception_when_user_is_not_logged_in() {\r
loggedInUser = GUEST;\r
\r
- tripService.getTripsByUser(UNUSED_USER);\r
+ tripService.getTripsByUser(UNUSED_USER, GUEST);\r
}\r
\r
@Test public void\r
.withTrips(TO_BRAZIL)\r
.build();\r
\r
- List<Trip> friendTrips = tripService.getTripsByUser(friend); \r
+ List<Trip> friendTrips = tripService.getTripsByUser(friend, loggedInUser); \r
// You must always begin writing the assert.\r
// Remember: the assert must match the unit test method's name!!\r
// In this case, no trips must be returned.\r
.withTrips(TO_BRAZIL, TO_BERLIN)\r
.build();\r
\r
- List<Trip> friendTrips = tripService.getTripsByUser(friend); \r
+ List<Trip> friendTrips = tripService.getTripsByUser(friend, loggedInUser); \r
// You must always begin writing the assert.\r
// Remember: the assert must match the unit test method's name!!\r
// In this case, no trips must be returned.\r
private class TesteableTripService extends TripService {\r
\r
@Override\r
- protected User getLoggedInUser() {\r
- return loggedInUser;\r
- }\r
-\r
- @Override\r
protected List<Trip> tripsBy(User user) {\r
return user.trips();\r
}\r