From b34232ccf21c829b17aa6944e532af3da712c392 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 27 Jun 2014 18:32:44 +0200 Subject: [PATCH] Inject identity loader instead of context into identity manager. --- .../net/pterodactylus/sone/freenet/wot/IdentityManager.java | 7 ++----- src/main/java/net/pterodactylus/sone/main/SonePlugin.java | 12 +++++++++++- .../pterodactylus/sone/freenet/wot/IdentityManagerTest.java | 4 +++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java index 810e054..22c1b71 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java @@ -68,16 +68,13 @@ public class IdentityManager extends AbstractService { * The event bus * @param webOfTrustConnector * The Web of Trust connector - * @param context - * The context to focus on (may be {@code null} to ignore - * contexts) */ @Inject - public IdentityManager(EventBus eventBus, WebOfTrustConnector webOfTrustConnector, Context context) { + public IdentityManager(EventBus eventBus, WebOfTrustConnector webOfTrustConnector, IdentityLoader identityLoader) { super("Sone Identity Manager", false); this.eventBus = eventBus; this.webOfTrustConnector = webOfTrustConnector; - this.identityLoader = new IdentityLoader(webOfTrustConnector, fromNullable(context.getContext())); + this.identityLoader = identityLoader; } // diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index 5b27282..6743197 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.main; +import static com.google.common.base.Optional.of; + import java.io.File; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -45,6 +47,7 @@ import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.logging.LoggingListener; import net.pterodactylus.util.version.Version; +import com.google.common.base.Optional; import com.google.common.eventbus.EventBus; import com.google.inject.AbstractModule; import com.google.inject.Guice; @@ -225,7 +228,9 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr bind(Configuration.class).toInstance(startConfiguration); bind(FreenetInterface.class).in(Singleton.class); bind(PluginConnector.class).in(Singleton.class); - bind(Context.class).toInstance(new Context("Sone")); + Context context = new Context("Sone"); + bind(Context.class).toInstance(context); + bind(getOptionalContextTypeLiteral()).toInstance(of(context)); bind(WebOfTrustConnector.class).in(Singleton.class); bind(WebOfTrustUpdater.class).in(Singleton.class); bind(IdentityManager.class).in(Singleton.class); @@ -251,6 +256,11 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr }); } + private TypeLiteral> getOptionalContextTypeLiteral() { + return new TypeLiteral>() { + }; + } + }; Injector injector = Guice.createInjector(freenetModule, soneModule); core = injector.getInstance(Core.class); diff --git a/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java b/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java index 2bb6d1f..548e46b 100644 --- a/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java +++ b/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java @@ -1,5 +1,7 @@ package net.pterodactylus.sone.freenet.wot; +import static com.google.common.base.Optional.fromNullable; +import static com.google.common.base.Optional.of; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.doThrow; @@ -20,7 +22,7 @@ public class IdentityManagerTest { private final EventBus eventBus = mock(EventBus.class); private final WebOfTrustConnector webOfTrustConnector = mock(WebOfTrustConnector.class); - private final IdentityManager identityManager = new IdentityManager(eventBus, webOfTrustConnector, new Context("Test")); + private final IdentityManager identityManager = new IdentityManager(eventBus, webOfTrustConnector, new IdentityLoader(webOfTrustConnector, of(new Context("Test")))); @Test public void identityManagerPingsWotConnector() throws PluginException { -- 2.7.4