From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 14:10:52 +0000 (+0100) Subject: TripService we can refactor as much as we want because everything is under test. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=e2d33188d245dcd310132a3d9a96230b6fed7eea;p=JavaForFun TripService we can refactor as much as we want because everything is under test. Creating validate method. --- 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 bd899a2..276710f 100644 --- a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java +++ b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java @@ -18,15 +18,19 @@ public class TripService { } public List getTripsByUser(User user, User loggedInUser) throws UserNotLoggedInException { - if (loggedInUser == null) { - throw new UserNotLoggedInException(); - } + validate(loggedInUser); return user.isFriendsWith(loggedInUser) ? tripsBy(user) : noTrips(); } + private void validate(User loggedInUser) { + if (loggedInUser == null) { + throw new UserNotLoggedInException(); + } + } + private ArrayList noTrips() { return new ArrayList<>(); }