Moving UserBuilder to production code
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 24 Nov 2016 22:49:48 +0000 (23:49 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 24 Nov 2016 22:49:48 +0000 (23:49 +0100)
TDD/src/main/java/org/craftedsw/tripservicekata/UserBuilder.java [new file with mode: 0644]
TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java
TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java [new file with mode: 0644]
TDD/src/test/java/org/craftedsw/tripservicekata/user/UserTest.java [deleted file]

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 (file)
index 0000000..8f95bc9
--- /dev/null
@@ -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);
+               }
+       }
+}
index e2a58ba..a41d1cd 100644 (file)
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertThat;
 \r
 import java.util.List;\r
 \r
+import org.craftedsw.tripservicekata.UserBuilder;\r
 import org.craftedsw.tripservicekata.exception.UserNotLoggedInException;\r
 import org.craftedsw.tripservicekata.user.User;\r
 import org.junit.Before;\r
@@ -62,45 +63,6 @@ public class TripServiceShould {
                assertThat(friendTrips.size(), is(2));\r
        }\r
        \r
-       \r
-       public static class UserBuilder {\r
-               private User[] friends = new User[]{};\r
-               private Trip[] trips = new Trip[]{};\r
-               \r
-               public static UserBuilder aUser() {\r
-                       return new UserBuilder();\r
-               }\r
-\r
-               public UserBuilder withTrips(Trip...trips) {\r
-                       this.trips  = trips;\r
-                       return this;\r
-               }\r
-\r
-               public UserBuilder friendsWith(User...friends) {\r
-                       this.friends = friends;\r
-                       return this;\r
-               }\r
-               \r
-               public User build() {\r
-                       User user = new User();\r
-                       addTripsTo(user);\r
-                       addFriendsTo(user);\r
-                       return user;\r
-               }\r
-\r
-               private void addFriendsTo(User user) {\r
-                       for (User friend : friends) {\r
-                               user.addFriend(friend);\r
-                       }               \r
-               }\r
-\r
-               private void addTripsTo(User user) {\r
-                       for (Trip trip : trips) {\r
-                               user.addTrip(trip);\r
-                       }\r
-               }\r
-       }\r
-       \r
        private class TesteableTripService extends TripService {\r
 \r
                @Override\r
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 (file)
index 0000000..28b2a37
--- /dev/null
@@ -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 (file)
index 28b2a37..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.craftedsw.tripservicekata.user;
-
-public class UserTest {
-
-}