From c92981025804bb1012a787dc19ec72842645c7ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 28 Sep 2024 18:04:37 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Mock=20methods=20instead=20of=20sett?= =?utf8?q?ing=20private=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/FreenetInterface.java | 2 +- src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt | 6 +++--- src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt | 2 +- src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt | 6 +++--- src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 0f05fc7..32f97b2 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -223,7 +223,7 @@ public class FreenetInterface { */ public void insertImage(TemporaryImage temporaryImage, Image image, InsertToken insertToken) throws SoneException { String filenameHint = image.getId() + "." + temporaryImage.getMimeType().substring(temporaryImage.getMimeType().lastIndexOf("/") + 1); - InsertableClientSSK key = InsertableClientSSK.createRandom(node.random, ""); + InsertableClientSSK key = InsertableClientSSK.createRandom(node.getRandom(), ""); FreenetURI targetUri = key.getInsertURI().setDocName(filenameHint); InsertContext insertContext = client.getInsertContext(true); RandomAccessBucket bucket = new ArrayBucket(temporaryImage.getImageData()); diff --git a/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt index 691ae4e..f2ff6fc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt @@ -33,7 +33,7 @@ class FreenetModule(private val pluginRespirator: PluginRespirator) : Module { @Provides fun getNodeClientCore(node: Node): NodeClientCore = - node.clientCore + node.getClientCore() @Provides fun getHighLevelSimpleClientCreator(nodeClientCore: NodeClientCore): HighLevelSimpleClientCreator = @@ -41,10 +41,10 @@ class FreenetModule(private val pluginRespirator: PluginRespirator) : Module { @Provides fun getClientContext(nodeClientCore: NodeClientCore): ClientContext = - nodeClientCore.clientContext + nodeClientCore.getClientContext() @Provides fun getUskManager(nodeClientCore: NodeClientCore): USKManager = - nodeClientCore.uskManager + nodeClientCore.getUskManager() } diff --git a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt index ffd5c60..ca5e21b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt @@ -69,7 +69,7 @@ class FreenetInterfaceTest { private val freenetInterface: FreenetInterface init { - setField(node, "random", randomSource) + whenever(node.getRandom()).thenReturn(randomSource) freenetInterface = FreenetInterface(eventBus, node, uskManager, clientContext, soneUriCreator) { _, _, _ -> highLevelSimpleClient } insertToken = freenetInterface.InsertToken(image) insertToken.setBucket(bucket) diff --git a/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt index 84cb567..476b935 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt @@ -33,11 +33,11 @@ class FreenetModuleTest { whenever(getSessionManager("Sone")).thenReturn(sessionManager) } private val nodeClientCore = mock().also { - setField(it, "uskManager", uskManager) - setField(it, "clientContext", clientContext) + whenever(it.getUskManager()).thenReturn(uskManager) + whenever(it.getClientContext()).thenReturn(clientContext) } private val node = pluginRespirator.node!!.also { - setField(it, "clientCore", nodeClientCore) + whenever(it.getClientCore()).thenReturn(nodeClientCore) } private val highLevelSimpleClient = pluginRespirator.hlSimpleClient!! private val toadletContainer: ToadletContainer = pluginRespirator.toadletContainer diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt index 3983aa2..dfa4830 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt @@ -35,10 +35,10 @@ class SonePluginTest { private val uskManager = deepMock() init { - setField(node, "clientCore", clientCore) + whenever(node.getClientCore()).thenReturn(clientCore) whenever(pluginRespirator.node).thenReturn(node) - setField(clientCore, "uskManager", uskManager) - setField(clientCore, "clientContext", mock()) + whenever(clientCore.getUskManager()).thenReturn(uskManager) + whenever(clientCore.getClientContext()).thenReturnMock() } @Test -- 2.7.4