Skip to content

Commit 56fac3f

Browse files
committed
use mock to verify methods are delegated properly in ObjectAssert
1 parent 2fb87fd commit 56fac3f

File tree

6 files changed

+114
-88
lines changed

6 files changed

+114
-88
lines changed

src/main/kotlin/com/memozr/assertk/CharSequenceAssert.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ enum class CharSequenceAssertTest {
1111

1212
class CharSequenceAssert internal constructor(
1313
private val subject: String?,
14-
override val assertion: AbstractCharSequenceAssert<*, String> = assertThat(subject))
15-
: AbstractAssertBuilder<CharSequenceAssert, String>(subject, CharSequenceAssert::class.java) {
14+
override val assertion: AbstractCharSequenceAssert<*, String> = assertThat(subject)) :
15+
AbstractAssertBuilder<CharSequenceAssert, String>(subject, CharSequenceAssert::class.java) {
1616

1717
object onlyDigits
1818

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.memozr.assertk
2+
3+
import org.assertj.core.api.AbstractObjectAssert
4+
import org.assertj.core.api.Assertions
5+
6+
class ObjectAssert<A : Any> internal constructor(
7+
actual: A?,
8+
override val assertion: AbstractObjectAssert<*, A> = Assertions.assertThat(actual)) :
9+
AbstractAssertBuilder<ObjectAssert<A>, A>(actual, ObjectAssert::class.java)

src/main/kotlin/com/memozr/assertk/ObjectAssert.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/kotlin/com/memozr/assertk/Abstract assert builder test.kt

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/test/kotlin/com/memozr/assertk/GeneralTest.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.memozr.assertk
2+
3+
import com.memozr.assertk.ObjectStuff.notNull
4+
import com.nhaarman.mockito_kotlin.spy
5+
import com.nhaarman.mockito_kotlin.verify
6+
import org.assertj.core.api.AbstractObjectAssert
7+
import org.assertj.core.api.Assertions
8+
import org.junit.Test
9+
10+
class `Object assert test` {
11+
val nullObject: Any? = null
12+
13+
lateinit var mockAssertion: AbstractObjectAssert<*, Any>
14+
val _expect = object : AssertionHook {
15+
override fun <A: Any> that(subjectUnderTest: A?): ObjectAssert<A> {
16+
val spy: AbstractObjectAssert<*, A?>? = spy(Assertions.assertThat(subjectUnderTest))
17+
mockAssertion = spy as AbstractObjectAssert<*, Any>
18+
return ObjectAssert(subjectUnderTest, mockAssertion) as ObjectAssert<A>
19+
}
20+
}
21+
22+
@Test
23+
fun `isEqualTo performs logical equality`() {
24+
_expect that Unit isEqualTo Unit
25+
26+
val expected = Any()
27+
_expect thatThrownBy {
28+
_expect that Any() isEqualTo expected
29+
}
30+
31+
verify(mockAssertion).isEqualTo(expected)
32+
}
33+
34+
@Test
35+
fun `isNotEqualTo performs logical inequality`() {
36+
_expect that Any() isNotEqualTo Any()
37+
38+
_expect thatThrownBy {
39+
_expect that Unit isNotEqualTo Unit
40+
}
41+
42+
verify(mockAssertion).isNotEqualTo(Unit)
43+
}
44+
45+
@Test
46+
fun `_is notNull checks whether object is null`() {
47+
_expect that Any() _is notNull
48+
49+
_expect thatThrownBy {
50+
_expect that nullObject _is notNull
51+
}
52+
verify(mockAssertion).isNotNull()
53+
}
54+
55+
@Test
56+
fun `_is null checks whether object is not null`() {
57+
_expect that nullObject _is null
58+
59+
_expect thatThrownBy {
60+
_expect that Any() _is null
61+
}
62+
verify(mockAssertion).isNull()
63+
}
64+
65+
@Test
66+
fun `isInstance of checks for object instance`() {
67+
val anObject = Any()
68+
69+
_expect that anObject isInstance of<Any>()
70+
verify(mockAssertion).isInstanceOf(Any::class.java)
71+
72+
_expect thatThrownBy {
73+
_expect that anObject isInstance of<Unit>()
74+
}
75+
76+
}
77+
78+
@Test
79+
fun `describedAs describes the object when referring to it in failure messages`() {
80+
_expect thatThrownBy {
81+
_expect that Any() describedAs "A labeled object" isInstance of<Unit>()
82+
} hasMessageContaining "A labeled object"
83+
84+
verify(mockAssertion).describedAs("A labeled object")
85+
}
86+
87+
@Test
88+
fun `block _expections are supported`() {
89+
_expect that Any() isSuchThat {
90+
it _is notNull
91+
it isInstance of<Any>()
92+
it isNotEqualTo Unit
93+
it isNotEqualTo Any()
94+
}
95+
96+
_expect thatThrownBy {
97+
_expect that Any() isSuchThat {
98+
it _is null
99+
it isInstance of<Unit>()
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)