import java.util.UUID;
+import javax.annotation.Nullable;
+
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.SoneProvider;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
/**
*/
@Override
public Optional<Sone> getRecipient() {
- return fromNullable(soneProvider.getSone(recipientId));
+ return Optional.fromNullable(recipientId).transform(new Function<String, Sone>() {
+ @Nullable
+ @Override
+ public Sone apply(String input) {
+ return soneProvider.getSone(input);
+ }
+ });
}
/**
--- /dev/null
+package net.pterodactylus.sone.database.memory
+
+import com.google.common.base.Optional.*
+import net.pterodactylus.sone.test.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
+import java.util.*
+
+class MemoryPostTest {
+
+ @Test
+ fun `memory post returns empty optional for post without recipient`() {
+ val postDatabase = mock<MemoryDatabase>()
+ val memoryPost = MemoryPost(postDatabase, postDatabase, UUID.randomUUID().toString(), "soneId", null, 123, "text")
+ assertThat(memoryPost.recipient, equalTo(absent()))
+ }
+
+}