Skip to content

Commit 3672294

Browse files
authored
Merge pull request #7 from memoizr/no_expect
do not require the use of expect
2 parents fe98205 + 2a4973e commit 3672294

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class AbstractAssertBuilder<S : AbstractAssertBuilder<S, A>, A : Any>(a
2222
}
2323

2424
@Suppress("UNUSED_PARAMETER")
25-
inline infix fun <reified R : Any> isInstance(bar: InstanceMatcher<R>): S {
25+
inline infix fun <reified R : Any> isInstance(bar: InstanceMatcher<out R>): S {
2626
assertion.isInstanceOf(R::class.java)
2727
return myself
2828
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ package com.memoizr.assertk
33
import org.assertj.core.api.AbstractDoubleAssert
44
import org.assertj.core.api.Assertions
55

6+
infix fun Double.isLessThan(expected: Double): DoubleAssert = expect that this isLessThan expected
7+
infix fun Double.isLessThanOrEqualTo(expected: Double): DoubleAssert = expect that this isLessThanOrEqualTo expected
8+
infix fun Double.isGreaterThan(expected: Double): DoubleAssert = expect that this isGreaterThan expected
9+
infix fun Double.isGreaterThanOrEqualTo(expected: Double): DoubleAssert = expect that this isGreaterThanOrEqualTo expected
10+
infix fun Double.isBetween(expected: ClosedRange<Double>): DoubleAssert = expect that this isBetween expected
11+
infix fun Double.isStrictlyBetween(expected: ClosedRange<Double>): DoubleAssert = expect that this isStrictlyBetween expected
12+
infix fun Double.isCloseTo(expected: Double): DoubleAssert.Close = expect that this isCloseTo expected
13+
infix fun Double.isEqualTo(expected: Double): DoubleAssert = expect that this isEqualTo expected
14+
infix fun Double.isNotEqualTo(expected: Double): DoubleAssert = expect that this isNotEqualTo expected
15+
infix fun Double.isInstance(expected: AbstractAssertBuilder.InstanceMatcher<Double>): DoubleAssert = expect that this isInstance expected
16+
infix fun Double.is_(expected: NumberSelector): DoubleAssert = expect that this _is expected
17+
infix fun Double.is_(expected: ObjectSelector): DoubleAssert = expect that this _is expected
18+
infix fun Double._is(expected: NumberSelector): DoubleAssert = expect that this _is expected
19+
infix fun Double._is(expected: ObjectSelector): DoubleAssert = expect that this _is expected
20+
infix fun Double.describedAs(description: String): DoubleAssert = expect that this describedAs description
21+
622
class DoubleAssert internal constructor(
723
subjectUnderTest: Double?,
824
override val assertion: AbstractDoubleAssert<*> = Assertions.assertThat(subjectUnderTest)) :
@@ -42,6 +58,8 @@ class DoubleAssert internal constructor(
4258
return Close(expected, assertion, this)
4359
}
4460

61+
infix fun is_(expected: NumberSelector): DoubleAssert = _is(expected)
62+
4563
infix fun _is(expected: NumberSelector): DoubleAssert {
4664
when (expected) {
4765
zero -> assertion.isZero()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ package com.memoizr.assertk
33
import org.assertj.core.api.AbstractObjectAssert
44
import org.assertj.core.api.Assertions
55

6+
infix fun <A: Any> A.isEqualTo(expected: A): ObjectAssert<A> = expect that this isEqualTo expected
7+
infix fun <A: Any> A.isNotEqualTo(expected: A): ObjectAssert<A> = expect that this isNotEqualTo expected
8+
infix fun <A: Any> A.is_(expected: ObjectSelector): ObjectAssert<A> = expect that this _is expected
9+
infix fun <A: Any> A.describedAs(description: String): ObjectAssert<A> = expect that this describedAs description
10+
inline infix fun <reified A: Any> A.isInstance(expected: AbstractAssertBuilder.InstanceMatcher<out A>): ObjectAssert<A> =
11+
expect.that(this).isInstance(expected)
12+
613
class ObjectAssert<A : Any> internal constructor(
714
actual: A?,
815
override val assertion: AbstractObjectAssert<*, A> = Assertions.assertThat(actual)) :

src/test/kotlin/com/memoizr/assertk/Double assert test.kt

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class `Double assert test` {
1010
lateinit var mockAssertion: AbstractDoubleAssert<*>
1111
@Suppress("UNCHECKED_CAST")
1212
val _expect = object : AssertionHook {
13-
override fun that(subjectUnderTest: Double?): DoubleAssert {
13+
override fun that(subjectUnderTest: Double?): DoubleAssert {
1414
val spy: AbstractDoubleAssert<*> = spy(Assertions.assertThat(subjectUnderTest))
1515
mockAssertion = spy
1616
return DoubleAssert(subjectUnderTest, mockAssertion)
@@ -28,100 +28,142 @@ class `Double assert test` {
2828
private val one = 1.0
2929
private val negativeOne = -one
3030

31+
@Test
32+
fun isEqualTo() {
33+
three isEqualTo three andCanBe chained
34+
}
35+
36+
@Test
37+
fun isNotEqualTo() {
38+
three isNotEqualTo four andCanBe chained
39+
}
40+
41+
@Test
42+
fun isInstance() {
43+
three isInstance of<Double>() andCanBe chained
44+
}
45+
46+
@Test
47+
fun is_() {
48+
three is_ notNull andCanBe chained
49+
three is_ notNegative andCanBe chained
50+
}
51+
52+
@Test
53+
fun describedAs() {
54+
three describedAs "foo" andCanBe chained
55+
}
56+
3157
@Test
3258
fun isLessThan() {
3359
_expect that three isLessThan four andCanBe chained
60+
three isLessThan four andCanBe chained
3461
verify.isLessThan(four)
3562
}
3663

3764
@Test
3865
fun isLessThanOrEqualTo() {
3966
_expect that four isLessThanOrEqualTo four andCanBe chained
67+
four isLessThanOrEqualTo four andCanBe chained
4068
verify.isLessThanOrEqualTo(four)
4169
}
4270

4371
@Test
4472
fun isGreaterThan() {
4573
_expect that five isGreaterThan four andCanBe chained
74+
five isGreaterThan four andCanBe chained
4675
verify.isGreaterThan(four)
4776
}
4877

4978
@Test
5079
fun isGreaterThanOrEqualTo() {
5180
_expect that four isGreaterThanOrEqualTo four andCanBe chained
81+
four isGreaterThanOrEqualTo four andCanBe chained
5282
verify.isGreaterThanOrEqualTo(four)
5383
}
5484

5585
@Test
5686
fun isBetween() {
5787
_expect that four isBetween (three..five) andCanBe chained
88+
four isBetween (three..five) andCanBe chained
5889
verify.isBetween(three, five)
5990
}
6091

6192
@Test
6293
fun isStrictlyBetween() {
6394
_expect that four isStrictlyBetween (three..five) andCanBe chained
95+
four isStrictlyBetween (three..five) andCanBe chained
6496
verify.isStrictlyBetween(three, five)
6597
}
6698

6799
@Test
68100
fun `isCloseTo within`() {
69101
_expect that four isCloseTo three withinOffset one andCanBe chained
102+
four isCloseTo three withinOffset one andCanBe chained
70103
verify.isCloseTo(three, Assertions.within(one))
71104
}
72105

73106
@Test
74107
fun `isCloseTo percentage int`() {
75108
_expect that three isCloseTo four withinPercentage 25 andCanBe chained
109+
three isCloseTo four withinPercentage 25 andCanBe chained
76110
verify.isCloseTo(four, Assertions.withinPercentage(25))
77111
}
78112

79113
@Test
80114
fun `isCloseTo percentage double`() {
81115
_expect that three isCloseTo four withinPercentage 25.3 andCanBe chained
116+
three isCloseTo four withinPercentage 25.3 andCanBe chained
82117
verify.isCloseTo(four, Assertions.withinPercentage(25.3))
83118
}
84119

85120
@Test
86121
fun `isCloseTo percentage float`() {
87122
_expect that three isCloseTo four withinPercentage 25f andCanBe chained
123+
three isCloseTo four withinPercentage 25f andCanBe chained
88124
verify.isCloseTo(four, Assertions.withinPercentage(25))
89125
}
90126

91127
@Test
92128
fun isZero() {
93129
_expect that 0.0 _is zero andCanBe chained
130+
0.0 _is zero andCanBe chained
94131
verify.isZero()
95132
}
96133

97134
@Test
98135
fun isNotZero() {
99136
_expect that one _is notZero andCanBe chained
137+
one _is notZero andCanBe chained
100138
verify.isNotZero()
101139
}
102140

103141
@Test
104142
fun isPositive() {
105143
_expect that one _is positive andCanBe chained
144+
one _is positive andCanBe chained
106145
verify.isPositive()
107146
}
108147

109148

110149
@Test
111150
fun isNotPositive() {
112151
_expect that negativeOne _is notPositive andCanBe chained
152+
negativeOne _is notPositive andCanBe chained
113153
verify.isNotPositive()
114154
}
115155

116156
@Test
117157
fun isNegative() {
118158
_expect that negativeOne _is negative andCanBe chained
159+
negativeOne _is negative andCanBe chained
119160
verify.isNegative()
120161
}
121162

122163
@Test
123164
fun isNotNegative() {
124165
_expect that one _is notNegative andCanBe chained
166+
one _is notNegative andCanBe chained
125167
verify.isNotNegative()
126168
}
127169

src/test/kotlin/com/memoizr/assertk/Object assert test.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import org.assertj.core.api.AbstractObjectAssert
66
import org.assertj.core.api.Assertions
77
import org.junit.Test
88

9+
interface FooBars
10+
object A : FooBars
11+
object B
12+
913
class `Object assert test` {
1014
val nullObject: Any? = null
1115

@@ -19,6 +23,32 @@ class `Object assert test` {
1923
}
2024
}
2125

26+
@Test
27+
fun isEqualTo() {
28+
Unit isEqualTo Unit
29+
}
30+
31+
@Test
32+
fun isNotEqualTo() {
33+
A isNotEqualTo B
34+
}
35+
36+
@Test
37+
fun isInstance() {
38+
expect that (A as FooBars) isInstance of<A>()
39+
(A as FooBars) isInstance of<A>()
40+
}
41+
42+
@Test
43+
fun is_() {
44+
A is_ notNull
45+
}
46+
47+
@Test
48+
fun describedAs() {
49+
A describedAs "foo"
50+
}
51+
2252
@Test
2353
fun `isEqualTo performs logical equality`() {
2454
_expect that Unit isEqualTo Unit

0 commit comments

Comments
 (0)