This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from piotrb5e3/add-suspend-backticks-exceptio…
…n-assertions Added `should throw` and `should not throw` assertions that operate on suspending functions
- Loading branch information
Showing
5 changed files
with
150 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
24 changes: 24 additions & 0 deletions
24
...est/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldNotThrowBackticksStyle.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,24 @@ | ||
package org.amshove.kluent.tests.assertions.exceptions | ||
|
||
import org.amshove.kluent.AnyException | ||
import org.amshove.kluent.`should not throw` | ||
import org.amshove.kluent.invoking | ||
import org.junit.Test | ||
import kotlin.test.assertFails | ||
|
||
class ShouldNotThrowBackticksStyle { | ||
@Test | ||
fun shouldNotThrowSucceedsWhenNotThrown() { | ||
invoking { } `should not throw` AnyException | ||
} | ||
|
||
@Test | ||
fun shouldNotThrowFailsWhenThrown() { | ||
assertFails { invoking { throw CustomException(12345) } `should not throw` AnyException } | ||
} | ||
|
||
@Test | ||
fun shouldNotThrowSucceedsWhenDifferentExceptionClassThrown() { | ||
invoking { throw IllegalArgumentException() } `should not throw` CustomException::class | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...lin/org/amshove/kluent/tests/assertions/exceptions/ShouldNotThrowSuspendBackticksStyle.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,35 @@ | ||
package org.amshove.kluent.tests.assertions.exceptions | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.coroutineScope | ||
import kotlinx.coroutines.test.runBlockingTest | ||
import org.amshove.kluent.AnyException | ||
import org.amshove.kluent.`should not throw` | ||
import org.amshove.kluent.coInvoking | ||
import org.amshove.kluent.internal.assertFails | ||
import org.junit.Test | ||
|
||
class ShouldNotThrowSuspendBackticksStyle { | ||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldNotThrowSucceedsWhenNotThrown() = runBlockingTest { | ||
suspend fun func() = coroutineScope {} | ||
coInvoking { func() } `should not throw` AnyException | ||
} | ||
|
||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldNotThrowFailsWhenThrown() = runBlockingTest { | ||
suspend fun func(): Nothing = coroutineScope { throw CustomException(12345) } | ||
|
||
assertFails { coInvoking { func() } `should not throw` AnyException } | ||
} | ||
|
||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldNotThrowSucceedsWhenDifferentExceptionClassThrown() = runBlockingTest { | ||
suspend fun func(): Nothing = coroutineScope { throw IllegalArgumentException() } | ||
|
||
coInvoking { func() } `should not throw` CustomException::class | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...c/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldThrowBackticksStyle.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,34 @@ | ||
package org.amshove.kluent.tests.assertions.exceptions | ||
|
||
|
||
import org.amshove.kluent.`should throw` | ||
import org.amshove.kluent.invoking | ||
import org.junit.Test | ||
import kotlin.test.assertFails | ||
|
||
class ShouldThrowBackticksStyle { | ||
@Test | ||
fun shouldThrowSucceedsWhenExpectedInstanceThrown() { | ||
invoking { throw CustomException(12345) } `should throw` CustomException(12345) | ||
} | ||
|
||
@Test | ||
fun shouldThrowSucceedsWhenExpectedClassThrown() { | ||
invoking { throw CustomException(12345) } `should throw` CustomException::class | ||
} | ||
|
||
@Test | ||
fun shouldThrowFailsWhenNoExceptionThrown() { | ||
assertFails { invoking { } `should throw` CustomException(12345) } | ||
} | ||
|
||
@Test | ||
fun shouldThrowFailsWhenDifferentExceptionThrown() { | ||
assertFails { invoking { throw CustomException(54321) } `should throw` CustomException(12345) } | ||
} | ||
|
||
@Test | ||
fun shouldThrowFailsWhenDifferentExceptionClassThrown() { | ||
assertFails { invoking { throw IllegalArgumentException() } `should throw` CustomException::class } | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldThrowSuspendBackticksStyle.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,51 @@ | ||
package org.amshove.kluent.tests.assertions.exceptions | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.coroutineScope | ||
import kotlinx.coroutines.test.runBlockingTest | ||
import org.amshove.kluent.`should throw` | ||
import org.amshove.kluent.coInvoking | ||
import org.junit.Test | ||
import kotlin.test.assertFails | ||
|
||
class ShouldThrowSuspendBackticksStyle { | ||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldThrowSucceedsWhenExpectedInstanceThrown() = runBlockingTest { | ||
suspend fun func(): Nothing = coroutineScope { throw CustomException(12345) } | ||
|
||
coInvoking { func() } `should throw` CustomException(12345) | ||
} | ||
|
||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldThrowSucceedsWhenExpectedClassThrown() = runBlockingTest { | ||
suspend fun func(): Nothing = coroutineScope { throw CustomException(12345) } | ||
|
||
coInvoking { func() } `should throw` CustomException::class | ||
} | ||
|
||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldThrowFailsWhenNoExceptionThrown() = runBlockingTest { | ||
suspend fun func() = coroutineScope { } | ||
|
||
assertFails { coInvoking { func() } `should throw` CustomException(12345) } | ||
} | ||
|
||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldThrowFailsWhenDifferentExceptionThrown() = runBlockingTest { | ||
suspend fun func(): Nothing = coroutineScope { throw CustomException(54321) } | ||
|
||
assertFails { coInvoking { func() } `should throw` CustomException(12345) } | ||
} | ||
|
||
@Test | ||
@ExperimentalCoroutinesApi | ||
fun shouldThrowFailsWhenDifferentExceptionClassThrown() = runBlockingTest { | ||
suspend fun func(): Nothing = coroutineScope { throw java.lang.IllegalArgumentException() } | ||
|
||
assertFails { coInvoking { func() } `should throw` CustomException::class } | ||
} | ||
} |