X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FAbstractSoneCommandTest.java;h=7f1c08f1499589ac0f60222eeddd010d48bdcbaf;hb=df85fb9529466327e3da6873328cb4c7507d8de5;hp=8867a36586479e687a62d7424573ac7c7aa721bb;hpb=e80be3f00b1d486fd3995d8f29ce3bf04da7b61d;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 8867a36..7f1c08f 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -27,17 +27,22 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.List; +import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder; +import net.pterodactylus.sone.freenet.fcp.FcpException; import freenet.node.FSParseException; import freenet.support.SimpleFieldSet; +import freenet.support.api.Bucket; import com.google.common.base.Optional; import org.junit.Test; @@ -50,6 +55,14 @@ import org.mockito.Matchers; */ public class AbstractSoneCommandTest { + private final Core core = mock(Core.class); + private final AbstractSoneCommand abstractSoneCommand = new AbstractSoneCommand(core) { + @Override + public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException { + return null; + } + }; + @Test public void testStringEncoding() { String testString = prepareStringToBeEncoded(); @@ -215,4 +228,28 @@ public class AbstractSoneCommandTest { assertThat(likesFieldSet.get("Prefix.2.ID"), is(likes.get(2).getId())); } + @Test + public void testParsingAMandatorySone() 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(); + Sone parsedSone = abstractSoneCommand.getMandatorySone(soneFieldSet, "Sone"); + assertThat(parsedSone, notNullValue()); + assertThat(parsedSone, is(sone)); + } + + @Test(expected = FcpException.class) + public void testParsingANonExistingMandatorySoneCausesAnError() throws FcpException { + when(core.getSone(Matchers.any())).thenReturn(Optional.absent()); + SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get(); + abstractSoneCommand.getMandatorySone(soneFieldSet, "Sone"); + } + + @Test(expected = FcpException.class) + public void testParsingAMandatorySoneFromANonExistingFieldCausesAnError() throws FcpException { + when(core.getSone(Matchers.any())).thenReturn(Optional.absent()); + SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get(); + abstractSoneCommand.getMandatorySone(soneFieldSet, "RealSone"); + } + }