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<PluginException> {
+ runBlocking {
pluginConnector.sendRequest("wrong.plugin", requestFields, requestData)
- Unit
+ }
+ }
}
@Test
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 <reified O : Any> setField(instance: O, name: String, value: Any?) {
unsafe.putObject(instance, offset, value)
}
-inline fun <reified T : Throwable> ExpectedException.expect() = expect(T::class.java)
+inline fun <reified T : Throwable> 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 ->