🚚 Rename method to better reflect purpose
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / freenet / plugin / PluginRespiratorFacadeTest.kt
1 package net.pterodactylus.sone.freenet.plugin
2
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.*
12 import kotlin.test.*
13
14 /**
15  * Unit test for [FredPluginRespiratorFacade] and [FredPluginTalkerFacade].
16  */
17 @Suppress("DEPRECATION")
18 class PluginRespiratorFacadeTest {
19
20         @Test
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))
26                                 Unit
27                         }
28                 }
29                 val fredPluginTalker = FredPluginTalker { _, _, _, _ -> }
30                 val pluginRespirator = mock<PluginRespirator>().apply {
31                         whenever(getPluginTalker(fredPluginTalker, "test.plugin", "test-request-1")).thenReturn(originalPluginTalker)
32                 }
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))
39         }
40
41 }
42
43 private val fields = SimpleFieldSetBuilder().put("foo", "bar").get()
44 private val data: Bucket? = ArrayBucket(byteArrayOf(1, 2))
45
46 private data class PluginTalkerSendParameters(val parameter: SimpleFieldSet, val data: Bucket?)