X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloaderTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloaderTest.java;h=24a1ac91ad4a970d64d65f0eead117f8fbed020b;hp=b05d2ca86807c1c0463ceffac3164ea3235f7c86;hb=40a1ac4c90c1480936c9c782727209cf23acd5e5;hpb=3568c3e220993291936f182ee1845bd795b8f513 diff --git a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java index b05d2ca..24a1ac9 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java @@ -75,6 +75,7 @@ public class SoneDownloaderTest { private final Core core = mock(Core.class); private final FreenetInterface freenetInterface = mock(FreenetInterface.class); private final SoneDownloaderImpl soneDownloader = new SoneDownloaderImpl(core, freenetInterface); + private final SoneUpdater soneUpdater = mock(SoneUpdater.class); private final FreenetURI requestUri = mock(FreenetURI.class); private final Sone sone = mock(Sone.class); private final PostBuilder postBuilder = mock(PostBuilder.class); @@ -341,7 +342,7 @@ public class SoneDownloaderTest { @Test public void addingASoneWillRegisterItsKey() { soneDownloader.addSone(sone); - verify(freenetInterface).registerUsk(sone, soneDownloader); + verify(freenetInterface).registerUsk(eq(sone), any(SoneUpdater.class)); verify(freenetInterface, never()).unregisterUsk(sone); } @@ -349,7 +350,7 @@ public class SoneDownloaderTest { public void addingASoneTwiceWillAlsoDeregisterItsKey() { soneDownloader.addSone(sone); soneDownloader.addSone(sone); - verify(freenetInterface, times(2)).registerUsk(sone, soneDownloader); + verify(freenetInterface, times(2)).registerUsk(eq(sone), any(SoneUpdater.class)); verify(freenetInterface).unregisterUsk(sone); } @@ -730,7 +731,7 @@ public class SoneDownloaderTest { @Test public void notBeingAbleToFetchAnUnknownSoneDoesNotUpdateCore() { - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); verify(freenetInterface).fetchUri(requestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(unknown); verify(core, never()).updateSone(any(Sone.class)); @@ -746,7 +747,7 @@ public class SoneDownloaderTest { @Test public void notBeingAbleToFetchAKnownSoneDoesNotUpdateCore() { when(sone.getTime()).thenReturn(1000L); - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); verify(freenetInterface).fetchUri(requestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(idle); verify(core, never()).updateSone(any(Sone.class)); @@ -756,7 +757,7 @@ public class SoneDownloaderTest { public void exceptionWhileFetchingAnUnknownSoneDoesNotUpdateCore() { when(freenetInterface.fetchUri(requestUri)).thenThrow(NullPointerException.class); try { - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); } finally { verify(freenetInterface).fetchUri(requestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(unknown); @@ -769,7 +770,7 @@ public class SoneDownloaderTest { when(sone.getTime()).thenReturn(1000L); when(freenetInterface.fetchUri(requestUri)).thenThrow(NullPointerException.class); try { - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); } finally { verify(freenetInterface).fetchUri(requestUri); verifyThatSoneStatusWasChangedToDownloadingAndBackTo(idle); @@ -781,7 +782,7 @@ public class SoneDownloaderTest { public void successfulFetchingOfSoneWithUskRequestUriUpdatesTheCoreWithASone() throws IOException { final Fetched fetchResult = createFetchResult(requestUri, getClass().getResourceAsStream("sone-parser-no-payload.xml")); when(freenetInterface.fetchUri(requestUri)).thenReturn(fetchResult); - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); verifyThatParsedSoneHasTheSameIdAsTheOriginalSone(); } @@ -796,7 +797,7 @@ public class SoneDownloaderTest { when(requestUri.getKeyType()).thenReturn("SSK"); final Fetched fetchResult = createFetchResult(requestUri, getClass().getResourceAsStream("sone-parser-no-payload.xml")); when(freenetInterface.fetchUri(requestUri)).thenReturn(fetchResult); - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); verifyThatParsedSoneHasTheSameIdAsTheOriginalSone(); } @@ -805,7 +806,7 @@ public class SoneDownloaderTest { when(requestUri.getKeyType()).thenReturn("SSK"); final Fetched fetchResult = createFetchResult(requestUri, getClass().getResourceAsStream("sone-parser-with-zero-time.xml")); when(freenetInterface.fetchUri(requestUri)).thenReturn(fetchResult); - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); verifyThatParsedSoneHasTheSameIdAsTheOriginalSone(); } @@ -813,7 +814,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.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); verify(core, never()).updateSone(any(Sone.class)); } @@ -822,7 +823,7 @@ public class SoneDownloaderTest { final Fetched fetchResult = createFetchResult(requestUri, getClass().getResourceAsStream("sone-parser-no-payload.xml")); when(sone.getId()).thenThrow(NullPointerException.class); when(freenetInterface.fetchUri(requestUri)).thenReturn(fetchResult); - soneDownloader.fetchSone(sone); + soneDownloader.fetchSoneAction(sone).run(); verify(core, never()).updateSone(any(Sone.class)); }