Add function that converts a Sone into its insert URI.
[Sone.git] / src / test / java / net / pterodactylus / sone / data / SoneTest.java
index 25e58bb..dae7379 100644 (file)
 
 package net.pterodactylus.sone.data;
 
+import static freenet.keys.InsertableClientSSK.createRandom;
+import static net.pterodactylus.sone.data.Sone.TO_INSERT_URI;
 import static net.pterodactylus.sone.data.Sone.TO_POSTS;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
 import static org.mockito.Mockito.when;
 
+import freenet.crypt.DummyRandomSource;
+import freenet.keys.InsertableClientSSK;
+
 import org.junit.Test;
 
 /**
@@ -36,14 +42,27 @@ public class SoneTest {
 
        @Test
        public void verifyThatTransformingASoneIntoItsPostsWorks() {
-               Sone sone = mocks.mockLocalSone("Sone");
-               Post post1 = mocks.mockPost(sone, "Post1");
+               Sone sone = mocks.mockSone("Sone").local().create();
+               Post post1 = mocks.mockPost(sone, "Post1").create();
                when(post1.getTime()).thenReturn(1000L);
-               Post post2 = mocks.mockPost(sone, "Post2");
+               Post post2 = mocks.mockPost(sone, "Post2").create();
                when(post2.getTime()).thenReturn(2000L);
-               Post post3 = mocks.mockPost(sone, "Post3");
+               Post post3 = mocks.mockPost(sone, "Post3").create();
                when(post3.getTime()).thenReturn(3000L);
                assertThat(TO_POSTS.apply(sone), contains(is(post3), is(post2), is(post1)));
        }
 
+       @Test
+       public void soneCanBeTransformedIntoAnInsertUri() {
+               InsertableClientSSK newKeypair = createRandom(new DummyRandomSource(), "Test");
+               Sone localSone = mocks.mockSone("A").local().insertUri(newKeypair.getInsertURI().toString()).create();
+               assertThat(TO_INSERT_URI.apply(localSone).toString(), is(newKeypair.getInsertURI().setDocName("Sone").toString()));
+       }
+
+       @Test
+       public void nonLocalSoneCanNotBeTransformedIntoAnInsertUri() {
+               Sone remoteSone = mocks.mockSone("A").create();
+               assertThat(TO_INSERT_URI.apply(remoteSone), nullValue());
+       }
+
 }