Skip to content

Instantly share code, notes, and snippets.

@dmcg
Created November 22, 2014 21:32
Show Gist options
  • Save dmcg/9270a42c3e078549ca24 to your computer and use it in GitHub Desktop.
Save dmcg/9270a42c3e078549ca24 to your computer and use it in GitHub Desktop.
Functional test data builder with lambdas and Lombok @wither
@Value public class User {
public final Optional<String> id;
public final DateTime createdDate;
public final String firstName;
public final String lastName;
@Wither public final Country country;
@Wither public final PhoneNumber phoneNumber;
@Wither public final String email;
@Wither public final Optional<String> stravaId;
@Wither public final Optional<String> facebookId;
public User(String id, DateTime createdDate, String firstName, String lastName, Country country, PhoneNumber phoneNumber, String email, Optional<String> stravaId, Optional<String> facebookId) {
this(Optional.of(id), createdDate, firstName, lastName, country, phoneNumber, email, stravaId, facebookId);
}
...
}
public static User newUser() {
return new User("userId", SOME_TIME, "firstName", "lastName", Country.GB, tel("phone"), "email", Ids.NO_ID, Ids.NO_ID);
}
public static User newUser(Function<User, User> mapper) {
return mapper.apply(newUser());
}
// So we can say
User user = Users.newUser(u -> u.withStravaId(Optional.of("stravaId")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment