- public static Sone mockRemoteSone(Core core, final String id) {
- final Sone sone = mock(Sone.class);
- when(sone.getId()).thenReturn(id);
- when(sone.isLocal()).thenReturn(false);
- when(sone.getProfile()).thenReturn(new Profile(sone));
- final Database database = core.getDatabase();
- when(sone.newPostBuilder()).thenThrow(IllegalStateException.class);
- when(sone.newPostReplyBuilder(Matchers.<String>anyObject())).thenThrow(IllegalStateException.class);
- when(core.getSone(eq(id))).thenReturn(of(sone));
- when(database.getSone(eq(id))).thenReturn(of(sone));
- when(sone.getPosts()).then(new Answer<List<Post>>() {
- @Override
- public List<Post> answer(InvocationOnMock invocationOnMock) throws Throwable {
- return from(TIME_COMPARATOR).sortedCopy(sonePosts.get(sone));
+ public PostMocker mockPost(Sone sone, String postId) {
+ return new PostMocker(postId, sone);
+ }
+
+ public PostReplyMocker mockPostReply(Sone sone, String replyId) {
+ return new PostReplyMocker(replyId, sone);
+ }
+
+ public class SoneMocker {
+
+ private final Sone mockedSone = mock(Sone.class);
+ private final String id;
+ private boolean local;
+ private Optional<String> name = absent();
+ private long time;
+ private Profile profile = new Profile(mockedSone);
+ private Collection<String> friends = emptySet();
+
+ private SoneMocker(String id) {
+ this.id = id;
+ }
+
+ public SoneMocker local() {
+ local = true;
+ return this;
+ }
+
+ public SoneMocker withName(String name) {
+ this.name = fromNullable(name);
+ return this;
+ }
+
+ public SoneMocker withTime(long time) {
+ this.time = time;
+ return this;
+ }
+
+ public SoneMocker withProfileName(String firstName, String middleName, String lastName) {
+ profile.modify().setFirstName(firstName).setMiddleName(middleName).setLastName(lastName).update();
+ return this;
+ }
+
+ public SoneMocker addProfileField(String fieldName, String fieldValue) {
+ profile.setField(profile.addField(fieldName), fieldValue);
+ return this;
+ }
+
+ public SoneMocker withFriends(Collection<String> friends) {
+ this.friends = friends;
+ return this;
+ }
+
+ public Sone create() {
+ when(mockedSone.getId()).thenReturn(id);
+ when(mockedSone.isLocal()).thenReturn(local);
+ if (name.isPresent()) {
+ when(mockedSone.getName()).thenReturn(name.get());