Skip to content

Commit 4e8075e

Browse files
committed
refactor test names
1 parent 9857891 commit 4e8075e

File tree

4 files changed

+140
-141
lines changed

4 files changed

+140
-141
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ val expect: AssertionHook get() = AssertionHook()
55

66
class AssertionHook {
77
infix fun <T : Any> that(subjectUnderTest: T?) = AbstractAssertBuilder(subjectUnderTest)
8-
infix fun thatExceptionIsThrownBy(expressionUnderTest: () -> Unit) = ThrowableAssertionBuilder(expressionUnderTest)
8+
infix fun thatThrownBy(expressionUnderTest: () -> Unit) = ThrowableAssertionBuilder(expressionUnderTest)
99
}
1010

1111

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,73 @@ package com.memozr.assertk
33
import com.memozr.assertk.ObjectStuff.notNull
44
import org.junit.Test
55

6-
class AbstractAssertBuilderTest {
6+
class `Abstract assert builder test` {
77
val nullObject: Any? = null
88

99
@Test
10-
fun `isEqualTo`() {
10+
fun `isEqualTo performs logical equality`() {
1111
assert that Unit isEqualTo Unit
1212

13-
assert thatExceptionIsThrownBy {
13+
assert thatThrownBy {
1414
assert that Any() isEqualTo Any()
1515
}
1616
}
1717

1818
@Test
19-
fun `isNotEqualTo`() {
19+
fun `isNotEqualTo peforms logical inequality`() {
2020
assert that Any() isNotEqualTo Any()
2121

22-
assert thatExceptionIsThrownBy {
22+
assert thatThrownBy {
2323
assert that Unit isNotEqualTo Unit
2424
}
2525
}
2626

2727
@Test
28-
fun `is not null`() {
28+
fun `_is notNull checks whether object is null`() {
2929
assert that Any() _is notNull
3030

31-
assert thatExceptionIsThrownBy {
31+
assert thatThrownBy {
3232
assert that nullObject _is notNull
3333
}
3434
}
3535

3636
@Test
37-
fun `is null`() {
37+
fun `_is null checks whether object is not null`() {
3838
assert that nullObject _is null
3939

40-
assert thatExceptionIsThrownBy {
40+
assert thatThrownBy {
4141
assert that Any() _is null
4242
}
4343
}
4444

4545
@Test
46-
fun `is instance of`() {
46+
fun `isInstance of checks for object instance`() {
4747
val anObject = Any()
4848

4949
assert that anObject isInstance of<Any>()
5050

51-
assert thatExceptionIsThrownBy {
51+
assert thatThrownBy {
5252
assert that anObject isInstance of<Unit>()
5353
}
5454
}
5555

5656
@Test
57-
fun `described as describes the object`() {
58-
assert thatExceptionIsThrownBy {
57+
fun `describedAs describes the object when referring to it in failure messages`() {
58+
assert thatThrownBy {
5959
assert that Any() describedAs "A labeled object" isInstance of<Unit>()
6060
} hasMessageContaining "A labeled object"
6161
}
6262

6363
@Test
64-
fun `block assertions`() {
64+
fun `block assertions are supported`() {
6565
assert that Any() isSuchThat {
6666
it _is notNull
6767
it isInstance of<Any>()
6868
it isNotEqualTo Unit
6969
it isNotEqualTo Any()
7070
}
7171

72-
assert thatExceptionIsThrownBy {
72+
assert thatThrownBy {
7373
assert that Any() isSuchThat {
7474
it _is null
7575
it isInstance of<Unit>()

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

Lines changed: 0 additions & 125 deletions
This file was deleted.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package com.memozr.assertk
2+
3+
import com.memozr.assertk.ThrowableAssertionBuilder.noCause
4+
import org.assertj.core.api.Assertions
5+
import org.junit.Test
6+
7+
class `ThrownBy test` {
8+
val aThrowable = Throwable()
9+
10+
private fun aThrowableWithCause() = Throwable("hello", aThrowable)
11+
12+
@Test
13+
fun `fails when no exception is thrown`() {
14+
Assertions.assertThatThrownBy {
15+
assert thatThrownBy { }
16+
}
17+
}
18+
19+
@Test
20+
fun `passes when exception is thrown`() {
21+
assert thatThrownBy { throw Throwable() }
22+
}
23+
24+
@Test
25+
fun `passes when throwable message matches the specified message`() {
26+
assert thatThrownBy { throw Throwable("hello") } hasMessage "hello"
27+
}
28+
29+
@Test
30+
fun `fails when throwable message does not match specified mesage`() {
31+
assert thatThrownBy {
32+
assert thatThrownBy { throw Throwable("this") } hasMessage "that"
33+
}
34+
}
35+
36+
@Test
37+
fun `passes when throwable cause and specified cause match`() {
38+
assert thatThrownBy { throw aThrowableWithCause() } hasCause aThrowable hasMessage "hello"
39+
assert thatThrownBy { throw aThrowableWithCause() } hasCause aThrowable
40+
}
41+
42+
@Test
43+
fun `fails when throwable cause and specified cause do not match`() {
44+
assert thatThrownBy {
45+
assert thatThrownBy { throw aThrowableWithCause() } hasCause Exception()
46+
}
47+
}
48+
49+
@Test
50+
fun `hasNoCause passes when throwable has no cause`() {
51+
assert thatThrownBy { throw aThrowable } has noCause
52+
}
53+
54+
@Test
55+
fun `hasNoCause fails when throwable has cause`() { assert thatThrownBy {
56+
assert thatThrownBy { throw aThrowableWithCause() } has noCause
57+
}
58+
}
59+
60+
@Test
61+
fun `hasMessageStartingWith checks throwable message starts with specified substring`() {
62+
assert thatThrownBy { throw Throwable("excepton foo") } hasMessageStartingWith "exc"
63+
assert thatThrownBy {
64+
assert thatThrownBy { throw Throwable("excepton foo") } hasMessageStartingWith "foo"
65+
}
66+
}
67+
68+
@Test
69+
fun `hasMessageEndingWith checks throwable message ends with specified substring`() {
70+
assert thatThrownBy { throw Throwable("excepton foo") } hasMessageEndingWith "foo"
71+
assert thatThrownBy {
72+
assert thatThrownBy { throw Throwable("excepton foo") } hasMessageEndingWith "exec"
73+
}
74+
}
75+
76+
@Test
77+
fun `hasMessageContaining checks throwable message ends with specified substring`() {
78+
assert thatThrownBy { throw Throwable("excepton foo") } hasMessageContaining "foo"
79+
assert thatThrownBy {
80+
assert thatThrownBy { throw Throwable("excepton foo") } hasMessageContaining "lololol"
81+
}
82+
}
83+
84+
@Test
85+
fun `hasStackTraceContaining checks stacktrace contains specified string`() {
86+
assert thatThrownBy { throw aThrowable } hasStackTraceContaining "init"
87+
assert thatThrownBy {
88+
assert thatThrownBy { throw Throwable("excepton foo") } hasStackTraceContaining "not in there!!"
89+
}
90+
}
91+
92+
@Test
93+
fun `hasCauseExactlyInstanceOf checks throwable cause is exactly instance of specified class`() {
94+
assert thatThrownBy { throw Throwable(Throwable()) } hasCauseExactlyInstanceOf Throwable::class.java
95+
96+
assert thatThrownBy {
97+
assert thatThrownBy { throw Throwable(Exception()) } hasCauseExactlyInstanceOf Throwable::class.java
98+
}
99+
100+
assert thatThrownBy {
101+
assert thatThrownBy { throw Throwable(Throwable()) } hasCauseExactlyInstanceOf Exception::class.java
102+
}
103+
}
104+
105+
@Test
106+
fun `block syntax is supported`() {
107+
assert thatThrownBy {
108+
throw Throwable("exception foo", Throwable())
109+
} and {
110+
it hasMessage "exception foo"
111+
it hasCause Throwable()
112+
it hasCauseExactlyInstanceOf Throwable::class.java
113+
it hasMessageContaining "foo"
114+
it hasMessageStartingWith "ex"
115+
it hasMessageEndingWith "foo"
116+
}
117+
118+
assert thatThrownBy {
119+
assert thatThrownBy { throw Throwable("exception foo", Throwable()) } and {
120+
it hasMessage "blah blah"
121+
}
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)