From f1703685a5b1118d7c4ce35f5f4a23917efcb362 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 25 Oct 2013 19:29:51 +0200 Subject: [PATCH] Add test for encoding a Sone. --- .../sone/fcp/AbstractSoneCommandTest.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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; + } + } -- 2.7.4