From: David ‘Bombe’ Roden Date: Fri, 25 Oct 2013 23:09:43 +0000 (+0200) Subject: Add tests for parsing optional Sones. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4182d9b5708c7b6cd3f9667ed36793722d393484;p=Sone.git Add tests for parsing optional Sones. --- diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index cfaf660..90f78cc 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -288,4 +288,31 @@ public class AbstractSoneCommandTest { abstractSoneCommand.getMandatoryLocalSone(soneFieldSet, "RealSone"); } + @Test + public void testParsingAnExistingOptionalSone() throws FcpException { + Sone sone = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test", "First", "M.", "Last", (long) (Math.random() * Long.MAX_VALUE)); + when(core.getSone(eq("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E"))).thenReturn(of(sone)); + SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get(); + Optional parsedSone = abstractSoneCommand.getOptionalSone(soneFieldSet, "Sone"); + assertThat(parsedSone, notNullValue()); + assertThat(parsedSone.isPresent(), is(true)); + assertThat(parsedSone.get(), is(sone)); + } + + @Test + public void testParsingANonExistingOptionalSone() throws FcpException { + when(core.getSone(Matchers.any())).thenReturn(Optional.absent()); + SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get(); + Optional parsedSone = abstractSoneCommand.getOptionalSone(soneFieldSet, "Sone"); + assertThat(parsedSone, notNullValue()); + assertThat(parsedSone.isPresent(), is(false)); + } + + @Test(expected = FcpException.class) + public void testParsingAnOptionalSoneFromANonExistingFieldCausesAnError() throws FcpException { + when(core.getSone(Matchers.any())).thenReturn(Optional.absent()); + SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get(); + abstractSoneCommand.getOptionalSone(soneFieldSet, "RealSone"); + } + }