Skip to content

Commit 0b886a3

Browse files
committed
Get rid of TestException copy-paste
1 parent eaf9b7c commit 0b886a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+34
-127
lines changed

common/kotlinx-coroutines-core-common/test/AbstractCoroutineTest.kt

+6-9
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AbstractCoroutineTest : TestBase() {
5858
}
5959

6060
override fun onCancellation(cause: Throwable?) {
61-
assertTrue(cause is TestException0)
61+
assertTrue(cause is TestException1)
6262
expect(5)
6363
}
6464

@@ -67,30 +67,27 @@ class AbstractCoroutineTest : TestBase() {
6767
}
6868

6969
override fun onCompletedExceptionally(exception: Throwable) {
70-
assertTrue(exception is TestException0)
70+
assertTrue(exception is TestException1)
7171
expect(9)
7272
}
7373
}
7474

7575
coroutine.invokeOnCompletion(onCancelling = true) {
76-
assertTrue(it is TestException0)
76+
assertTrue(it is TestException1)
7777
expect(6)
7878
}
7979

8080
coroutine.invokeOnCompletion {
81-
assertTrue(it is TestException0)
81+
assertTrue(it is TestException1)
8282
expect(8)
8383
}
8484

8585
expect(2)
8686
coroutine.start()
8787
expect(4)
88-
coroutine.cancel(TestException0())
88+
coroutine.cancel(TestException1())
8989
expect(7)
90-
coroutine.resumeWithException(TestException1())
90+
coroutine.resumeWithException(TestException2())
9191
finish(10)
9292
}
93-
94-
private class TestException0 : Throwable()
95-
private class TestException1 : Throwable()
9693
}

common/kotlinx-coroutines-core-common/test/AsyncLazyTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,4 @@ class AsyncLazyTest : TestBase() {
184184
assertEquals(d.await(), 42) // await shall throw CancellationException
185185
expectUnreached()
186186
}
187-
188-
private class TestException : Exception()
189187
}

common/kotlinx-coroutines-core-common/test/AsyncTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,4 @@ class AsyncTest : TestBase() {
238238
finish(3)
239239
}
240240
}
241-
242-
private class TestException : Exception()
243241
}

common/kotlinx-coroutines-core-common/test/AwaitTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,4 @@ class AwaitTest : TestBase() {
351351
async(NonCancellable) { throw TestException() }
352352
joinAll(job, job, job)
353353
}
354-
355-
private class TestException : Exception()
356354
}

common/kotlinx-coroutines-core-common/test/CancellableContinuationTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,4 @@ class CancellableContinuationTest : TestBase() {
116116
continuation!!.resume(Unit) // Should not fail
117117
finish(4)
118118
}
119-
120-
private class TestException : Exception()
121119
}

common/kotlinx-coroutines-core-common/test/CompletableDeferredTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,4 @@ class CompletableDeferredTest : TestBase() {
184184
assertTrue(e is T)
185185
}
186186
}
187-
188-
class TestException : Throwable()
189187
}

common/kotlinx-coroutines-core-common/test/CoroutineExceptionHandlerTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,4 @@ class CoroutineExceptionHandlerTest : TestBase() {
4444
assertTrue(parent.isCancelled)
4545
assertTrue(parent.getCompletionExceptionOrNull() is TestException)
4646
}
47-
48-
private class TestException: RuntimeException()
4947
}

common/kotlinx-coroutines-core-common/test/CoroutineScopeTest.kt

-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,4 @@ class CoroutineScopeTest : TestBase() {
258258

259259
private fun scopePlusContext(c1: CoroutineContext, c2: CoroutineContext) =
260260
(ContextScope(c1) + c2).coroutineContext
261-
262-
private class TestException1 : Exception()
263-
private class TestException2 : Exception()
264261
}

common/kotlinx-coroutines-core-common/test/CoroutinesTest.kt

-5
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,4 @@ class CoroutinesTest : TestBase() {
330330
}
331331

332332
private fun throwTestException() { throw TestException() }
333-
334-
private class TestException : Exception {
335-
constructor(message: String): super(message)
336-
constructor(): super()
337-
}
338333
}

common/kotlinx-coroutines-core-common/test/FailedJobTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,4 @@ class FailedJobTest : TestBase() {
5959
assertTrue(!job.isActive)
6060
assertTrue(job.isCancelled)
6161
}
62-
63-
private class TestException : Exception()
6462
}

common/kotlinx-coroutines-core-common/test/JobStatesTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,4 @@ class JobStatesTest : TestBase() {
159159
assertTrue(job.isCompleted)
160160
assertTrue(job.isCancelled)
161161
}
162-
163-
private class TestException : Exception()
164162
}

common/kotlinx-coroutines-core-common/test/JobTest.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,13 @@ class JobTest : TestBase() {
9494
val job = Job()
9595
val n = 100 * stressTestMultiplier
9696
val fireCount = IntArray(n)
97-
class TestException : Throwable()
9897
for (i in 0 until n) job.invokeOnCompletion {
9998
fireCount[i]++
10099
throw TestException()
101100
}
102101
assertTrue(job.isActive)
103102
for (i in 0 until n) assertEquals(0, fireCount[i])
104-
val tryCancel = Try<Unit> { job.cancel() }
103+
val tryCancel = Try { job.cancel() }
105104
assertTrue(!job.isActive)
106105
for (i in 0 until n) assertEquals(1, fireCount[i])
107106
assertTrue(tryCancel.exception is CompletionHandlerException)
@@ -206,6 +205,4 @@ class JobTest : TestBase() {
206205
assertTrue(job.isCancelled)
207206
assertTrue(parent.isCancelled)
208207
}
209-
210-
private class TestException : Exception()
211208
}

common/kotlinx-coroutines-core-common/test/NonCancellableTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,4 @@ class NonCancellableTest : TestBase() {
123123
finish(7)
124124
}
125125
}
126-
127-
private class TestException : Exception()
128126
}

common/kotlinx-coroutines-core-common/test/ParentCancellationTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,4 @@ class ParentCancellationTest : TestBase() {
152152
}
153153
finish(3)
154154
}
155-
156-
private class TestException : Exception()
157155
}

common/kotlinx-coroutines-core-common/test/SupervisorTest.kt

-3
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,4 @@ class SupervisorTest : TestBase() {
218218
yield() // to coroutineScope
219219
finish(7)
220220
}
221-
222-
private class TestException1 : Exception()
223-
private class TestException2 : Exception()
224221
}

common/kotlinx-coroutines-core-common/test/TestBase.common.kt

+6
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ public expect open class TestBase constructor() {
2020
block: suspend CoroutineScope.() -> Unit
2121
)
2222
}
23+
24+
public class TestException(message: String? = null) : Throwable(message)
25+
public class TestException1(message: String? = null) : Throwable(message)
26+
public class TestException2(message: String? = null) : Throwable(message)
27+
public class TestException3(message: String? = null) : Throwable(message)
28+
public class TestRuntimeException(message: String? = null) : RuntimeException(message)

common/kotlinx-coroutines-core-common/test/UnconfinedTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,4 @@ class UnconfinedTest : TestBase() {
110110

111111
finish(7)
112112
}
113-
114-
class TestException : Throwable()
115113
}

common/kotlinx-coroutines-core-common/test/WithContextTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,4 @@ class WithContextTest : TestBase() {
309309
}
310310
}
311311
}
312-
313-
private class TestException : Exception()
314312
}

common/kotlinx-coroutines-core-common/test/WithTimeoutOrNullTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ class WithTimeoutOrNullTest : TestBase() {
210210
}
211211
}
212212

213-
private class TestException : Exception()
214-
215213
@Test
216214
fun testNegativeTimeout() = runTest {
217215
expect(1)

common/kotlinx-coroutines-core-common/test/WithTimeoutTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ class WithTimeoutTest : TestBase() {
167167
}
168168
}
169169

170-
private class TestException : Exception()
171-
172170
@Test
173171
fun testNegativeTimeout() = runTest {
174172
expect(1)

common/kotlinx-coroutines-core-common/test/channels/ArrayBroadcastChannelTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,4 @@ class ArrayBroadcastChannelTest : TestBase() {
206206
assertTrue(sub.isClosedForReceive)
207207
check(sub.receiveOrNull() == null)
208208
}
209-
210-
private class TestException : Exception()
211209
}

common/kotlinx-coroutines-core-common/test/channels/ArrayChannelTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,4 @@ class ArrayChannelTest : TestBase() {
144144
channel.cancel(TestException())
145145
channel.receiveOrNull()
146146
}
147-
148-
private class TestException : Exception()
149147
}

common/kotlinx-coroutines-core-common/test/channels/BasicOperationsTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,4 @@ class BasicOperationsTest : TestBase() {
147147
assertEquals(iterations, expected)
148148
}
149149
}
150-
151-
private class TestException : Exception()
152150
}

common/kotlinx-coroutines-core-common/test/channels/ConflatedChannelTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,4 @@ class ConflatedChannelTest : TestBase() {
8383
channel.cancel(TestException())
8484
channel.receiveOrNull()
8585
}
86-
87-
private class TestException : Exception()
8886
}

common/kotlinx-coroutines-core-common/test/channels/LinkedListChannelTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ class LinkedListChannelTest : TestBase() {
4040
channel.cancel(TestException())
4141
channel.receiveOrNull()
4242
}
43-
44-
private class TestException : Exception()
4543
}

common/kotlinx-coroutines-core-common/test/channels/ProduceTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,4 @@ class ProduceTest : TestBase() {
112112
finish(4)
113113
}
114114
}
115-
116-
private class TestException : Exception()
117115
}

common/kotlinx-coroutines-core-common/test/channels/RendezvousChannelTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,4 @@ class RendezvousChannelTest : TestBase() {
282282
channel.cancel(TestException())
283283
channel.receiveOrNull()
284284
}
285-
286-
private class TestException : Exception()
287285
}

common/kotlinx-coroutines-core-common/test/selects/SelectBuilderImplTest.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
package kotlinx.coroutines.selects
66

7+
import kotlinx.coroutines.*
78
import kotlin.coroutines.*
89
import kotlin.coroutines.intrinsics.*
910
import kotlin.test.*
1011

11-
class SelectBuilderImplTest {
12+
class SelectBuilderImplTest : TestBase() {
1213
@Test
1314
fun testIdempotentSelectResumeInline() {
1415
var resumed = false
@@ -113,6 +114,4 @@ class SelectBuilderImplTest {
113114
check(!c.trySelect("OTHER"))
114115
check(c.trySelect("SELECT"))
115116
}
116-
117-
class TestException : Throwable()
118117
}

core/kotlinx-coroutines-core/test/AwaitJvmTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,4 @@ class AwaitJvmTest : TestBase() {
2424
}
2525
finish(iterations + 1)
2626
}
27-
28-
private class TestException : Exception()
2927
}

core/kotlinx-coroutines-core/test/AwaitStressTest.kt

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import java.util.concurrent.*
1010

1111
class AwaitStressTest : TestBase() {
1212

13-
private class TestException : Exception() {
14-
override fun fillInStackTrace(): Throwable = this
15-
}
16-
1713
private val iterations = 50_000 * stressTestMultiplier
1814
private val pool = newFixedThreadPoolContext(4, "AwaitStressTest")
1915

core/kotlinx-coroutines-core/test/CoroutinesJvmTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,4 @@ class CoroutinesJvmTest : TestBase() {
3636
}
3737

3838
private fun throwTestException(): Unit = throw TestException()
39-
40-
private class TestException : Exception()
4139
}

core/kotlinx-coroutines-core/test/JobActivationStressTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,4 @@ class JobActivationStressTest : TestBase() {
6868
}
6969
}
7070
}
71-
72-
private class TestException : Exception()
7371
}

core/kotlinx-coroutines-core/test/JobChildStressTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,4 @@ class JobChildStressTest : TestBase() {
5757
}
5858
}
5959
}
60-
61-
private class TestException : Exception()
6260
}

core/kotlinx-coroutines-core/test/JoinStressTest.kt

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ class JoinStressTest : TestBase() {
2020
pool.close()
2121
}
2222

23-
class TestException : Exception() {
24-
override fun fillInStackTrace(): Throwable = this
25-
}
26-
2723
@Test
2824
fun testExceptionalJoinWithCancellation() = runBlocking {
2925
val results = IntArray(2)

core/kotlinx-coroutines-core/test/exceptions/CoroutineExceptionHandlerJvmTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@ class CoroutineExceptionHandlerJvmTest : TestBase() {
3939

4040
finish(3)
4141
}
42-
43-
private class TestException : Throwable()
4442
}

core/kotlinx-coroutines-core/test/exceptions/JobExceptionsStressTest.kt

-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,4 @@ class JobExceptionsStressTest : TestBase() {
6464
assertTrue(classes.isEmpty(), "Expected all exception to be present, but following exceptions are missing: $classes")
6565
}
6666
}
67-
68-
private class TestException1 : Exception()
69-
private class TestException2 : Exception()
70-
private class TestException3 : Exception()
7167
}

core/kotlinx-coroutines-core/test/exceptions/ProduceExceptionsTest.kt

-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,4 @@ class ProduceExceptionsTest : TestBase() {
165165
finish(4)
166166
}
167167
}
168-
169-
class TestException : Exception()
170-
class TestException2 : Exception()
171168
}

integration/kotlinx-coroutines-guava/test/ListenableFutureExceptionsTest.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ class ListenableFutureExceptionsTest : TestBase() {
4646
testException(TestException(), { it is TestException }, { i -> i!! + 1 })
4747
}
4848

49-
class TestException : CompletionException("test2")
50-
5149
private fun testException(
52-
exception: Exception,
50+
exception: Throwable,
5351
expected: ((Throwable) -> Boolean),
5452
transformer: ((Int?) -> Int?)? = null
5553
) {
@@ -61,7 +59,7 @@ class ListenableFutureExceptionsTest : TestBase() {
6159
future.setException(exception)
6260
try {
6361
chained.await()
64-
} catch (e: Exception) {
62+
} catch (e: Throwable) {
6563
assertTrue(expected(e))
6664
}
6765
}
@@ -76,7 +74,7 @@ class ListenableFutureExceptionsTest : TestBase() {
7674

7775
try {
7876
chained.await()
79-
} catch (e: Exception) {
77+
} catch (e: Throwable) {
8078
assertTrue(expected(e))
8179
}
8280
}

0 commit comments

Comments
 (0)