Make it possible to mock a Sone’s insert URI.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 1 Mar 2014 13:06:08 +0000 (14:06 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 1 Mar 2014 13:06:08 +0000 (14:06 +0100)
src/test/java/net/pterodactylus/sone/data/Mocks.java

index 3e8880c..1962686 100644 (file)
@@ -46,6 +46,7 @@ import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.PostBuilder.PostCreated;
 import net.pterodactylus.sone.database.PostReplyBuilder;
 import net.pterodactylus.sone.database.PostReplyBuilder.PostReplyCreated;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
 import net.pterodactylus.sone.utils.IntegerRangePredicate;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
@@ -217,6 +218,7 @@ public class Mocks {
 
                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();
@@ -233,6 +235,11 @@ public class Mocks {
                        return this;
                }
 
+               public SoneMocker insertUri(String insertUri) {
+                       this.insertUrI = insertUri;
+                       return this;
+               }
+
                public SoneMocker current() {
                        current = true;
                        return this;
@@ -266,6 +273,11 @@ public class Mocks {
                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);
+                       }
                        if (current) {
                                currentSone = of(mockedSone);
                        }