From: David ‘Bombe’ Roden Date: Tue, 11 Feb 2020 19:20:05 +0000 (+0100) Subject: 🔇 Silence logger during freenet interface test X-Git-Tag: v82^2~75 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b47ccc9c7796fa160777a03aef49f1168623fbc8;p=Sone.git 🔇 Silence logger during freenet interface test --- diff --git a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt index e02cddb..81b4e04 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt @@ -43,6 +43,10 @@ class FreenetInterfaceTest { @JvmField val expectionException: ExpectedException = ExpectedException.none() + @Rule + @JvmField + val silencedLogging = silencedLogging() + @Suppress("UnstableApiUsage") private val eventBus = mock() private val node = mock() diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Logging.kt b/src/test/kotlin/net/pterodactylus/sone/test/Logging.kt new file mode 100644 index 0000000..2a2c6b7 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/test/Logging.kt @@ -0,0 +1,25 @@ +package net.pterodactylus.sone.test + +import org.junit.rules.TestRule +import org.junit.runners.model.Statement +import java.util.logging.Level +import java.util.logging.Logger.getLogger + +/** + * Silences the `net.pterodactylus.sone` [logger][java.util.logging.Logger] during a test. + */ +fun silencedLogging() = TestRule { base, _ -> + object : Statement() { + override fun evaluate() { + getLogger("net.pterodactylus.sone").let { logger -> + val oldLevel = logger.level + logger.level = Level.OFF + try { + base.evaluate() + } finally { + logger.level = oldLevel + } + } + } + } +}