import net.pterodactylus.sone.freenet.wot.*;
import net.pterodactylus.sone.web.*;
import net.pterodactylus.sone.web.notification.NotificationHandler;
+import net.pterodactylus.sone.web.notification.NotificationHandlerModule;
import freenet.l10n.BaseL10n.*;
import freenet.l10n.*;
/* create the web interface. */
webInterface = injector.getInstance(WebInterface.class);
- NotificationHandler notificationHandler = injector.getInstance(NotificationHandler.class);
+
+ /* we need to request this to install all notification handlers. */
+ injector.getInstance(NotificationHandler.class);
/* start core! */
core.start();
webInterface.start();
webInterface.setFirstStart(injector.getInstance(Key.get(Boolean.class, Names.named("FirstStart"))));
webInterface.setNewConfig(injector.getInstance(Key.get(Boolean.class, Names.named("NewConfig"))));
- notificationHandler.start();
}
@VisibleForTesting
FreenetModule freenetModule = new FreenetModule(pluginRespirator);
AbstractModule soneModule = new SoneModule(this, new EventBus());
Module webInterfaceModule = new WebInterfaceModule();
+ Module notificationHandlerModule = new NotificationHandlerModule();
- return createInjector(freenetModule, soneModule, webInterfaceModule);
+ return createInjector(freenetModule, soneModule, webInterfaceModule, notificationHandlerModule);
}
@VisibleForTesting
package net.pterodactylus.sone.web
-import com.google.common.eventbus.*
import com.google.inject.*
import freenet.support.api.*
import net.pterodactylus.sone.core.*
import net.pterodactylus.sone.main.*
import net.pterodactylus.sone.template.*
import net.pterodactylus.sone.text.*
-import net.pterodactylus.sone.web.notification.*
import net.pterodactylus.util.notify.*
import net.pterodactylus.util.template.*
import javax.inject.*
fun getNotificationManager() =
NotificationManager()
- @Provides
- @Singleton
- fun getNotificationHandler(eventBus: EventBus, loaders: Loaders, notificationManager: NotificationManager) =
- NotificationHandler(eventBus, loaders, notificationManager)
-
}
@Dirty
class SonePluginTest {
- private var injector = mockInjector()
private val sonePlugin by lazy { SonePlugin { injector } }
private val pluginRespirator = deepMock<PluginRespirator>()
private val node = deepMock<Node>()
}
@Test
- fun `notification handler is being started`() {
+ fun `notification handler is being requested`() {
sonePlugin.runPlugin(pluginRespirator)
- val notificationHandler = injector.getInstance<NotificationHandler>()
- verify(notificationHandler).start()
+ assertThat(getInjected(NotificationHandler::class.java), notNullValue())
}
-}
+ private fun <T> getInjected(clazz: Class<T>, annotation: Annotation? = null): T? =
+ injected[TypeLiteral.get(clazz) to annotation] as? T
+
+ private val injected =
+ mutableMapOf<Pair<TypeLiteral<*>, Annotation?>, Any>()
-private fun mockInjector() = mock<Injector>().apply {
- val injected = mutableMapOf<Pair<TypeLiteral<*>, Annotation?>, Any>()
- fun mockValue(clazz: Class<*>) = false.takeIf { clazz.name == java.lang.Boolean::class.java.name } ?: mock(clazz)
- whenever(getInstance(any<Key<*>>())).then {
- injected.getOrPut((it.getArgument(0) as Key<*>).let { it.typeLiteral to it.annotation }) {
- it.getArgument<Key<*>>(0).typeLiteral.type.typeName.toClass().let(::mockValue)
+ private val injector = mock<Injector>().apply {
+ fun mockValue(clazz: Class<*>) = false.takeIf { clazz.name == java.lang.Boolean::class.java.name } ?: mock(clazz)
+ whenever(getInstance(any<Key<*>>())).then {
+ injected.getOrPut((it.getArgument(0) as Key<*>).let { it.typeLiteral to it.annotation }) {
+ it.getArgument<Key<*>>(0).typeLiteral.type.typeName.toClass().let(::mockValue)
+ }
}
- }
- whenever(getInstance(any<Class<*>>())).then {
- injected.getOrPut(TypeLiteral.get(it.getArgument(0) as Class<*>) to null) {
- it.getArgument<Class<*>>(0).let(::mockValue)
+ whenever(getInstance(any<Class<*>>())).then {
+ injected.getOrPut(TypeLiteral.get(it.getArgument(0) as Class<*>) to null) {
+ it.getArgument<Class<*>>(0).let(::mockValue)
+ }
}
}
+
}
private fun String.toClass(): Class<*> = SonePlugin::class.java.classLoader.loadClass(this)