From: David ‘Bombe’ Roden Date: Thu, 1 Feb 2018 17:55:43 +0000 (+0100) Subject: Add test for DI constructability of SoneDownloader X-Git-Tag: v79^2~152 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=534abb5d5dba7f0377856d2d067ae48538226680;p=Sone.git Add test for DI constructability of SoneDownloader --- diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index be0be02..039faad 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -5,12 +5,15 @@ import net.pterodactylus.util.service.Service; import freenet.keys.FreenetURI; +import com.google.inject.ImplementedBy; + /** * Downloads and parses Sone and {@link Core#updateSone(Sone) updates the * core}. * * @author David ‘Bombe’ Roden */ +@ImplementedBy(SoneDownloaderImpl.class) public interface SoneDownloader extends Service { void addSone(Sone sone); diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java index a859106..d3f23ed 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java @@ -29,6 +29,8 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import javax.inject.Inject; + import net.pterodactylus.sone.core.FreenetInterface.Fetched; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; @@ -75,6 +77,7 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade * @param freenetInterface * The Freenet interface */ + @Inject public SoneDownloaderImpl(Core core, FreenetInterface freenetInterface) { this(core, freenetInterface, new SoneParser(core)); } diff --git a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java index 9043974..be697b3 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java @@ -6,8 +6,10 @@ import static java.util.concurrent.TimeUnit.DAYS; import static net.pterodactylus.sone.data.Sone.SoneStatus.downloading; import static net.pterodactylus.sone.data.Sone.SoneStatus.idle; import static net.pterodactylus.sone.data.Sone.SoneStatus.unknown; +import static net.pterodactylus.sone.web.AllPagesTestKt.getBaseInjector; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; import static org.mockito.ArgumentCaptor.forClass; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -193,4 +195,9 @@ public class SoneDownloaderTest { return new Fetched(uri, fetchResult); } + @Test + public void soneDownloaderCanBeCreatedByDependencyInjection() { + assertThat(getBaseInjector().getInstance(SoneDownloader.class), notNullValue()); + } + } diff --git a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt index da05926..9e395f2 100644 --- a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt +++ b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt @@ -1,6 +1,8 @@ package net.pterodactylus.sone.web import com.google.inject.Guice.createInjector +import net.pterodactylus.sone.core.Core +import net.pterodactylus.sone.core.FreenetInterface import net.pterodactylus.sone.main.SonePlugin.PluginHomepage import net.pterodactylus.sone.main.SonePlugin.PluginVersion import net.pterodactylus.sone.main.SonePlugin.PluginYear @@ -34,6 +36,8 @@ class AllPagesTest { val baseInjector by lazy { createInjector( + Core::class.isProvidedByMock(), + FreenetInterface::class.isProvidedByMock(), Template::class.isProvidedByMock(), WebInterface::class.isProvidedByMock() )!!