X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloaderTest.java;h=568d76cd0709aedfbefe820241c6c648966595c0;hp=be697b3c6abd335f774655694e0cf56f48229dea;hb=62573c314957b1851f4fbe693b8746686caa940a;hpb=534abb5d5dba7f0377856d2d067ae48538226680 diff --git a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java index be697b3..568d76c 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java @@ -22,10 +22,10 @@ import static org.mockito.Mockito.when; import java.io.IOException; import java.io.InputStream; -import net.pterodactylus.sone.core.FreenetInterface.Fetched; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; import net.pterodactylus.sone.freenet.wot.Identity; +import net.pterodactylus.sone.test.GuiceKt; import freenet.client.ClientMetadata; import freenet.client.FetchResult; @@ -43,8 +43,6 @@ import org.mockito.stubbing.Answer; /** * Unit test for {@link SoneDownloaderImpl} and its subclasses. - * - * @author David ‘Bombe’ Roden */ public class SoneDownloaderTest { @@ -109,7 +107,7 @@ public class SoneDownloaderTest { FreenetURI finalRequestUri = requestUri.sskForUSK() .setMetaString(new String[] { "sone.xml" }); setupSoneAsUnknown(); - soneDownloader.fetchSoneAction(sone).run(); + soneDownloader.fetchSoneAsSskAction(sone).run(); verify(freenetInterface).fetchUri(finalRequestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(unknown); verify(core, never()).updateSone(any(Sone.class)); @@ -126,7 +124,7 @@ public class SoneDownloaderTest { public void notBeingAbleToFetchAKnownSoneDoesNotUpdateCore() { FreenetURI finalRequestUri = requestUri.sskForUSK() .setMetaString(new String[] { "sone.xml" }); - soneDownloader.fetchSoneAction(sone).run(); + soneDownloader.fetchSoneAsSskAction(sone).run(); verify(freenetInterface).fetchUri(finalRequestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(idle); verify(core, never()).updateSone(any(Sone.class)); @@ -139,7 +137,7 @@ public class SoneDownloaderTest { setupSoneAsUnknown(); when(freenetInterface.fetchUri(finalRequestUri)).thenThrow(NullPointerException.class); try { - soneDownloader.fetchSoneAction(sone).run(); + soneDownloader.fetchSoneAsSskAction(sone).run(); } finally { verify(freenetInterface).fetchUri(finalRequestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(unknown); @@ -153,7 +151,7 @@ public class SoneDownloaderTest { .setMetaString(new String[] { "sone.xml" }); when(freenetInterface.fetchUri(finalRequestUri)).thenThrow( NullPointerException.class); try { - soneDownloader.fetchSoneAction(sone).run(); + soneDownloader.fetchSoneAsSskAction(sone).run(); } finally { verify(freenetInterface).fetchUri(finalRequestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(idle); @@ -165,7 +163,7 @@ public class SoneDownloaderTest { public void fetchingSoneWithInvalidXmlWillNotUpdateTheCore() throws IOException { final Fetched fetchResult = createFetchResult(requestUri, getClass().getResourceAsStream("sone-parser-not-xml.xml")); when(freenetInterface.fetchUri(requestUri)).thenReturn(fetchResult); - soneDownloader.fetchSoneAction(sone).run(); + soneDownloader.fetchSoneAsSskAction(sone).run(); verify(core, never()).updateSone(any(Sone.class)); } @@ -174,7 +172,7 @@ public class SoneDownloaderTest { final Fetched fetchResult = createFetchResult(requestUri, getClass().getResourceAsStream("sone-parser-no-payload.xml")); when(core.soneBuilder()).thenReturn(null); when(freenetInterface.fetchUri(requestUri)).thenReturn(fetchResult); - soneDownloader.fetchSoneAction(sone).run(); + soneDownloader.fetchSoneAsSskAction(sone).run(); verify(core, never()).updateSone(any(Sone.class)); } @@ -197,7 +195,9 @@ public class SoneDownloaderTest { @Test public void soneDownloaderCanBeCreatedByDependencyInjection() { - assertThat(getBaseInjector().getInstance(SoneDownloader.class), notNullValue()); + assertThat(getBaseInjector().createChildInjector( + GuiceKt.supply(SoneParser.class).byInstance(mock(SoneParser.class)) + ).getInstance(SoneDownloader.class), notNullValue()); } }