File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
main/kotlin/com/memoizr/assertk
test/kotlin/com/memoizr/assertk Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ interface AssertionHook {
13
13
infix fun that (subjectUnderTest : Float? ) = FloatAssert (subjectUnderTest)
14
14
infix fun that (subjectUnderTest : Double? ) = DoubleAssert (subjectUnderTest)
15
15
infix fun that (subjectUnderTest : Long? ) = LongAssert (subjectUnderTest)
16
+ infix fun that (subjectUnderTest : Boolean? ) = BooleanAssert (subjectUnderTest)
16
17
}
17
18
18
19
class RealAssertionHook : AssertionHook
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments