--- /dev/null
+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);
+ }
+ }
+}
\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
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