* The database
*/
@Inject
- public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database) {
- super("Sone Core");
- this.configuration = configuration;
- this.freenetInterface = freenetInterface;
- this.identityManager = identityManager;
- this.soneDownloader = soneDownloader;
- this.imageInserter = new ImageInserter(freenetInterface, freenetInterface.new InsertTokenSupplier());
- this.updateChecker = updateChecker;
- this.webOfTrustUpdater = webOfTrustUpdater;
- this.eventBus = eventBus;
- this.database = database;
- preferences = new Preferences(eventBus);
- }
-
- @VisibleForTesting
- protected Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database) {
+ public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database) {
super("Sone Core");
this.configuration = configuration;
this.freenetInterface = freenetInterface;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
+import javax.inject.Inject;
import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent;
import net.pterodactylus.sone.core.event.ImageInsertFailedEvent;
import com.google.common.base.Function;
import com.google.common.eventbus.EventBus;
-import com.google.inject.Inject;
import com.google.inject.Singleton;
import freenet.client.ClientMetadata;
}
- public class InsertTokenSupplier implements Function<Image, InsertToken> {
+ public static class InsertTokenSupplier implements Function<Image, InsertToken> {
+
+ private final FreenetInterface freenetInterface;
+
+ @Inject
+ public InsertTokenSupplier(FreenetInterface freenetInterface) {
+ this.freenetInterface = freenetInterface;
+ }
@Override
public InsertToken apply(Image image) {
- return new InsertToken(image);
+ return freenetInterface.new InsertToken(image);
}
}
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.inject.Inject;
+
import net.pterodactylus.sone.core.FreenetInterface.InsertToken;
+import net.pterodactylus.sone.core.FreenetInterface.InsertTokenSupplier;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.TemporaryImage;
* @param insertTokenSupplier
* The supplier for insert tokens
*/
- public ImageInserter(FreenetInterface freenetInterface, Function<Image, InsertToken> insertTokenSupplier) {
+ @Inject
+ public ImageInserter(FreenetInterface freenetInterface, InsertTokenSupplier insertTokenSupplier) {
this.freenetInterface = freenetInterface;
this.insertTokenSupplier = insertTokenSupplier;
}
@Test
public void insertTokenSupplierSuppliesInsertTokens() {
- InsertTokenSupplier insertTokenSupplier = freenetInterface.new InsertTokenSupplier();
+ InsertTokenSupplier insertTokenSupplier = new InsertTokenSupplier(freenetInterface);
assertThat(insertTokenSupplier.apply(image), notNullValue());
}
import net.pterodactylus.sone.core.FreenetInterface.InsertTokenSupplier
import net.pterodactylus.sone.data.Image
import net.pterodactylus.sone.data.TemporaryImage
+import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.web.baseInjector
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.notNullValue
import org.junit.Test
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.eq
verify(insertToken).cancel()
}
+ @Test
+ fun `image inserter can be created by dependency injection`() {
+ assertThat(baseInjector.getInstance<ImageInserter>(), notNullValue())
+ }
+
}