Increase test coverage.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Aug 2014 17:12:54 +0000 (19:12 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Aug 2014 17:12:54 +0000 (19:12 +0200)
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java

index 46a3fe7..734847a 100644 (file)
@@ -265,7 +265,8 @@ public class SoneInserter extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       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;
                }
 
index ed436fe..05cc49e 100644 (file)
@@ -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<String, Object> 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;
+       }
+
 }