1 package net.pterodactylus.util.exception
3 import org.hamcrest.MatcherAssert
4 import org.hamcrest.Matchers
6 import java.util.concurrent.atomic.AtomicBoolean
7 import java.util.concurrent.atomic.AtomicReference
12 fun `runnable is run by suppress method`() {
13 val runnabledCalled = AtomicBoolean(false)
14 suppressException({ runnabledCalled.set(true) })()
15 MatcherAssert.assertThat(runnabledCalled.get(), Matchers.equalTo(true))
19 fun `exception thrown in runnable is suppressed`() {
20 suppressException({ throw RuntimeException() })()
24 fun `error runnable is called with exception`() {
25 val caughtException = AtomicReference<Exception>()
26 suppressException({ throw IllegalStateException("Test") }) { caughtException.set(it) }()
27 MatcherAssert.assertThat(caughtException.get(), Matchers.instanceOf(RuntimeException::class.java))
28 MatcherAssert.assertThat(caughtException.get().message, Matchers.equalTo("Test"))