--- /dev/null
+package org.craftedsw.tripservicekata;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.craftedsw.tripservicekata.exception.UserNotLoggedInException;
+import org.craftedsw.tripservicekata.trip.Trip;
+import org.craftedsw.tripservicekata.trip.TripDAO;
+import org.craftedsw.tripservicekata.user.User;
+import org.craftedsw.tripservicekata.user.UserSession;
+
+public class TripService_Original {
+
+ public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException {
+ List<Trip> tripList = new ArrayList<Trip>();
+ User loggedUser = UserSession.getInstance().getLoggedUser();
+ boolean isFriend = false;
+ if (loggedUser != null) {
+ for (User friend : user.getFriends()) {
+ if (friend.equals(loggedUser)) {
+ isFriend = true;
+ break;
+ }
+ }
+ if (isFriend) {
+ tripList = TripDAO.findTripsByUser(user);
+ }
+ return tripList;
+ } else {
+ throw new UserNotLoggedInException();
+ }
+ }
+
+}
--- /dev/null
+package org.craftedsw.tripservicekata.exception;
+
+public class CollaboratorCallException extends RuntimeException {
+
+ private static final long serialVersionUID = -4584041339906109902L;
+
+ public CollaboratorCallException() {
+ super();
+ }
+
+ public CollaboratorCallException(String message,
+ Throwable cause) {
+ super(message, cause);
+ }
+
+ public CollaboratorCallException(String message) {
+ super(message);
+ }
+
+ public CollaboratorCallException(Throwable cause) {
+ super(cause);
+ }
+
+
+}
--- /dev/null
+package org.craftedsw.tripservicekata.exception;
+
+public class UserNotLoggedInException extends RuntimeException {
+
+ private static final long serialVersionUID = 8959479918185637340L;
+
+}
--- /dev/null
+package org.craftedsw.tripservicekata.trip;
+
+public class Trip {
+
+}
--- /dev/null
+package org.craftedsw.tripservicekata.trip;
+
+import java.util.List;
+
+import org.craftedsw.tripservicekata.exception.CollaboratorCallException;
+import org.craftedsw.tripservicekata.user.User;
+
+public class TripDAO {
+
+ public static List<Trip> findTripsByUser(User user) {
+ throw new CollaboratorCallException(
+ "TripDAO should not be invoked on an unit test.");
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package org.craftedsw.tripservicekata.trip;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.craftedsw.tripservicekata.exception.UserNotLoggedInException;\r
+import org.craftedsw.tripservicekata.user.User;\r
+import org.craftedsw.tripservicekata.user.UserSession;\r
+\r
+public class TripService {\r
+\r
+ public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException {\r
+ List<Trip> tripList = new ArrayList<Trip>();\r
+ User loggedUser = UserSession.getInstance().getLoggedUser();\r
+ boolean isFriend = false;\r
+ if (loggedUser != null) {\r
+ for (User friend : user.getFriends()) {\r
+ if (friend.equals(loggedUser)) {\r
+ isFriend = true;\r
+ break;\r
+ }\r
+ }\r
+ if (isFriend) {\r
+ tripList = TripDAO.findTripsByUser(user);\r
+ }\r
+ return tripList;\r
+ } else {\r
+ throw new UserNotLoggedInException();\r
+ }\r
+ }\r
+ \r
+}\r
--- /dev/null
+package org.craftedsw.tripservicekata.user;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.craftedsw.tripservicekata.trip.Trip;\r
+\r
+public class User {\r
+\r
+ private List<Trip> trips = new ArrayList<Trip>();\r
+ private List<User> friends = new ArrayList<User>();\r
+ \r
+ public List<User> getFriends() {\r
+ return friends;\r
+ }\r
+ \r
+ public void addFriend(User user) {\r
+ friends.add(user);\r
+ }\r
+\r
+ public void addTrip(Trip trip) {\r
+ trips.add(trip);\r
+ }\r
+ \r
+ public List<Trip> trips() {\r
+ return trips;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.craftedsw.tripservicekata.user;
+
+import org.craftedsw.tripservicekata.exception.CollaboratorCallException;
+
+public class UserSession {
+
+ private static final UserSession userSession = new UserSession();
+
+ private UserSession() {
+ }
+
+ public static UserSession getInstance() {
+ return userSession;
+ }
+
+ public User getLoggedUser() {
+ throw new CollaboratorCallException(
+ "UserSession.getLoggedUser() should not be called in an unit test");
+ }
+
+}
--- /dev/null
+package org.craftedsw.tripservicekata.trip;
+
+public class TripDAOTest {
+
+}
--- /dev/null
+package org.craftedsw.tripservicekata.trip;\r
+\r
+import org.junit.Test;\r
+\r
+public class TripServiceTest {\r
+ \r
+ @Test public void\r
+ should_throw_an_exception_when_no_logged_user() {\r
+ \r
+ }\r
+}\r
--- /dev/null
+package org.craftedsw.tripservicekata.user;
+
+public class UserTest {
+
+}