From e28ea0c647737dfe23bd8b77c6480986b320d312 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:34:47 +0200 Subject: [PATCH] =?utf8?q?Add=20tests=20for=20verifying=20the=20=E2=80=9CF?= =?utf8?q?ollowed=E2=80=9D=20attribute=20if=20a=20local=20Sone=20is=20give?= =?utf8?q?n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/fcp/AbstractSoneCommandTest.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index f0fd58c..b5de50e 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.fcp; +import static com.google.common.base.Optional.of; import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeSone; import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeString; import static org.hamcrest.CoreMatchers.is; @@ -34,6 +35,7 @@ import freenet.support.SimpleFieldSet; import com.google.common.base.Optional; import org.junit.Test; +import org.mockito.Matchers; /** * Unit test for {@link AbstractSoneCommand}. @@ -73,6 +75,48 @@ public class AbstractSoneCommandTest { assertThat(soneFieldSet.get("Prefix.Field.0.Value"), is("Value1")); } + @Test + public void testEncodingAFollowedSone() throws FSParseException { + Sone sone = prepareSoneToBeEncoded(); + Sone localSone = prepareLocalSoneThatFollowsEverybody(); + SimpleFieldSet soneFieldSet = encodeSone(sone, "Prefix.", of(localSone)); + 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.get("Prefix.Followed"), is("true")); + 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")); + } + + @Test + public void testEncodingANotFollowedSone() throws FSParseException { + Sone sone = prepareSoneToBeEncoded(); + Sone localSone = prepareLocalSoneThatFollowsNobody(); + SimpleFieldSet soneFieldSet = encodeSone(sone, "Prefix.", of(localSone)); + 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.get("Prefix.Followed"), is("false")); + 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 prepareLocalSoneThatFollowsEverybody() { + Sone sone = mock(Sone.class); + when(sone.hasFriend(Matchers.any())).thenReturn(true); + return sone; + } + + private Sone prepareLocalSoneThatFollowsNobody() { + Sone sone = mock(Sone.class); + when(sone.hasFriend(Matchers.any())).thenReturn(false); + return sone; + } + private Sone prepareSoneToBeEncoded() { long time = (long) (Math.random() * Long.MAX_VALUE); Sone sone = mock(Sone.class); -- 2.7.4