TripService we can refactor as much as we want because everything is under test.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 14:10:52 +0000 (15:10 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 14:10:52 +0000 (15:10 +0100)
Creating validate method.

TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java

index bd899a2..276710f 100644 (file)
@@ -18,15 +18,19 @@ public class TripService {
        }\r
 \r
        public List<Trip> getTripsByUser(User user, User loggedInUser) throws UserNotLoggedInException {\r
-               if (loggedInUser == null) {\r
-                       throw new UserNotLoggedInException();\r
-               }\r
+               validate(loggedInUser);\r
                \r
                return user.isFriendsWith(loggedInUser)\r
                                ? tripsBy(user)\r
                            : noTrips();\r
        }\r
 \r
+       private void validate(User loggedInUser) {\r
+               if (loggedInUser == null) {\r
+                       throw new UserNotLoggedInException();\r
+               }\r
+       }\r
+\r
        private ArrayList<Trip> noTrips() {\r
                return new ArrayList<>();\r
        }\r