Skip to content

Commit e72291f

Browse files
committed
Added the OptionAssert
1 parent b71c01f commit e72291f

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package `in`.rcard.assertj.arrowcore
2+
3+
import arrow.core.Option
4+
import org.assertj.core.api.AbstractObjectAssert
5+
6+
/**
7+
* Assertions for [Option].
8+
*
9+
* @param SELF the "self" type of this assertion class.
10+
* @param VALUE type of the value contained in the [Option].
11+
* @author Riccardo Cardin
12+
*/
13+
abstract class AbstractOptionAssert<
14+
SELF : AbstractOptionAssert<SELF, VALUE>, VALUE : Any,
15+
>(
16+
option: Option<VALUE>?,
17+
) : AbstractObjectAssert<SELF, Option<VALUE>>(option, AbstractOptionAssert::class.java)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package `in`.rcard.assertj.arrowcore
2+
3+
import arrow.core.Option
4+
5+
class OptionAssert<VALUE : Any>(option: Option<VALUE>?) :
6+
AbstractOptionAssert<OptionAssert<VALUE>, VALUE>(option) {
7+
companion object {
8+
fun <VALUE : Any> assertThat(option: Option<VALUE>?): OptionAssert<VALUE> =
9+
OptionAssert(option)
10+
}
11+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package `in`.rcard.assertj.arrowcore
2+
3+
import arrow.core.Option
4+
import arrow.core.some
5+
import org.assertj.core.api.BDDAssertions.then
6+
import org.junit.jupiter.api.Test
7+
8+
class OptionAssert_assertThat_Test {
9+
10+
@Test
11+
fun `should create an assertion instance when given object is not null`() {
12+
// GIVEN
13+
val someValue = 42.some()
14+
// WHEN
15+
val assertion = OptionAssert.assertThat<Any>(someValue)
16+
// THEN
17+
then(assertion).isNotNull.isInstanceOf(OptionAssert::class.java)
18+
}
19+
20+
@Test
21+
fun `should create an assertion instance when given object is null`() {
22+
// GIVEN
23+
val someNullValue: Option<Nothing>? = null
24+
// WHEN
25+
val assertion = OptionAssert.assertThat(someNullValue)
26+
// THEN
27+
then(assertion).isNotNull.isInstanceOf(OptionAssert::class.java)
28+
}
29+
}

0 commit comments

Comments
 (0)