1
1
package kotlinx.coroutines.tasks
2
2
3
+ import kotlinx.coroutines.testing.*
3
4
import com.google.android.gms.tasks.*
4
5
import kotlinx.coroutines.*
5
6
import org.junit.*
@@ -50,7 +51,7 @@ class TaskTest : TestBase() {
50
51
try {
51
52
runTest { task.await() }
52
53
} catch (e: Exception ) {
53
- assertTrue(e is CancellationException )
54
+ assertIs< CancellationException >(e )
54
55
assertTrue(task.isCanceled)
55
56
}
56
57
}
@@ -102,7 +103,7 @@ class TaskTest : TestBase() {
102
103
deferred.await()
103
104
fail(" deferred.await() should be cancelled" )
104
105
} catch (e: Exception ) {
105
- assertTrue(e is CancellationException )
106
+ assertIs< CancellationException >(e )
106
107
}
107
108
}
108
109
@@ -112,14 +113,14 @@ class TaskTest : TestBase() {
112
113
113
114
assertTrue(deferred.isCancelled && deferred.isCompleted)
114
115
val completionException = deferred.getCompletionExceptionOrNull()!!
115
- assertTrue (completionException is TestException )
116
+ assertIs< TestException > (completionException)
116
117
assertEquals(" something went wrong" , completionException.message)
117
118
118
119
try {
119
120
deferred.await()
120
121
fail(" deferred.await() should throw an exception" )
121
122
} catch (e: Exception ) {
122
- assertTrue(e is TestException )
123
+ assertIs< TestException >(e )
123
124
assertEquals(" something went wrong" , e.message)
124
125
}
125
126
}
@@ -139,7 +140,7 @@ class TaskTest : TestBase() {
139
140
deferred.await()
140
141
fail(" deferred.await() should throw an exception" )
141
142
} catch (e: Exception ) {
142
- assertTrue(e is TestException )
143
+ assertIs< TestException >(e )
143
144
assertEquals(" something went wrong" , e.message)
144
145
assertSame(e.cause, deferred.getCompletionExceptionOrNull()) // debug mode stack augmentation
145
146
}
@@ -170,7 +171,7 @@ class TaskTest : TestBase() {
170
171
deferred.await()
171
172
fail(" deferred.await() should be cancelled" )
172
173
} catch (e: Exception ) {
173
- assertTrue(e is CancellationException )
174
+ assertIs< CancellationException >(e )
174
175
}
175
176
assertTrue(cancellationTokenSource.token.isCancellationRequested)
176
177
}
@@ -186,7 +187,7 @@ class TaskTest : TestBase() {
186
187
deferred.await()
187
188
fail(" deferred.await() should be cancelled" )
188
189
} catch (e: Exception ) {
189
- assertTrue(e is CancellationException )
190
+ assertIs< CancellationException >(e )
190
191
}
191
192
assertTrue(cancellationTokenSource.token.isCancellationRequested)
192
193
}
@@ -203,7 +204,7 @@ class TaskTest : TestBase() {
203
204
deferred.await()
204
205
fail(" deferred.await() should be cancelled" )
205
206
} catch (e: Exception ) {
206
- assertTrue(e is CancellationException )
207
+ assertIs< CancellationException >(e )
207
208
}
208
209
assertTrue(cancellationTokenSource.token.isCancellationRequested)
209
210
}
@@ -222,18 +223,19 @@ class TaskTest : TestBase() {
222
223
@Test
223
224
fun testFailedCancellableTaskAsDeferred () = runTest {
224
225
val cancellationTokenSource = CancellationTokenSource ()
225
- val deferred = Tasks .forException<Int >(TestException (" something went wrong" )).asDeferred(cancellationTokenSource)
226
+ val deferred =
227
+ Tasks .forException<Int >(TestException (" something went wrong" )).asDeferred(cancellationTokenSource)
226
228
227
229
assertTrue(deferred.isCancelled && deferred.isCompleted)
228
230
val completionException = deferred.getCompletionExceptionOrNull()!!
229
- assertTrue (completionException is TestException )
231
+ assertIs< TestException > (completionException)
230
232
assertEquals(" something went wrong" , completionException.message)
231
233
232
234
try {
233
235
deferred.await()
234
236
fail(" deferred.await() should throw an exception" )
235
237
} catch (e: Exception ) {
236
- assertTrue(e is TestException )
238
+ assertIs< TestException >(e )
237
239
assertEquals(" something went wrong" , e.message)
238
240
}
239
241
assertTrue(cancellationTokenSource.token.isCancellationRequested)
@@ -255,7 +257,7 @@ class TaskTest : TestBase() {
255
257
deferred.await()
256
258
fail(" deferred.await() should throw an exception" )
257
259
} catch (e: Exception ) {
258
- assertTrue(e is TestException )
260
+ assertIs< TestException >(e )
259
261
assertEquals(" something went wrong" , e.message)
260
262
assertSame(e.cause, deferred.getCompletionExceptionOrNull()) // debug mode stack augmentation
261
263
}
@@ -318,7 +320,7 @@ class TaskTest : TestBase() {
318
320
deferred.await()
319
321
fail(" deferred.await() should be cancelled" )
320
322
} catch (e: Exception ) {
321
- assertTrue(e is CancellationException )
323
+ assertIs< CancellationException >(e )
322
324
}
323
325
324
326
assertTrue(cancellationTokenSource.token.isCancellationRequested)
@@ -341,7 +343,7 @@ class TaskTest : TestBase() {
341
343
deferred.await()
342
344
fail(" deferred.await() should be cancelled" )
343
345
} catch (e: Exception ) {
344
- assertTrue(e is CancellationException )
346
+ assertIs< CancellationException >(e )
345
347
}
346
348
347
349
assertTrue(cancellationTokenSource.token.isCancellationRequested)
0 commit comments