-
-
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 fun0 assertions (#991)
- Loading branch information
1 parent
fa08255
commit b1b8b6e
Showing
2 changed files
with
69 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
61 changes: 61 additions & 0 deletions
61
...mmon/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/Fun0ExpectationSamples.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,61 @@ | ||
package ch.tutteli.atrium.api.fluent.en_GB.samples | ||
|
||
import ch.tutteli.atrium.api.fluent.en_GB.* | ||
import ch.tutteli.atrium.api.verbs.internal.expect | ||
import kotlin.test.Test | ||
|
||
class Fun0ExpectationSamples { | ||
|
||
@Test | ||
fun toThrowFeature() { | ||
expect { throw IllegalStateException("abc") } | ||
.toThrow<IllegalStateException>() // subject is now of type IllegalStateException | ||
.messageToContain("abc") | ||
|
||
fails { | ||
expect { throw IllegalStateException("abc") } | ||
.toThrow<IndexOutOfBoundsException>() | ||
.messageToContain("abc") // not shown in reporting as `toThrow<IndexOutOfBoundsException>()` already fails | ||
} | ||
} | ||
|
||
@Test | ||
fun toThrow() { | ||
expect { throw IllegalStateException("abc") } | ||
.toThrow<IllegalStateException> { // subject inside this block is of type IllegalStateException | ||
messageToContain("abc") | ||
} | ||
|
||
fails { // because wrong type expected (IndexOutOfBoundsException instead of IllegalStateException), but since we use a block... | ||
expect { throw IllegalStateException("abc") } | ||
.toThrow<IndexOutOfBoundsException> { | ||
messageToContain("abc") // ... reporting mentions that subject's message was expected `to contain: "abc"` | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun notToThrowFeature() { | ||
expect { "abc" } | ||
.notToThrow() // subject is now of type String | ||
.toContain("abc") | ||
|
||
fails { | ||
expect { throw IllegalStateException("abc") } | ||
.notToThrow() | ||
} | ||
} | ||
|
||
@Test | ||
fun notToThrow() { | ||
expect { "abc" } | ||
.notToThrow { // subject is now of type String | ||
toEqual("abc") | ||
} | ||
|
||
fails { | ||
expect { throw IllegalStateException("abc") } | ||
.notToThrow {} | ||
} | ||
} | ||
} |