From fc7fbd2c2545049f866cbccbd115dbf68227e1e4 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Fri, 25 Nov 2016 00:15:16 +0100 Subject: [PATCH] User isFriendsWith(user) method in TripService --- .../org/craftedsw/tripservicekata/trip/TripService.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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. -- 2.1.4