Skip to content

Commit

Permalink
Get rid of TestException copy-paste
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Oct 25, 2018
1 parent eaf9b7c commit 69dc390
Show file tree
Hide file tree
Showing 44 changed files with 24 additions and 118 deletions.
Expand Up @@ -58,7 +58,7 @@ class AbstractCoroutineTest : TestBase() {
}

override fun onCancellation(cause: Throwable?) {
assertTrue(cause is TestException0)
assertTrue(cause is TestException1)
expect(5)
}

Expand All @@ -67,30 +67,27 @@ class AbstractCoroutineTest : TestBase() {
}

override fun onCompletedExceptionally(exception: Throwable) {
assertTrue(exception is TestException0)
assertTrue(exception is TestException1)
expect(9)
}
}

coroutine.invokeOnCompletion(onCancelling = true) {
assertTrue(it is TestException0)
assertTrue(it is TestException1)
expect(6)
}

coroutine.invokeOnCompletion {
assertTrue(it is TestException0)
assertTrue(it is TestException1)
expect(8)
}

expect(2)
coroutine.start()
expect(4)
coroutine.cancel(TestException0())
coroutine.cancel(TestException1())
expect(7)
coroutine.resumeWithException(TestException1())
coroutine.resumeWithException(TestException2())
finish(10)
}

private class TestException0 : Throwable()
private class TestException1 : Throwable()
}
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/AsyncLazyTest.kt
Expand Up @@ -184,6 +184,4 @@ class AsyncLazyTest : TestBase() {
assertEquals(d.await(), 42) // await shall throw CancellationException
expectUnreached()
}

private class TestException : Exception()
}
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/AsyncTest.kt
Expand Up @@ -238,6 +238,4 @@ class AsyncTest : TestBase() {
finish(3)
}
}

private class TestException : Exception()
}
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/AwaitTest.kt
Expand Up @@ -351,6 +351,4 @@ class AwaitTest : TestBase() {
async(NonCancellable) { throw TestException() }
joinAll(job, job, job)
}

private class TestException : Exception()
}
Expand Up @@ -116,6 +116,4 @@ class CancellableContinuationTest : TestBase() {
continuation!!.resume(Unit) // Should not fail
finish(4)
}

private class TestException : Exception()
}
Expand Up @@ -184,6 +184,4 @@ class CompletableDeferredTest : TestBase() {
assertTrue(e is T)
}
}

class TestException : Throwable()
}
Expand Up @@ -44,6 +44,4 @@ class CoroutineExceptionHandlerTest : TestBase() {
assertTrue(parent.isCancelled)
assertTrue(parent.getCompletionExceptionOrNull() is TestException)
}

private class TestException: RuntimeException()
}
Expand Up @@ -258,7 +258,4 @@ class CoroutineScopeTest : TestBase() {

private fun scopePlusContext(c1: CoroutineContext, c2: CoroutineContext) =
(ContextScope(c1) + c2).coroutineContext

private class TestException1 : Exception()
private class TestException2 : Exception()
}
5 changes: 0 additions & 5 deletions common/kotlinx-coroutines-core-common/test/CoroutinesTest.kt
Expand Up @@ -330,9 +330,4 @@ class CoroutinesTest : TestBase() {
}

private fun throwTestException() { throw TestException() }

private class TestException : Exception {
constructor(message: String): super(message)
constructor(): super()
}
}
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/FailedJobTest.kt
Expand Up @@ -59,6 +59,4 @@ class FailedJobTest : TestBase() {
assertTrue(!job.isActive)
assertTrue(job.isCancelled)
}

private class TestException : Exception()
}
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/JobStatesTest.kt
Expand Up @@ -159,6 +159,4 @@ class JobStatesTest : TestBase() {
assertTrue(job.isCompleted)
assertTrue(job.isCancelled)
}

private class TestException : Exception()
}
5 changes: 1 addition & 4 deletions common/kotlinx-coroutines-core-common/test/JobTest.kt
Expand Up @@ -94,14 +94,13 @@ class JobTest : TestBase() {
val job = Job()
val n = 100 * stressTestMultiplier
val fireCount = IntArray(n)
class TestException : Throwable()
for (i in 0 until n) job.invokeOnCompletion {
fireCount[i]++
throw TestException()
}
assertTrue(job.isActive)
for (i in 0 until n) assertEquals(0, fireCount[i])
val tryCancel = Try<Unit> { job.cancel() }
val tryCancel = Try { job.cancel() }
assertTrue(!job.isActive)
for (i in 0 until n) assertEquals(1, fireCount[i])
assertTrue(tryCancel.exception is CompletionHandlerException)
Expand Down Expand Up @@ -206,6 +205,4 @@ class JobTest : TestBase() {
assertTrue(job.isCancelled)
assertTrue(parent.isCancelled)
}

private class TestException : Exception()
}
Expand Up @@ -123,6 +123,4 @@ class NonCancellableTest : TestBase() {
finish(7)
}
}

private class TestException : Exception()
}
Expand Up @@ -152,6 +152,4 @@ class ParentCancellationTest : TestBase() {
}
finish(3)
}

private class TestException : Exception()
}
3 changes: 0 additions & 3 deletions common/kotlinx-coroutines-core-common/test/SupervisorTest.kt
Expand Up @@ -218,7 +218,4 @@ class SupervisorTest : TestBase() {
yield() // to coroutineScope
finish(7)
}

private class TestException1 : Exception()
private class TestException2 : Exception()
}
5 changes: 5 additions & 0 deletions common/kotlinx-coroutines-core-common/test/TestBase.common.kt
Expand Up @@ -20,3 +20,8 @@ public expect open class TestBase constructor() {
block: suspend CoroutineScope.() -> Unit
)
}

class TestException(message: String? = null) : Throwable(message)
class TestException1(message: String? = null) : Throwable()
class TestException2(message: String? = null) : Throwable()
class TestException3(message: String? = null) : Throwable()
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/UnconfinedTest.kt
Expand Up @@ -110,6 +110,4 @@ class UnconfinedTest : TestBase() {

finish(7)
}

class TestException : Throwable()
}
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/WithContextTest.kt
Expand Up @@ -309,6 +309,4 @@ class WithContextTest : TestBase() {
}
}
}

private class TestException : Exception()
}
Expand Up @@ -210,8 +210,6 @@ class WithTimeoutOrNullTest : TestBase() {
}
}

private class TestException : Exception()

@Test
fun testNegativeTimeout() = runTest {
expect(1)
Expand Down
2 changes: 0 additions & 2 deletions common/kotlinx-coroutines-core-common/test/WithTimeoutTest.kt
Expand Up @@ -167,8 +167,6 @@ class WithTimeoutTest : TestBase() {
}
}

private class TestException : Exception()

@Test
fun testNegativeTimeout() = runTest {
expect(1)
Expand Down
Expand Up @@ -206,6 +206,4 @@ class ArrayBroadcastChannelTest : TestBase() {
assertTrue(sub.isClosedForReceive)
check(sub.receiveOrNull() == null)
}

private class TestException : Exception()
}
Expand Up @@ -144,6 +144,4 @@ class ArrayChannelTest : TestBase() {
channel.cancel(TestException())
channel.receiveOrNull()
}

private class TestException : Exception()
}
Expand Up @@ -147,6 +147,4 @@ class BasicOperationsTest : TestBase() {
assertEquals(iterations, expected)
}
}

private class TestException : Exception()
}
Expand Up @@ -83,6 +83,4 @@ class ConflatedChannelTest : TestBase() {
channel.cancel(TestException())
channel.receiveOrNull()
}

private class TestException : Exception()
}
Expand Up @@ -40,6 +40,4 @@ class LinkedListChannelTest : TestBase() {
channel.cancel(TestException())
channel.receiveOrNull()
}

private class TestException : Exception()
}
Expand Up @@ -112,6 +112,4 @@ class ProduceTest : TestBase() {
finish(4)
}
}

private class TestException : Exception()
}
Expand Up @@ -282,6 +282,4 @@ class RendezvousChannelTest : TestBase() {
channel.cancel(TestException())
channel.receiveOrNull()
}

private class TestException : Exception()
}
Expand Up @@ -4,11 +4,12 @@

package kotlinx.coroutines.selects

import kotlinx.coroutines.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
import kotlin.test.*

class SelectBuilderImplTest {
class SelectBuilderImplTest : TestBase() {
@Test
fun testIdempotentSelectResumeInline() {
var resumed = false
Expand Down Expand Up @@ -113,6 +114,4 @@ class SelectBuilderImplTest {
check(!c.trySelect("OTHER"))
check(c.trySelect("SELECT"))
}

class TestException : Throwable()
}
2 changes: 0 additions & 2 deletions core/kotlinx-coroutines-core/test/AwaitJvmTest.kt
Expand Up @@ -24,6 +24,4 @@ class AwaitJvmTest : TestBase() {
}
finish(iterations + 1)
}

private class TestException : Exception()
}
4 changes: 0 additions & 4 deletions core/kotlinx-coroutines-core/test/AwaitStressTest.kt
Expand Up @@ -10,10 +10,6 @@ import java.util.concurrent.*

class AwaitStressTest : TestBase() {

private class TestException : Exception() {
override fun fillInStackTrace(): Throwable = this
}

private val iterations = 50_000 * stressTestMultiplier
private val pool = newFixedThreadPoolContext(4, "AwaitStressTest")

Expand Down
2 changes: 0 additions & 2 deletions core/kotlinx-coroutines-core/test/CoroutinesJvmTest.kt
Expand Up @@ -36,6 +36,4 @@ class CoroutinesJvmTest : TestBase() {
}

private fun throwTestException(): Unit = throw TestException()

private class TestException : Exception()
}
2 changes: 0 additions & 2 deletions core/kotlinx-coroutines-core/test/JobActivationStressTest.kt
Expand Up @@ -68,6 +68,4 @@ class JobActivationStressTest : TestBase() {
}
}
}

private class TestException : Exception()
}
2 changes: 0 additions & 2 deletions core/kotlinx-coroutines-core/test/JobChildStressTest.kt
Expand Up @@ -57,6 +57,4 @@ class JobChildStressTest : TestBase() {
}
}
}

private class TestException : Exception()
}
4 changes: 0 additions & 4 deletions core/kotlinx-coroutines-core/test/JoinStressTest.kt
Expand Up @@ -20,10 +20,6 @@ class JoinStressTest : TestBase() {
pool.close()
}

class TestException : Exception() {
override fun fillInStackTrace(): Throwable = this
}

@Test
fun testExceptionalJoinWithCancellation() = runBlocking {
val results = IntArray(2)
Expand Down
Expand Up @@ -39,6 +39,4 @@ class CoroutineExceptionHandlerJvmTest : TestBase() {

finish(3)
}

private class TestException : Throwable()
}
Expand Up @@ -64,8 +64,4 @@ class JobExceptionsStressTest : TestBase() {
assertTrue(classes.isEmpty(), "Expected all exception to be present, but following exceptions are missing: $classes")
}
}

private class TestException1 : Exception()
private class TestException2 : Exception()
private class TestException3 : Exception()
}
Expand Up @@ -165,7 +165,4 @@ class ProduceExceptionsTest : TestBase() {
finish(4)
}
}

class TestException : Exception()
class TestException2 : Exception()
}
Expand Up @@ -46,10 +46,8 @@ class ListenableFutureExceptionsTest : TestBase() {
testException(TestException(), { it is TestException }, { i -> i!! + 1 })
}

class TestException : CompletionException("test2")

private fun testException(
exception: Exception,
exception: Throwable,
expected: ((Throwable) -> Boolean),
transformer: ((Int?) -> Int?)? = null
) {
Expand All @@ -61,7 +59,7 @@ class ListenableFutureExceptionsTest : TestBase() {
future.setException(exception)
try {
chained.await()
} catch (e: Exception) {
} catch (e: Throwable) {
assertTrue(expected(e))
}
}
Expand All @@ -76,7 +74,7 @@ class ListenableFutureExceptionsTest : TestBase() {

try {
chained.await()
} catch (e: Exception) {
} catch (e: Throwable) {
assertTrue(expected(e))
}
}
Expand Down

0 comments on commit 69dc390

Please sign in to comment.