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=73a98a91555f09793931ece6a0930f1cad47c63e;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 2b9854d..de5931c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt @@ -1,9 +1,9 @@ package net.pterodactylus.sone.test -import org.junit.rules.ExpectedException import java.io.InputStreamReader import java.nio.charset.Charset import java.nio.charset.StandardCharsets.UTF_8 +import org.junit.Assert.assertThrows import sun.misc.Unsafe inline fun setField(instance: O, name: String, value: Any?) { @@ -15,7 +15,7 @@ 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) fun resource(name: String, resourceClass: Class<*>, encoding: Charset = UTF_8): String? = resourceClass.getResourceAsStream(name)?.use { inputStream -> InputStreamReader(inputStream, encoding).use { inputStreamReader ->