X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneTest.java;h=dae7379d4f4f23025ce54db0b6b189bc680c0ec9;hb=0a4b6fc252003c71f4bdef09560e87982838d9c8;hp=25e58bb18c2fc4527877226139d962fc9c0f70f5;hpb=a781971dedd44853820a9e1b6963d6f49e451ad6;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/data/SoneTest.java b/src/test/java/net/pterodactylus/sone/data/SoneTest.java index 25e58bb..dae7379 100644 --- a/src/test/java/net/pterodactylus/sone/data/SoneTest.java +++ b/src/test/java/net/pterodactylus/sone/data/SoneTest.java @@ -17,12 +17,18 @@ 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()); + } + }