diff --git a/src/main/kotlin/com/memoizr/assertk/AssertionHooks.kt b/src/main/kotlin/com/memoizr/assertk/AssertionHooks.kt index 9f65922..84042ff 100644 --- a/src/main/kotlin/com/memoizr/assertk/AssertionHooks.kt +++ b/src/main/kotlin/com/memoizr/assertk/AssertionHooks.kt @@ -13,6 +13,7 @@ interface AssertionHook { infix fun that(subjectUnderTest: Float?) = FloatAssert(subjectUnderTest) infix fun that(subjectUnderTest: Double?) = DoubleAssert(subjectUnderTest) infix fun that(subjectUnderTest: Long?) = LongAssert(subjectUnderTest) + infix fun that(subjectUnderTest: Boolean?) = BooleanAssert(subjectUnderTest) } class RealAssertionHook : AssertionHook diff --git a/src/main/kotlin/com/memoizr/assertk/BooleanAssert.kt b/src/main/kotlin/com/memoizr/assertk/BooleanAssert.kt new file mode 100644 index 0000000..593d4f0 --- /dev/null +++ b/src/main/kotlin/com/memoizr/assertk/BooleanAssert.kt @@ -0,0 +1,15 @@ +package com.memoizr.assertk + +import org.assertj.core.api.AbstractBooleanAssert +import org.assertj.core.api.Assertions + +class BooleanAssert internal constructor( + subjectUnderTest: Boolean?, + override val assertion: AbstractBooleanAssert<*> = Assertions.assertThat(subjectUnderTest)) : + AbstractAssertBuilder(subjectUnderTest, BooleanAssert::class.java) { + + infix fun _is(other: Boolean): BooleanAssert { + if (other) assertion.isTrue() else assertion.isFalse() + return this + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/memoizr/assertk/BooleanAssert test.kt b/src/test/kotlin/com/memoizr/assertk/BooleanAssert test.kt new file mode 100644 index 0000000..c4085d0 --- /dev/null +++ b/src/test/kotlin/com/memoizr/assertk/BooleanAssert test.kt @@ -0,0 +1,37 @@ +package com.memoizr.assertk + +import com.nhaarman.mockito_kotlin.never +import com.nhaarman.mockito_kotlin.spy +import com.nhaarman.mockito_kotlin.verify +import org.assertj.core.api.AbstractBooleanAssert +import org.assertj.core.api.Assertions +import org.junit.Test + +class `BooleanAssert test` { + lateinit var mockAssertion: AbstractBooleanAssert<*> + @Suppress("UNCHECKED_CAST") + val _expect = object : AssertionHook { + override fun that(subjectUnderTest: Boolean?): BooleanAssert { + val spy: AbstractBooleanAssert<*> = spy(Assertions.assertThat(subjectUnderTest)) + mockAssertion = spy + return BooleanAssert(subjectUnderTest, mockAssertion) + } + } + + val chained = Any() + infix fun BooleanAssert.andCanBe(chained: Any) = this + + @Test + fun isTrue() { + _expect that true _is true andCanBe chained + verify(mockAssertion).isTrue() + verify(mockAssertion, never()).isFalse() + } + + @Test + fun isFalse() { + _expect that false _is false andCanBe chained + verify(mockAssertion).isFalse() + verify(mockAssertion, never()).isTrue() + } +}