+ private final Sone sone = mock(Sone.class);
+
+ @Before
+ public void setupSone() {
+ when(sone.getId()).thenReturn(SONE_ID);
+ }
+
+ @Test
+ public void postRecipientsAreDetectedCorrectly() {
+ Post postWithRecipient = mock(Post.class);
+ when(postWithRecipient.getSone()).thenReturn(sone);
+ when(postWithRecipient.getRecipientId()).thenReturn(of(RECIPIENT_ID));
+ memoryDatabase.storePost(postWithRecipient);
+ Post postWithoutRecipient = mock(Post.class);
+ when(postWithoutRecipient.getSone()).thenReturn(sone);
+ when(postWithoutRecipient.getRecipientId()).thenReturn(
+ Optional.<String>absent());
+ memoryDatabase.storePost(postWithoutRecipient);
+ assertThat(memoryDatabase.getDirectedPosts(RECIPIENT_ID),
+ contains(postWithRecipient));
+ }