X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FAbstractSoneCommandTest.java;h=90f78cc60e35a9a0d9705fc8640ea6b08a8ea549;hb=4182d9b5708c7b6cd3f9667ed36793722d393484;hp=cfaf660d35065a585c47cb414a2e5bd8c0adaf13;hpb=5680eb94d4545c38e2f6bb6e9fd903838459ee56;p=Sone.git 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"); + } + }