-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add samples for infix throwable expectations (#1002)
- Loading branch information
1 parent
ff4551b
commit b6e40bd
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/ThrowableExpectationSamples.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package ch.tutteli.atrium.api.infix.en_GB.samples | ||
|
||
import ch.tutteli.atrium.api.infix.en_GB.* | ||
import ch.tutteli.atrium.api.verbs.internal.expect | ||
import kotlin.test.Test | ||
|
||
class ThrowableExpectationSamples { | ||
|
||
@Test | ||
fun messageToContain() { | ||
expect(RuntimeException("abc")) messageToContain "b" | ||
|
||
fails { | ||
expect(RuntimeException("abc")) messageToContain "d" | ||
} | ||
} | ||
|
||
@Test | ||
fun messageFeature() { | ||
expect(RuntimeException("abc")).message toContain "a" | ||
// | subject is now of type String | ||
|
||
fails { | ||
expect(RuntimeException("abc")).message toContain "d" | ||
// | subject is now of type String | ||
} | ||
} | ||
|
||
@Test | ||
fun message() { | ||
expect(RuntimeException("abc")) message { // subject inside this block is of type String (actually "abc") | ||
toContain("a") | ||
} | ||
|
||
fails { | ||
expect(RuntimeException("abc")) message { // subject inside this block is of type String (actually "abc") | ||
toContain("d") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun causeFeature() { | ||
expect(IllegalStateException(IndexOutOfBoundsException("abc"))) | ||
.cause<IndexOutOfBoundsException>() messageToContain "b" | ||
// | subject is now of type IndexOutOfBoundsException | ||
|
||
fails { | ||
expect(IllegalStateException(IndexOutOfBoundsException("abc"))) | ||
.cause<IllegalStateException>() messageToContain "d" // not shown in reporting as `cause<IllegalStateException>()` already fails | ||
|
||
} | ||
} | ||
|
||
@Test | ||
fun cause() { | ||
expect(IllegalStateException(IndexOutOfBoundsException("abc"))) | ||
.cause<IndexOutOfBoundsException> { // subject is now of type IndexOutOfBoundsException | ||
it messageToContain "b" | ||
} | ||
|
||
fails { // because wrong type expected (IllegalStateException instead of IndexOutOfBoundsException), but since we use a block... | ||
expect(IllegalStateException(IndexOutOfBoundsException("abc"))).cause<IllegalStateException> { | ||
it messageToContain "b" // ... reporting mentions that subject's message was expected `to contain: "b"` | ||
} | ||
} | ||
} | ||
} |