import net.pterodactylus.sone.freenet.wot.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.web.*
+import net.pterodactylus.sone.web.notification.*
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.mockito.Mockito.*
@Dirty
class SonePluginTest {
- private var injector = mockInjector()
private val sonePlugin by lazy { SonePlugin { injector } }
private val pluginRespirator = deepMock<PluginRespirator>()
private val node = deepMock<Node>()
assertThat(injector.getInstance<WebOfTrustConnector>(), notNullValue())
}
+ @Test
+ fun `notification handler can be created`() {
+ val injector: Injector = runSonePluginWithRealInjector()
+ assertThat(injector.getInstance<NotificationHandler>(), notNullValue())
+ }
+
private fun runSonePluginWithRealInjector(): Injector {
lateinit var injector: Injector
val sonePlugin = SonePlugin {
verify(core).start()
}
-}
+ @Test
+ fun `notification handler is being requested`() {
+ sonePlugin.runPlugin(pluginRespirator)
+ 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 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 injected =
+ mutableMapOf<Pair<TypeLiteral<*>, Annotation?>, Any>()
+
+ 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)