Replace unbookmark page with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / utils / OptionalsTest.kt
index 2a49db0..6d35509 100644 (file)
@@ -5,6 +5,7 @@ import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
 import org.hamcrest.Matchers.nullValue
 import org.junit.Test
+import java.util.concurrent.atomic.AtomicBoolean
 
 /**
  * Test for [Optional] utils.
@@ -24,6 +25,20 @@ class OptionalsTest {
        }
 
        @Test
+       fun `present optional can be processed with also`() {
+               val called = AtomicBoolean(false)
+               Optional.of(1).also { if (it == 1) called.set(true) }
+               assertThat(called.get(), equalTo(true))
+       }
+
+       @Test
+       fun `absent optional is not processed with also`() {
+               val called = AtomicBoolean(false)
+               Optional.absent<Int>().also { called.set(true) }
+               assertThat(called.get(), equalTo(false))
+       }
+
+       @Test
        fun `1 as optional is correct optional`() {
                val optional = 1.asOptional()
                assertThat(optional.get(), equalTo(1))