From: David ‘Bombe’ Roden Date: Sun, 6 Apr 2025 08:03:00 +0000 (+0200) Subject: ♻️ Replace deprecated ExpectedException @Rule with assertThrows X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=080a17e9c42e0b0c5dce8a3a117591b1168eb686;p=Sone.git ♻️ Replace deprecated ExpectedException @Rule with assertThrows --- 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)