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;
/**
* Unit test for {@link SoneDownloaderImpl} and its subclasses.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
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));
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));
setupSoneAsUnknown();
when(freenetInterface.fetchUri(finalRequestUri)).thenThrow(NullPointerException.class);
try {
- soneDownloader.fetchSoneAction(sone).run();
+ soneDownloader.fetchSoneAsSskAction(sone).run();
} finally {
verify(freenetInterface).fetchUri(finalRequestUri);
verifyThatSoneStatusWasChangedToDownloadingAndBackTo(unknown);
.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);
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));
}
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));
}
@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());
}
}