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