From e89893822ee0b116f964b815b8515acc733ec512 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Aug 2014 19:12:54 +0200 Subject: [PATCH] Increase test coverage. --- .../net/pterodactylus/sone/core/SoneInserter.java | 6 ++-- .../pterodactylus/sone/core/SoneInserterTest.java | 38 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 46a3fe7..734847a 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -265,7 +265,8 @@ public class SoneInserter extends AbstractService { * * @author David ‘Bombe’ Roden */ - private class InsertInformation { + @VisibleForTesting + class InsertInformation { private final String fingerprint; @@ -297,7 +298,8 @@ public class SoneInserter extends AbstractService { // ACCESSORS // - private String getFingerprint() { + @VisibleForTesting + String getFingerprint() { return fingerprint; } diff --git a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java index ed436fe..05cc49e 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java @@ -1,10 +1,21 @@ package net.pterodactylus.sone.core; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.util.HashMap; + +import net.pterodactylus.sone.core.SoneInserter.InsertInformation; import net.pterodactylus.sone.core.SoneInserter.SetInsertionDelay; +import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.Sone; + +import freenet.keys.FreenetURI; +import com.google.common.eventbus.EventBus; import org.junit.Test; /** @@ -21,4 +32,31 @@ public class SoneInserterTest { assertThat(SoneInserter.getInsertionDelay().get(), is(15)); } + @Test + /* this test is hilariously bad. */ + public void manifestEntriesAreCreated() { + FreenetURI insertUri = mock(FreenetURI.class); + String fingerprint = "fingerprint"; + Sone sone = createSone(insertUri, fingerprint); + Core core = mock(Core.class); + UpdateChecker updateChecker = mock(UpdateChecker.class); + when(core.getUpdateChecker()).thenReturn(updateChecker); + EventBus eventBus = mock(EventBus.class); + FreenetInterface freenetInterface = mock(FreenetInterface.class); + SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone); + InsertInformation insertInformation = soneInserter.new InsertInformation(sone); + HashMap manifestEntries = insertInformation.generateManifestEntries(); + assertThat(manifestEntries.keySet(), containsInAnyOrder("index.html", "sone.xml")); + assertThat(insertInformation.getInsertUri(), is(insertUri)); + assertThat(insertInformation.getFingerprint(), is(fingerprint)); + } + + private Sone createSone(FreenetURI insertUri, String fingerprint) { + Sone sone = mock(Sone.class); + when(sone.getInsertUri()).thenReturn(insertUri); + when(sone.getFingerprint()).thenReturn(fingerprint); + when(sone.getRootAlbum()).thenReturn(mock(Album.class)); + return sone; + } + } -- 2.7.4