diff --git a/dependencies.gradle b/dependencies.gradle index 47475105..3bbfeeac 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -13,7 +13,7 @@ ext.versions = [ rxAndroid: '2.0.2', rxKotlin: '2.2.0', rxJava1: '1.3.4', - kotlinxCoroutines: '1.4.3', + kotlinxCoroutines: '1.5.2', stetho: '1.5.0', stethoOkHttp: '1.5.0', @@ -42,6 +42,7 @@ ext.versions = [ junit: '4.12', assertJ: '3.8.0', + truth: '1.1.3', stateMachine: "0.2.0" ] @@ -61,7 +62,8 @@ ext.libs = [ kotlinx: [ coroutines: [ core: "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.kotlinxCoroutines", - reactive: "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$versions.kotlinxCoroutines" + reactive: "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$versions.kotlinxCoroutines", + test: "org.jetbrains.kotlinx:kotlinx-coroutines-test:$versions.kotlinxCoroutines" ] ], @@ -100,6 +102,7 @@ ext.libs = [ junit: "junit:junit:$versions.junit", mockito: "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0", assertJ: "org.assertj:assertj-core:$versions.assertJ", + truth: "com.google.truth:truth:$versions.truth", kotlin: [ stdlib: "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version", diff --git a/scarlet-stream-adapter-coroutines/build.gradle b/scarlet-stream-adapter-coroutines/build.gradle index 23aca8e1..b9b192a1 100644 --- a/scarlet-stream-adapter-coroutines/build.gradle +++ b/scarlet-stream-adapter-coroutines/build.gradle @@ -15,5 +15,6 @@ dependencies { testImplementation libs.junit testImplementation libs.mockito testImplementation libs.kotlin.reflect - testImplementation libs.assertJ + testImplementation libs.kotlinx.coroutines.test + testImplementation libs.truth } diff --git a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelAdapter.kt b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelAdapter.kt index a103a524..4b76baf2 100644 --- a/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelAdapter.kt +++ b/scarlet-stream-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelAdapter.kt @@ -27,6 +27,7 @@ class ReceiveChannelAdapter : StreamAdapter> { } override fun onNext(data: T) { + println("$data is ") _channel.sendBlocking(data) } } diff --git a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt index a89464ce..bcca4cdc 100644 --- a/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt +++ b/scarlet-stream-adapter-coroutines/src/test/java/com/tinder/scarlet/streamadapter/coroutines/ReceiveChannelTest.kt @@ -4,6 +4,7 @@ package com.tinder.scarlet.streamadapter.coroutines +import com.google.common.truth.Truth.assertThat import com.tinder.scarlet.Lifecycle import com.tinder.scarlet.Scarlet import com.tinder.scarlet.Stream @@ -11,9 +12,9 @@ import com.tinder.scarlet.WebSocket import com.tinder.scarlet.lifecycle.LifecycleRegistry import com.tinder.scarlet.testutils.TestStreamObserver import com.tinder.scarlet.testutils.any -import com.tinder.scarlet.testutils.test -import com.tinder.scarlet.testutils.containingText import com.tinder.scarlet.testutils.containingBytes +import com.tinder.scarlet.testutils.containingText +import com.tinder.scarlet.testutils.test import com.tinder.scarlet.websocket.mockwebserver.newWebSocketFactory import com.tinder.scarlet.websocket.okhttp.newWebSocketFactory import com.tinder.scarlet.ws.Receive @@ -23,7 +24,6 @@ import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.runBlocking import okhttp3.OkHttpClient import okhttp3.mockwebserver.MockWebServer -import org.assertj.core.api.Assertions.assertThat import org.junit.Rule import org.junit.Test import java.util.concurrent.TimeUnit @@ -63,19 +63,19 @@ class ReceiveChannelTest { assertThat(isSendBytesSuccessful).isTrue() serverEventObserver.awaitValues( - any>(), - any().containingText(textMessage1), - any().containingText(textMessage2), - any().containingBytes(bytesMessage1), - any().containingBytes(bytesMessage2) + any>(), + any().containingText(textMessage1), + any().containingText(textMessage2), + any().containingBytes(bytesMessage1), + any().containingBytes(bytesMessage2) ) runBlocking { - assertThat(testTextChannel.receiveOrNull()).isEqualTo(textMessage1) - assertThat(testTextChannel.receiveOrNull()).isEqualTo(textMessage2) + assertThat(testTextChannel.receive()).isEqualTo(textMessage1) + assertThat(testTextChannel.receive()).isEqualTo(textMessage2) - assertThat(testBytesChannel.receiveOrNull()).isEqualTo(bytesMessage1) - assertThat(testBytesChannel.receiveOrNull()).isEqualTo(bytesMessage2) + assertThat(testBytesChannel.receive()).isEqualTo(bytesMessage1) + assertThat(testBytesChannel.receive()).isEqualTo(bytesMessage2) } } @@ -96,33 +96,33 @@ class ReceiveChannelTest { private fun createServer(): Service { val webSocketFactory = mockWebServer.newWebSocketFactory() val scarlet = Scarlet.Builder() - .webSocketFactory(webSocketFactory) - .lifecycle(serverLifecycleRegistry) - .addStreamAdapterFactory(CoroutinesStreamAdapterFactory()) - .build() + .webSocketFactory(webSocketFactory) + .lifecycle(serverLifecycleRegistry) + .addStreamAdapterFactory(CoroutinesStreamAdapterFactory()) + .build() return scarlet.create() } private fun createClient(): Service { val okHttpClient = OkHttpClient.Builder() - .writeTimeout(500, TimeUnit.MILLISECONDS) - .readTimeout(500, TimeUnit.MILLISECONDS) - .build() + .writeTimeout(500, TimeUnit.MILLISECONDS) + .readTimeout(500, TimeUnit.MILLISECONDS) + .build() val webSocketFactory = okHttpClient.newWebSocketFactory(serverUrlString) val scarlet = Scarlet.Builder() - .webSocketFactory(webSocketFactory) - .lifecycle(clientLifecycleRegistry) - .addStreamAdapterFactory(CoroutinesStreamAdapterFactory()) - .build() + .webSocketFactory(webSocketFactory) + .lifecycle(clientLifecycleRegistry) + .addStreamAdapterFactory(CoroutinesStreamAdapterFactory()) + .build() return scarlet.create() } private fun blockUntilConnectionIsEstablish() { clientEventObserver.awaitValues( - any>() + any>() ) serverEventObserver.awaitValues( - any>() + any>() ) } @@ -148,4 +148,4 @@ class ReceiveChannelTest { @Send fun sendBytesAndConfirm(message: ByteArray): Boolean } -} \ No newline at end of file +}