Skip to content

Commit 52a627a

Browse files
committed
rename assertion
1 parent 95b1e47 commit 52a627a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

core-kotlin-modules/core-kotlin-concurrency-3/src/test/java/com/baeldung/singlerxjavatocoroutinedeferred/SingleRxJavaToCoroutineDeferredUnitTest.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import kotlinx.coroutines.*
66
import kotlinx.coroutines.rx3.await
77
import org.assertj.core.api.Assertions.assertThat
88
import org.junit.jupiter.api.Test
9+
import org.slf4j.LoggerFactory
910
import kotlin.coroutines.CoroutineContext
1011
import kotlin.coroutines.resume
1112
import kotlin.coroutines.resumeWithException
@@ -15,6 +16,8 @@ import kotlin.test.assertTrue
1516

1617
class SingleRxJavaToCoroutineDeferredUnitTest {
1718

19+
private val logger = LoggerFactory.getLogger("")
20+
1821
data class Product(val id: Int, val name: String, val price: Double)
1922

2023
private val allProducts = listOf(
@@ -33,7 +36,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
3336
}.subscribeOn(Schedulers.io())
3437
}
3538

36-
private suspend fun Deferred<*>.assertResultsTrue() {
39+
private suspend fun Deferred<*>.assertOver500AndSorted() {
3740
assertTrue(actual = this is Deferred<*>)
3841

3942
assertThat(this.await() as List<*>).containsExactly(
@@ -46,7 +49,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
4649
@Test
4750
fun `using async direcly and blockingGet`() = runBlocking {
4851
val deferred = async { getFilteredProducts().blockingGet() } // simple, but must be careful because blocking main thread
49-
deferred.assertResultsTrue() // assertion test
52+
deferred.assertOver500AndSorted() // assertion test
5053
}
5154

5255
// using async with extension
@@ -57,7 +60,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
5760
@Test
5861
fun `test using async with extension`() = runBlocking {
5962
val deferredExt = getFilteredProducts().toDeferredAsync()
60-
deferredExt.assertResultsTrue()
63+
deferredExt.assertOver500AndSorted()
6164
}
6265

6366
// using CoroutineScope(context).async
@@ -67,7 +70,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
6770
@Test
6871
fun `test using CoroutineScope with context and async`(): Unit = runBlocking {
6972
val deferred = getFilteredProducts().toDeferredWithContext(Dispatchers.IO)
70-
deferred.assertResultsTrue()
73+
deferred.assertOver500AndSorted()
7174
}
7275

7376
// using CompletableDeferred & subscribe
@@ -79,7 +82,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
7982
}, { error ->
8083
deferred.completeExceptionally(error)
8184
})
82-
deferred.assertResultsTrue()
85+
deferred.assertOver500AndSorted()
8386
}
8487

8588
// using CompletableDeferred extension
@@ -107,15 +110,15 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
107110
@Test
108111
fun `test using CompletableDeferred extension`() = runBlocking {
109112
val deferred = getFilteredProducts().toCompletableDeferred()
110-
deferred.assertResultsTrue()
113+
deferred.assertOver500AndSorted()
111114
}
112115

113116
@Test
114117
fun `test using CompletableDeferred with callback`(): Unit = runBlocking {
115118
getFilteredProducts().toCompletableDeferred(onSuccess = { deferredResult, _ ->
116-
launch { deferredResult.assertResultsTrue() }
119+
launch { deferredResult.assertOver500AndSorted() }
117120
}, onError = { _, error ->
118-
println("Error: ${error.message}")
121+
logger.debug("Error: ${error.message}")
119122
}).await()
120123
}
121124

@@ -129,7 +132,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
129132
}
130133
}
131134
}
132-
defered.assertResultsTrue()
135+
defered.assertOver500AndSorted()
133136
}
134137

135138
// using suspendCoroutines with extension
@@ -148,7 +151,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
148151
@Test
149152
fun `test using suspendCoroutine extension`() = runBlocking {
150153
val deferred = getFilteredProducts().toDeferredWithSuspend()
151-
deferred.assertResultsTrue()
154+
deferred.assertOver500AndSorted()
152155
}
153156

154157
// using suspendCancellableCoroutine
@@ -175,17 +178,17 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
175178
@Test
176179
fun `test using suspendCancellableCoroutine with custom callback`(): Unit = runBlocking {
177180
getFilteredProducts().toDeferredWithSuspendCancellableCoroutine(onSuccess = { deferredResult ->
178-
launch { deferredResult.assertResultsTrue() }
181+
launch { deferredResult.assertOver500AndSorted() }
179182
}, onError = { error ->
180-
println("Error: ${error.message}")
183+
logger.debug("Error: ${error.message}")
181184
}).await()
182185
}
183186

184187
// using rx3 directly
185188
@Test
186189
fun `using rx3 directly`() = runBlocking {
187190
val deferred = async { getFilteredProducts().await() }
188-
deferred.assertResultsTrue()
191+
deferred.assertOver500AndSorted()
189192
}
190193

191194
// using rx3 ext
@@ -195,7 +198,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
195198
@Test
196199
fun `test using rx3 ext`() = runBlocking {
197200
val deferred = getFilteredProducts().toDeferredRx3()
198-
deferred.assertResultsTrue()
201+
deferred.assertOver500AndSorted()
199202
}
200203

201204
// using rx3 with context
@@ -205,7 +208,7 @@ class SingleRxJavaToCoroutineDeferredUnitTest {
205208
@Test
206209
fun `test using rx3 with context`(): Unit = runBlocking {
207210
val deferred = getFilteredProducts().toDeferredRx3WithContext(Dispatchers.IO)
208-
deferred.assertResultsTrue()
211+
deferred.assertOver500AndSorted()
209212
}
210213

211214
}

0 commit comments

Comments
 (0)