From 080a17e9c42e0b0c5dce8a3a117591b1168eb686 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 6 Apr 2025 10:03:00 +0200 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Replace=20deprecated=20Expe?= =?utf8?q?ctedException=20@Rule=20with=20assertThrows?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/freenet/plugin/FredPluginConnectorTest.kt | 14 ++++++-------- src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/plugin/FredPluginConnectorTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/plugin/FredPluginConnectorTest.kt index 0c68bfe..575218b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/freenet/plugin/FredPluginConnectorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/plugin/FredPluginConnectorTest.kt @@ -29,21 +29,19 @@ import net.pterodactylus.sone.freenet.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* import org.junit.* -import org.junit.rules.* import kotlin.concurrent.* +import net.pterodactylus.sone.test.assertThrows class FredPluginConnectorTest { - @Rule - @JvmField - val expectedException = ExpectedException.none()!! - @Test - fun `connector throws exception if plugin can not be found`() = runBlocking { + fun `connector throws exception if plugin can not be found`() { val pluginConnector = FredPluginConnector(pluginRespiratorFacade) - expectedException.expect(PluginException::class.java) + assertThrows { + runBlocking { pluginConnector.sendRequest("wrong.plugin", requestFields, requestData) - Unit + } + } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt b/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt index e49663f..5af4fbf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt @@ -1,6 +1,6 @@ package net.pterodactylus.sone.test -import org.junit.rules.ExpectedException +import org.junit.Assert.assertThrows import sun.misc.Unsafe inline fun setField(instance: O, name: String, value: Any?) { @@ -12,4 +12,4 @@ inline fun setField(instance: O, name: String, value: Any?) { unsafe.putObject(instance, offset, value) } -inline fun ExpectedException.expect() = expect(T::class.java) +inline fun assertThrows(noinline block: () -> Unit): T = assertThrows(T::class.java, block) -- 2.7.4