From 51ab7efd1f6376f9d7a27b63a121262a9cef9cb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 17 Sep 2014 22:24:37 +0200 Subject: [PATCH] Refactor post mocking into its own method. --- .../sone/database/memory/MemoryDatabaseTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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)); -- 2.7.4