Skip to content

Commit

Permalink
[#465] Switch to use turbine for stability
Browse files Browse the repository at this point in the history
  • Loading branch information
luongvo committed May 19, 2023
1 parent 34c7d9a commit 0196415
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ class ResponseMappingTest {
runTest {
flowTransform<Model> {
throw UnknownHostException()
}.catch {
it shouldBe NoConnectivityException
}.collect()
}.test {
awaitError() shouldBe NoConnectivityException
}
}

@Test
fun `When mapping API request flow failed with InterruptedIOException, it returns mapped NoConnectivityException error`() =
runTest {
flowTransform<Model> {
throw InterruptedIOException()
}.catch {
it shouldBe NoConnectivityException
}.collect()
}.test {
awaitError() shouldBe NoConnectivityException
}
}

@Test
Expand All @@ -44,13 +44,13 @@ class ResponseMappingTest {
val httpException = MockUtil.mockHttpException
flowTransform<Model> {
throw httpException
}.catch {
it shouldBe ApiException(
}.test {
awaitError() shouldBe ApiException(
MockUtil.errorResponse.toModel(),
httpException.code(),
httpException.message()
)
}.collect()
}
}

@Test
Expand All @@ -59,8 +59,8 @@ class ResponseMappingTest {
val exception = IOException("Canceled")
flowTransform<Model> {
throw exception
}.catch {
it shouldBe exception
}.collect()
}.test {
awaitError() shouldBe exception
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package co.nimblehq.template.compose.data.extensions

import app.cash.turbine.test
import co.nimblehq.template.compose.data.response.toModel
import co.nimblehq.template.compose.data.test.MockUtil
import co.nimblehq.template.compose.domain.exceptions.ApiException
import co.nimblehq.template.compose.domain.exceptions.NoConnectivityException
import co.nimblehq.template.compose.domain.model.Model
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.test.runTest
import org.junit.Test
import java.io.IOException
Expand All @@ -23,19 +22,19 @@ class ResponseMappingTest {
runTest {
flowTransform<Model> {
throw UnknownHostException()
}.catch {
it shouldBe NoConnectivityException
}.collect()
}.test {
awaitError() shouldBe NoConnectivityException
}
}

@Test
fun `When mapping API request flow failed with InterruptedIOException, it returns mapped NoConnectivityException error`() =
runTest {
flowTransform<Model> {
throw InterruptedIOException()
}.catch {
it shouldBe NoConnectivityException
}.collect()
}.test {
awaitError() shouldBe NoConnectivityException
}
}

@Test
Expand All @@ -44,13 +43,13 @@ class ResponseMappingTest {
val httpException = MockUtil.mockHttpException
flowTransform<Model> {
throw httpException
}.catch {
it shouldBe ApiException(
}.test {
awaitError() shouldBe ApiException(
MockUtil.errorResponse.toModel(),
httpException.code(),
httpException.message()
)
}.collect()
}
}

@Test
Expand All @@ -59,8 +58,8 @@ class ResponseMappingTest {
val exception = IOException("Canceled")
flowTransform<Model> {
throw exception
}.catch {
it shouldBe exception
}.collect()
}.test {
awaitError() shouldBe exception
}
}
}

0 comments on commit 0196415

Please sign in to comment.