2 * Sone - SoneTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data;
20 import static freenet.keys.InsertableClientSSK.createRandom;
21 import static net.pterodactylus.sone.data.Sone.TO_INSERT_URI;
22 import static net.pterodactylus.sone.data.Sone.TO_POSTS;
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.contains;
25 import static org.hamcrest.Matchers.is;
26 import static org.hamcrest.Matchers.nullValue;
27 import static org.mockito.Mockito.when;
29 import freenet.crypt.DummyRandomSource;
30 import freenet.keys.InsertableClientSSK;
32 import org.junit.Test;
35 * Unit test for the static functions and predicates in {@link Sone}.
37 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39 public class SoneTest {
41 private final Mocks mocks = new Mocks();
44 public void verifyThatTransformingASoneIntoItsPostsWorks() {
45 Sone sone = mocks.mockSone("Sone").local().create();
46 Post post1 = mocks.mockPost(sone, "Post1").create();
47 when(post1.getTime()).thenReturn(1000L);
48 Post post2 = mocks.mockPost(sone, "Post2").create();
49 when(post2.getTime()).thenReturn(2000L);
50 Post post3 = mocks.mockPost(sone, "Post3").create();
51 when(post3.getTime()).thenReturn(3000L);
52 assertThat(TO_POSTS.apply(sone), contains(is(post3), is(post2), is(post1)));
56 public void soneCanBeTransformedIntoAnInsertUri() {
57 InsertableClientSSK newKeypair = createRandom(new DummyRandomSource(), "Test");
58 Sone localSone = mocks.mockSone("A").local().insertUri(newKeypair.getInsertURI().toString()).create();
59 assertThat(TO_INSERT_URI.apply(localSone).toString(), is(newKeypair.getInsertURI().setDocName("Sone").toString()));
63 public void nonLocalSoneCanNotBeTransformedIntoAnInsertUri() {
64 Sone remoteSone = mocks.mockSone("A").create();
65 assertThat(TO_INSERT_URI.apply(remoteSone), nullValue());