public class TripService {\r
\r
public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException {\r
- List<Trip> tripList = new ArrayList<Trip>();\r
- // 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 loggedInUser = getLoggedInUser();\r
- if (loggedInUser != null) {\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
- // 1. Write the unit test from the shortest to deepest branch. Modifications\r
- // in legacy code must be done JUST with the automatic tools provided by the IDE.\r
- // 2. Once the legacy code is under test start refactoring from deepest\r
- // to shortest branch. Modifications in the legacy code may be hand made.\r
- // In this case we can not do anything with this code (this is the deepest branch)\r
- // so we will have to start with the for loop (which is the second deepest branch)\r
- if (user.isFriendsWith(loggedInUser)) {\r
- tripList = tripsBy(user);\r
- }\r
- return tripList;\r
- } else {\r
+ if (loggedInUser == null) {\r
throw new UserNotLoggedInException();\r
}\r
+ \r
+ List<Trip> tripList = new ArrayList<Trip>();\r
+ if (user.isFriendsWith(loggedInUser)) {\r
+ tripList = tripsBy(user);\r
+ }\r
+ return tripList;\r
}\r
\r
protected List<Trip> tripsBy(User user) {\r