From: David ‘Bombe’ Roden Date: Wed, 17 Sep 2014 20:24:37 +0000 (+0200) Subject: Refactor post mocking into its own method. X-Git-Tag: 0.9-rc1^2~3^2~116 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=51ab7efd1f6376f9d7a27b63a121262a9cef9cb0;p=Sone.git Refactor post mocking into its own method. --- diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java index cad0a23..73e63dd 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.database.memory; import static com.google.common.base.Optional.of; +import static java.util.UUID.randomUUID; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -52,19 +53,22 @@ public class MemoryDatabaseTest { @Test public void postRecipientsAreDetectedCorrectly() { - Post postWithRecipient = mock(Post.class); - when(postWithRecipient.getSone()).thenReturn(sone); - when(postWithRecipient.getRecipientId()).thenReturn(of(RECIPIENT_ID)); + Post postWithRecipient = createPost(of(RECIPIENT_ID)); memoryDatabase.storePost(postWithRecipient); - Post postWithoutRecipient = mock(Post.class); - when(postWithoutRecipient.getSone()).thenReturn(sone); - when(postWithoutRecipient.getRecipientId()).thenReturn( - Optional.absent()); + Post postWithoutRecipient = createPost(Optional.absent()); memoryDatabase.storePost(postWithoutRecipient); assertThat(memoryDatabase.getDirectedPosts(RECIPIENT_ID), contains(postWithRecipient)); } + private Post createPost(Optional recipient) { + Post postWithRecipient = mock(Post.class); + when(postWithRecipient.getId()).thenReturn(randomUUID().toString()); + when(postWithRecipient.getSone()).thenReturn(sone); + when(postWithRecipient.getRecipientId()).thenReturn(recipient); + return postWithRecipient; + } + @Test public void testBasicAlbumFunctionality() { Album newAlbum = new AlbumImpl(mock(Sone.class));