User isFriendsWith(user) method in TripService
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 24 Nov 2016 23:15:16 +0000 (00:15 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 24 Nov 2016 23:15:16 +0000 (00:15 +0100)
TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java

index 570b6a0..4eddb9e 100644 (file)
@@ -14,16 +14,9 @@ public class TripService {
                // In Unit Test we shouldn't invoke other classes because\r
                // other classes could be using data base, network, etc, etc.\r
                // User loggedUser = UserSession.getInstance().getLoggedUser();\r
-               User loggedUser = getLoggedInUser();\r
-               boolean isFriend = false;\r
-               if (loggedUser != null) {\r
-                       // Feature envy. TripService envies User class. This should be done by User class.\r
-                       for (User friend : user.getFriends()) {\r
-                               if (friend.equals(loggedUser)) {\r
-                                       isFriend = true;\r
-                                       break;\r
-                               }\r
-                       }\r
+               User loggedInUser = getLoggedInUser();\r
+               if (loggedInUser != null) {\r
+                       boolean isFriend = user.isFriendsWith(loggedInUser);            \r
                        // The deepest branch. For refactoring legacy code we must begin from the\r
                        // deepest branch. This is just the opposite for creating the unit test\r
                        // for our legacy code.\r