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);
@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);
}
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);
}
@Test
public void notBeingAbleToFetchAnUnknownSoneDoesNotUpdateCore() {
- soneDownloader.fetchSone(sone);
+ soneDownloader.fetchSoneAction(sone).run();
verify(freenetInterface).fetchUri(requestUri);
verifyThatSoneStatusWasChangedToDownloadingAndBackTo(unknown);
verify(core, never()).updateSone(any(Sone.class));
@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));
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);
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);
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();
}
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();
}
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();
}
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));
}
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));
}