Skip to content

Commit 56f7348

Browse files
committed
rename package
1 parent 7cfe3d5 commit 56f7348

File tree

8 files changed

+748
-0
lines changed

8 files changed

+748
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.memoizr.assertk
2+
3+
import com.memoizr.assertk.ObjectStuff.notNull
4+
import org.assertj.core.api.AbstractAssert
5+
import org.assertj.core.api.Assertions
6+
7+
enum class ObjectStuff {
8+
notNull
9+
}
10+
11+
inline fun <reified R : Any> of() = AbstractAssertBuilder.InstanceMatcher<R>()
12+
13+
abstract class AbstractAssertBuilder<S : AbstractAssertBuilder<S, A>, A : Any> internal constructor(actual: A?, selfType: Class<*>) {
14+
class InstanceMatcher<R>
15+
16+
@Suppress("UNCHECKED_CAST", "LeakingThis")
17+
protected val myself: S = selfType.cast(this) as S
18+
19+
open protected val assertion: AbstractAssert<*, out A?> = Assertions.assertThat(actual)
20+
21+
infix fun isEqualTo(other: A): S {
22+
assertion.isEqualTo(other)
23+
return myself
24+
}
25+
26+
infix fun isNotEqualTo(other: A): S {
27+
assertion.isNotEqualTo(other)
28+
return myself
29+
}
30+
31+
@Suppress("UNUSED_PARAMETER")
32+
inline infix fun <reified R : Any> isInstance(bar: InstanceMatcher<R>): S {
33+
assertion.isInstanceOf(R::class.java)
34+
return myself
35+
}
36+
37+
infix fun _is(objectStuff: ObjectStuff?): S {
38+
return when (objectStuff) {
39+
notNull -> {
40+
assertion.isNotNull()
41+
myself
42+
}
43+
else -> {
44+
assertion.isNull()
45+
myself
46+
}
47+
}
48+
}
49+
50+
infix fun describedAs(description: String): S {
51+
assertion.`as`(description)
52+
return myself
53+
}
54+
55+
@Suppress("UNCHECKED_CAST")
56+
infix fun isSuchThat(assertionBlock: S.(S) -> Unit): S {
57+
(this as S).assertionBlock(this)
58+
return myself
59+
}
60+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.memoizr.assertk
2+
3+
val assert: AssertionHook get() = RealAssertionHook()
4+
val expect: AssertionHook get() = RealAssertionHook()
5+
6+
interface AssertionHook {
7+
infix fun <T : Any> that(subjectUnderTest: T?) = ObjectAssert(subjectUnderTest)
8+
infix fun that(subjectUnderTest: CharSequence?) = CharSequenceAssert(subjectUnderTest)
9+
infix fun thatThrownBy(expressionUnderTest: () -> Unit) = ThrowableAssertion(expressionUnderTest)
10+
}
11+
12+
class RealAssertionHook : AssertionHook
13+
14+
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package com.memoizr.assertk
2+
3+
import com.memoizr.assertk.CharSequenceAssertTest.*
4+
import org.assertj.core.api.AbstractCharSequenceAssert
5+
import org.assertj.core.api.Assertions.assertThat
6+
import java.util.regex.Pattern
7+
8+
enum class CharSequenceAssertTest {
9+
nullOrEmpty, empty, notEmpty
10+
}
11+
12+
class CharSequenceAssert internal constructor(
13+
private val subject: CharSequence?,
14+
override val assertion: AbstractCharSequenceAssert<*, out CharSequence> = assertThat(subject)) :
15+
AbstractAssertBuilder<CharSequenceAssert, CharSequence>(subject, CharSequenceAssert::class.java) {
16+
17+
object onlyDigits
18+
19+
infix fun _is(assertionTest: CharSequenceAssertTest): CharSequenceAssert {
20+
when (assertionTest) {
21+
empty -> assertion.isEmpty()
22+
notEmpty -> assertion.isNotEmpty()
23+
nullOrEmpty -> assertion.isNullOrEmpty()
24+
}
25+
return this
26+
}
27+
28+
infix fun hasSize(expectedSize: Int): CharSequenceAssert {
29+
assertion.hasSize(expectedSize)
30+
return this
31+
}
32+
33+
infix fun hasLineCount(expectedLineCount: Int): CharSequenceAssert {
34+
assertion.hasLineCount(expectedLineCount)
35+
return this
36+
}
37+
38+
infix fun isEqualToIgnoringCase(expected: CharSequence): CharSequenceAssert {
39+
assertion.isEqualToIgnoringCase(expected)
40+
return this
41+
}
42+
43+
infix fun isNotEqualToIgnoringCase(expected: CharSequence): CharSequenceAssert {
44+
assertion.isNotEqualToIgnoringCase(expected)
45+
return this
46+
}
47+
48+
infix fun contains(onlyDigits: onlyDigits): CharSequenceAssert {
49+
assertion.containsOnlyDigits()
50+
return this
51+
}
52+
53+
infix fun contains(expected: CharSequence): CharSequenceAssert {
54+
assertion.contains(expected)
55+
return this
56+
}
57+
58+
infix fun containsOnlyOnce(expected: CharSequence): CharSequenceAssert {
59+
assertion.containsOnlyOnce(expected)
60+
return this
61+
}
62+
63+
infix fun contains(expected: Iterable<CharSequence>): CharSequenceAssert {
64+
assertion.contains(expected)
65+
return this
66+
}
67+
68+
infix fun containsSequence(expected: Iterable<CharSequence>): CharSequenceAssert {
69+
assertion.containsSequence(expected)
70+
return this
71+
}
72+
73+
infix fun containsIgnoringCase(expected: CharSequence): CharSequenceAssert {
74+
assertion.containsIgnoringCase(expected)
75+
return this
76+
}
77+
78+
infix fun doesNotContain(expected: CharSequence): CharSequenceAssert {
79+
assertion.doesNotContain(expected)
80+
return this
81+
}
82+
83+
infix fun startsWith(expected: CharSequence): CharSequenceAssert {
84+
assertion.startsWith(expected)
85+
return this
86+
}
87+
88+
infix fun doesNotStartWith(expected: CharSequence): CharSequenceAssert {
89+
assertion.doesNotStartWith(expected)
90+
return this
91+
}
92+
93+
infix fun endsWith(expected: CharSequence): CharSequenceAssert {
94+
assertion.endsWith(expected)
95+
return this
96+
}
97+
98+
infix fun doesNotEndWith(expected: CharSequence): CharSequenceAssert {
99+
assertion.doesNotEndWith(expected)
100+
return this
101+
}
102+
103+
infix fun matches(expected: Pattern): CharSequenceAssert {
104+
assertion.matches(expected)
105+
return this
106+
}
107+
108+
infix fun doesNotMatch(expected: Pattern): CharSequenceAssert {
109+
assertion.doesNotMatch(expected)
110+
return this
111+
}
112+
113+
infix fun matches(expected: CharSequence): CharSequenceAssert {
114+
assertion.matches(expected)
115+
return this
116+
}
117+
118+
infix fun doesNotMatch(expected: CharSequence): CharSequenceAssert {
119+
assertion.doesNotMatch(expected)
120+
return this
121+
}
122+
123+
infix fun isEqualToIgnoringWhitespace(expected: CharSequence): CharSequenceAssert {
124+
assertion.isEqualToIgnoringWhitespace(expected)
125+
return this
126+
}
127+
128+
infix fun isNotEqualToIgnoringWhitespace(expected: CharSequence): CharSequenceAssert {
129+
assertion.isNotEqualToIgnoringWhitespace(expected)
130+
return this
131+
}
132+
133+
infix fun isSubstringOf(expected: CharSequence): CharSequenceAssert {
134+
assertion.isSubstringOf(expected)
135+
return this
136+
}
137+
138+
infix fun containsPattern(pattern: CharSequence): CharSequenceAssert {
139+
assertion.containsPattern(pattern)
140+
return this
141+
}
142+
143+
infix fun containsPattern(pattern: Pattern): CharSequenceAssert {
144+
assertion.containsPattern(pattern)
145+
return this
146+
}
147+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.memoizr.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)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.memoizr.assertk
2+
3+
import org.assertj.core.api.AbstractThrowableAssert
4+
import org.assertj.core.api.Assertions
5+
6+
class ThrowableAssertion(
7+
func: () -> Unit,
8+
private val assertion: AbstractThrowableAssert<*, out Throwable> = Assertions.assertThatThrownBy(func)) {
9+
10+
infix fun hasMessage(message: String): ThrowableAssertion {
11+
assertion.hasMessage(message)
12+
return this
13+
}
14+
15+
infix fun hasCause(throwable: Throwable): ThrowableAssertion {
16+
assertion.hasCause(throwable)
17+
return this
18+
}
19+
20+
infix fun has(noCause: noCause): ThrowableAssertion {
21+
assertion.hasNoCause()
22+
return this
23+
}
24+
25+
infix fun hasMessageStartingWith(message: String): ThrowableAssertion {
26+
assertion.hasMessageStartingWith(message)
27+
return this
28+
}
29+
30+
infix fun hasMessageEndingWith(message: String): ThrowableAssertion {
31+
assertion.hasMessageEndingWith(message)
32+
return this
33+
}
34+
35+
infix fun hasMessageContaining(message: String): ThrowableAssertion {
36+
assertion.hasMessageContaining(message)
37+
return this
38+
}
39+
40+
infix fun hasStackTraceContaining(message: String): ThrowableAssertion {
41+
assertion.hasStackTraceContaining(message)
42+
return this
43+
}
44+
45+
infix fun hasCauseExactlyInstanceOf(throwable: Class<out Throwable>): ThrowableAssertion {
46+
assertion.hasCauseExactlyInstanceOf(throwable)
47+
return this
48+
}
49+
50+
infix fun and(assertions: ThrowableAssertion.(ThrowableAssertion) -> Unit) {
51+
assertions(this)
52+
}
53+
54+
object noCause
55+
}

0 commit comments

Comments
 (0)