From: Gustavo Martin Morcuende Date: Thu, 24 Nov 2016 23:15:16 +0000 (+0100) Subject: User isFriendsWith(user) method in TripService X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=fc7fbd2c2545049f866cbccbd115dbf68227e1e4;p=JavaForFun User isFriendsWith(user) method in TripService --- diff --git a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java index 570b6a0..4eddb9e 100644 --- a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java +++ b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java @@ -14,16 +14,9 @@ public class TripService { // In Unit Test we shouldn't invoke other classes because // other classes could be using data base, network, etc, etc. // User loggedUser = UserSession.getInstance().getLoggedUser(); - User loggedUser = getLoggedInUser(); - boolean isFriend = false; - if (loggedUser != null) { - // Feature envy. TripService envies User class. This should be done by User class. - for (User friend : user.getFriends()) { - if (friend.equals(loggedUser)) { - isFriend = true; - break; - } - } + User loggedInUser = getLoggedInUser(); + if (loggedInUser != null) { + boolean isFriend = user.isFriendsWith(loggedInUser); // The deepest branch. For refactoring legacy code we must begin from the // deepest branch. This is just the opposite for creating the unit test // for our legacy code.