1 package net.pterodactylus.sone.freenet.plugin
3 import freenet.pluginmanager.*
4 import freenet.support.*
5 import freenet.support.api.*
6 import freenet.support.io.*
7 import net.pterodactylus.sone.freenet.*
8 import net.pterodactylus.sone.test.*
9 import org.hamcrest.MatcherAssert.*
10 import org.hamcrest.Matchers.*
11 import org.mockito.ArgumentMatchers.*
15 * Unit test for [FredPluginRespiratorFacade] and [FredPluginTalkerFacade].
17 @Suppress("DEPRECATION")
18 class PluginRespiratorFacadeTest {
21 fun `respirator facade creates correct plugin talker facade`() {
22 val pluginTalkerSendParameters = mutableListOf<PluginTalkerSendParameters>()
23 val originalPluginTalker = mock<PluginTalker>().apply {
24 whenever(send(any(), any())).then { invocation ->
25 pluginTalkerSendParameters += PluginTalkerSendParameters(invocation.getArgument(0), invocation.getArgument(1))
29 val fredPluginTalker = FredPluginTalker { _, _, _, _ -> }
30 val pluginRespirator = mock<PluginRespirator>().apply {
31 whenever(getPluginTalker(fredPluginTalker, "test.plugin", "test-request-1")).thenReturn(originalPluginTalker)
33 val pluginRespiratorFacade = FredPluginRespiratorFacade(pluginRespirator)
34 val pluginTalker = pluginRespiratorFacade.getPluginTalker(fredPluginTalker, "test.plugin", "test-request-1")
35 pluginTalker.send(fields, data)
36 assertThat(pluginTalkerSendParameters, hasSize(1))
37 assertThat(pluginTalkerSendParameters[0].parameter, equalTo(fields))
38 assertThat(pluginTalkerSendParameters[0].data, equalTo(data))
43 private val fields = SimpleFieldSetBuilder().put("foo", "bar").get()
44 private val data: Bucket? = ArrayBucket(byteArrayOf(1, 2))
46 private data class PluginTalkerSendParameters(val parameter: SimpleFieldSet, val data: Bucket?)