From 900991f19b1004458f99b09db0c3406f788e9812 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 26 Oct 2013 01:54:20 +0200 Subject: [PATCH] Add tests for parsing a reply. --- .../sone/fcp/AbstractSoneCommandTest.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index 787baea..5db07ee 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -352,4 +352,34 @@ public class AbstractSoneCommandTest { abstractSoneCommand.getPost(postFieldSet, "Post"); } + @Test + public void testParsingAReply() throws FcpException { + PostReply reply = createPostReply(); + when(database.getPostReply(eq(reply.getId()))).thenReturn(of(reply)); + SimpleFieldSet replyFieldSet = new SimpleFieldSetBuilder().put("Reply", reply.getId()).get(); + PostReply parsedReply = abstractSoneCommand.getReply(replyFieldSet, "Reply"); + assertThat(parsedReply, notNullValue()); + assertThat(parsedReply, is(reply)); + } + + private PostReply createPostReply() { + PostReply postReply = mock(PostReply.class); + when(postReply.getId()).thenReturn(randomUUID().toString()); + return postReply; + } + + @Test(expected = FcpException.class) + public void testParsingANonExistingReply() throws FcpException { + PostReply reply = createPostReply(); + when(database.getPostReply(Matchers.any())).thenReturn(Optional.absent()); + SimpleFieldSet replyFieldSet = new SimpleFieldSetBuilder().put("Reply", reply.getId()).get(); + abstractSoneCommand.getReply(replyFieldSet, "Reply"); + } + + @Test(expected = FcpException.class) + public void testParsingAReplyFromANonExistingField() throws FcpException { + SimpleFieldSet replyFieldSet = new SimpleFieldSetBuilder().get(); + abstractSoneCommand.getReply(replyFieldSet, "Reply"); + } + } -- 2.7.4