import java.util.List;
import java.util.Set;
+import javax.annotation.Nullable;
+
import net.pterodactylus.sone.core.Options;
import net.pterodactylus.sone.database.AlbumBuilder;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostReplyBuilder;
import net.pterodactylus.sone.freenet.wot.Identity;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import freenet.keys.FreenetURI;
}
};
+ public static final Function<Sone, FreenetURI> TO_INSERT_URI = new Function<Sone, FreenetURI>() {
+ @Override
+ public FreenetURI apply(@Nullable Sone sone) {
+ return ((sone == null) || !sone.isLocal()) ? null : create(((OwnIdentity) sone.getIdentity()).getInsertUri());
+ }
+ };
+
public static final Function<Sone, List<Post>> TO_POSTS = new Function<Sone, List<Post>>() {
@Override
public List<Post> apply(Sone sone) {
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;
/**
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());
+ }
+
}