- private void initializeSoneMock(String id, final Sone sone) {
- when(sone.getId()).thenReturn(id);
- when(sone.getProfile()).thenReturn(new Profile(sone));
- 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 FreenetRequest mockRequest(String path) {
+ HTTPRequest httpRequest = mock(HTTPRequest.class);
+ when(httpRequest.getMethod()).thenReturn("GET");
+ when(httpRequest.getPath()).thenReturn(path);
+ FreenetRequest request = mock(FreenetRequest.class);
+ when(request.getHttpRequest()).thenReturn(httpRequest);
+ return request;
+ }
+
+ public class SoneMocker {
+
+ private final Sone mockedSone = mock(Sone.class);
+ private final String id;
+ private String insertUrI;
+ private boolean local;
+ private boolean current;
+ 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 insertUri(String insertUri) {
+ this.insertUrI = insertUri;
+ return this;
+ }
+
+ public SoneMocker current() {
+ current = 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 (local) {
+ OwnIdentity ownIdentity = mock(OwnIdentity.class);
+ when(ownIdentity.getInsertUri()).thenReturn(insertUrI);
+ when(mockedSone.getIdentity()).thenReturn(ownIdentity);