Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/kotlin/com/memoizr/assertk/AssertionHooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/main/kotlin/com/memoizr/assertk/BooleanAssert.kt
Original file line number Diff line number Diff line change
@@ -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<BooleanAssert, Boolean>(subjectUnderTest, BooleanAssert::class.java) {

infix fun _is(other: Boolean): BooleanAssert {
if (other) assertion.isTrue() else assertion.isFalse()
return this
}
}
37 changes: 37 additions & 0 deletions src/test/kotlin/com/memoizr/assertk/BooleanAssert test.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}