From 13173509cb13a52251adfd523166498518674791 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Thu, 24 Nov 2016 23:49:48 +0100 Subject: [PATCH] Moving UserBuilder to production code --- .../org/craftedsw/tripservicekata/UserBuilder.java | 42 ++++++++++++++++++++++ .../tripservicekata/trip/TripServiceShould.java | 40 +-------------------- .../craftedsw/tripservicekata/user/UserShould.java | 5 +++ .../craftedsw/tripservicekata/user/UserTest.java | 5 --- 4 files changed, 48 insertions(+), 44 deletions(-) create mode 100644 TDD/src/main/java/org/craftedsw/tripservicekata/UserBuilder.java create mode 100644 TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java delete mode 100644 TDD/src/test/java/org/craftedsw/tripservicekata/user/UserTest.java diff --git a/TDD/src/main/java/org/craftedsw/tripservicekata/UserBuilder.java b/TDD/src/main/java/org/craftedsw/tripservicekata/UserBuilder.java new file mode 100644 index 0000000..8f95bc9 --- /dev/null +++ b/TDD/src/main/java/org/craftedsw/tripservicekata/UserBuilder.java @@ -0,0 +1,42 @@ +package org.craftedsw.tripservicekata; + +import org.craftedsw.tripservicekata.trip.Trip; +import org.craftedsw.tripservicekata.user.User; + +public class UserBuilder { + private User[] friends = new User[]{}; + private Trip[] trips = new Trip[]{}; + + public static UserBuilder aUser() { + return new UserBuilder(); + } + + public UserBuilder withTrips(Trip...trips) { + this.trips = trips; + return this; + } + + public UserBuilder friendsWith(User...friends) { + this.friends = friends; + return this; + } + + public User build() { + User user = new User(); + addTripsTo(user); + addFriendsTo(user); + return user; + } + + private void addFriendsTo(User user) { + for (User friend : friends) { + user.addFriend(friend); + } + } + + private void addTripsTo(User user) { + for (Trip trip : trips) { + user.addTrip(trip); + } + } +} diff --git a/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java b/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java index e2a58ba..a41d1cd 100644 --- a/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java +++ b/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertThat; import java.util.List; +import org.craftedsw.tripservicekata.UserBuilder; import org.craftedsw.tripservicekata.exception.UserNotLoggedInException; import org.craftedsw.tripservicekata.user.User; import org.junit.Before; @@ -62,45 +63,6 @@ public class TripServiceShould { assertThat(friendTrips.size(), is(2)); } - - public static class UserBuilder { - private User[] friends = new User[]{}; - private Trip[] trips = new Trip[]{}; - - public static UserBuilder aUser() { - return new UserBuilder(); - } - - public UserBuilder withTrips(Trip...trips) { - this.trips = trips; - return this; - } - - public UserBuilder friendsWith(User...friends) { - this.friends = friends; - return this; - } - - public User build() { - User user = new User(); - addTripsTo(user); - addFriendsTo(user); - return user; - } - - private void addFriendsTo(User user) { - for (User friend : friends) { - user.addFriend(friend); - } - } - - private void addTripsTo(User user) { - for (Trip trip : trips) { - user.addTrip(trip); - } - } - } - private class TesteableTripService extends TripService { @Override diff --git a/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java b/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java new file mode 100644 index 0000000..28b2a37 --- /dev/null +++ b/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java @@ -0,0 +1,5 @@ +package org.craftedsw.tripservicekata.user; + +public class UserTest { + +} diff --git a/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserTest.java b/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserTest.java deleted file mode 100644 index 28b2a37..0000000 --- a/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.craftedsw.tripservicekata.user; - -public class UserTest { - -} -- 2.1.4