import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.nullValue
import org.junit.Test
+import java.util.concurrent.atomic.AtomicBoolean
/**
* Test for [Optional] utils.
}
@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))