// 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