From: David ‘Bombe’ Roden Date: Fri, 25 Oct 2013 17:29:51 +0000 (+0200) Subject: Add test for encoding a Sone. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f1703685a5b1118d7c4ce35f5f4a23917efcb362;p=Sone.git Add test for encoding a Sone. --- diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index b2d7556..8683b24 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -17,11 +17,21 @@ package net.pterodactylus.sone.fcp; +import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeSone; import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import net.pterodactylus.sone.data.Profile; +import net.pterodactylus.sone.data.Sone; + +import freenet.node.FSParseException; +import freenet.support.SimpleFieldSet; + +import com.google.common.base.Optional; import org.junit.Test; /** @@ -48,4 +58,29 @@ public class AbstractSoneCommandTest { return testString.toString(); } + @Test + public void testEncodingASone() throws FSParseException { + Sone sone = prepareSoneToBeEncoded(); + SimpleFieldSet soneFieldSet = encodeSone(sone, "Prefix.", Optional.absent()); + assertThat(soneFieldSet, notNullValue()); + assertThat(soneFieldSet.get("Prefix.Name"), is("test")); + assertThat(soneFieldSet.get("Prefix.NiceName"), is("First M. Last")); + assertThat(soneFieldSet.getLong("Prefix.LastUpdated"), is(sone.getTime())); + assertThat(soneFieldSet.getInt("Prefix.Field.Count"), is(1)); + assertThat(soneFieldSet.get("Prefix.Field.0.Name"), is("Test1")); + assertThat(soneFieldSet.get("Prefix.Field.0.Value"), is("Value1")); + } + + private Sone prepareSoneToBeEncoded() { + long time = (long) (Math.random() * Long.MAX_VALUE); + Sone sone = mock(Sone.class); + Profile profile = new Profile(sone); + profile.modify().setFirstName("First").setMiddleName("M.").setLastName("Last").update(); + profile.setField(profile.addField("Test1"), "Value1"); + when(sone.getName()).thenReturn("test"); + when(sone.getTime()).thenReturn(time); + when(sone.getProfile()).thenReturn(profile); + return sone; + } + }