X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FObjectsTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FObjectsTest.kt;h=9e96bfe647994cb28e981f12422db90ed358e831;hp=1c2d7f57f0210846340ab0147ad54e55246f8b65;hb=03cec6a6772c2d836d94864adddaf544cbe9d72f;hpb=6f1f26e3998cfef155b0cf59152827accea70d30 diff --git a/src/test/kotlin/net/pterodactylus/sone/utils/ObjectsTest.kt b/src/test/kotlin/net/pterodactylus/sone/utils/ObjectsTest.kt index 1c2d7f5..9e96bfe 100644 --- a/src/test/kotlin/net/pterodactylus/sone/utils/ObjectsTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/utils/ObjectsTest.kt @@ -1,8 +1,7 @@ package net.pterodactylus.sone.utils import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.contains -import org.hamcrest.Matchers.empty +import org.hamcrest.Matchers.* import org.junit.Test /** @@ -20,4 +19,26 @@ class ObjectsTest { assertThat(null.asList(), empty()) } + @Test(expected = IllegalArgumentException::class) + fun `exception is thrown for null and true condition`() { + null.throwOnNullIf(true) { IllegalArgumentException() } + } + + @Test + fun `exception is not thrown for null and false condition`() { + assertThat(null.throwOnNullIf(false) { IllegalArgumentException() }, nullValue()) + } + + @Test + fun `exception is not thrown for any and true condition`() { + val any = Any() + assertThat(any.throwOnNullIf(true) { IllegalArgumentException() }, equalTo(any)) + } + + @Test + fun `exception is not thrown for any and false condition`() { + val any = Any() + assertThat(any.throwOnNullIf(false) { IllegalArgumentException() }, equalTo(any)) + } + }