🔀 Merge branch 'release-79'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / utils / ObjectsTest.kt
index 1c2d7f5..9e96bfe 100644 (file)
@@ -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))
+       }
+
 }