Skip to content

Commit 505a61f

Browse files
authored
Merge pull request #4 from memoizr/boolean
add boolean assert
2 parents 9cf09f9 + 017f4f5 commit 505a61f

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/main/kotlin/com/memoizr/assertk/AssertionHooks.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface AssertionHook {
1313
infix fun that(subjectUnderTest: Float?) = FloatAssert(subjectUnderTest)
1414
infix fun that(subjectUnderTest: Double?) = DoubleAssert(subjectUnderTest)
1515
infix fun that(subjectUnderTest: Long?) = LongAssert(subjectUnderTest)
16+
infix fun that(subjectUnderTest: Boolean?) = BooleanAssert(subjectUnderTest)
1617
}
1718

1819
class RealAssertionHook : AssertionHook
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.memoizr.assertk
2+
3+
import org.assertj.core.api.AbstractBooleanAssert
4+
import org.assertj.core.api.Assertions
5+
6+
class BooleanAssert internal constructor(
7+
subjectUnderTest: Boolean?,
8+
override val assertion: AbstractBooleanAssert<*> = Assertions.assertThat(subjectUnderTest)) :
9+
AbstractAssertBuilder<BooleanAssert, Boolean>(subjectUnderTest, BooleanAssert::class.java) {
10+
11+
infix fun _is(other: Boolean): BooleanAssert {
12+
if (other) assertion.isTrue() else assertion.isFalse()
13+
return this
14+
}
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.memoizr.assertk
2+
3+
import com.nhaarman.mockito_kotlin.never
4+
import com.nhaarman.mockito_kotlin.spy
5+
import com.nhaarman.mockito_kotlin.verify
6+
import org.assertj.core.api.AbstractBooleanAssert
7+
import org.assertj.core.api.Assertions
8+
import org.junit.Test
9+
10+
class `BooleanAssert test` {
11+
lateinit var mockAssertion: AbstractBooleanAssert<*>
12+
@Suppress("UNCHECKED_CAST")
13+
val _expect = object : AssertionHook {
14+
override fun that(subjectUnderTest: Boolean?): BooleanAssert {
15+
val spy: AbstractBooleanAssert<*> = spy(Assertions.assertThat(subjectUnderTest))
16+
mockAssertion = spy
17+
return BooleanAssert(subjectUnderTest, mockAssertion)
18+
}
19+
}
20+
21+
val chained = Any()
22+
infix fun BooleanAssert.andCanBe(chained: Any) = this
23+
24+
@Test
25+
fun isTrue() {
26+
_expect that true _is true andCanBe chained
27+
verify(mockAssertion).isTrue()
28+
verify(mockAssertion, never()).isFalse()
29+
}
30+
31+
@Test
32+
fun isFalse() {
33+
_expect that false _is false andCanBe chained
34+
verify(mockAssertion).isFalse()
35+
verify(mockAssertion, never()).isTrue()
36+
}
37+
}

0 commit comments

Comments
 (0)