Skip to content

Commit f0726ab

Browse files
committed
Return error instead of throwing in case site is null
1 parent 2568ebc commit f0726ab

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/localcatalog/WooPosFullSyncStatusChecker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class WooPosFullSyncStatusChecker @Inject constructor(
2323
@Suppress("ReturnCount")
2424
suspend fun checkSyncRequirement(): WooPosFullSyncRequirement {
2525
val site = selectedSite.getOrNull()
26-
?: error("No site selected")
26+
if (site == null) {
27+
wooPosLogWrapper.e("Full sync check failed: No site selected")
28+
return WooPosFullSyncRequirement.Error("No site selected")
29+
}
2730

2831
if (!isLocalCatalogSupported(site.localId())) {
2932
wooPosLogWrapper.d("Full sync check skipped: Local catalog not supported for site")

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/localcatalog/WooPosFullSyncStatusCheckerTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,19 @@ class WooPosFullSyncStatusCheckerTest {
8181
assertThat(result).isInstanceOf(WooPosFullSyncRequirement.LocalCatalogDisabled::class.java)
8282
}
8383

84-
@Test(expected = IllegalStateException::class)
85-
fun `given no site selected, when checkSyncRequirement called, then should throw error`() = runTest {
84+
@Test
85+
fun `given no site selected, when checkSyncRequirement called, then should return Error`() = runTest {
8686
// GIVEN
8787
whenever(selectedSite.getOrNull()).thenReturn(null)
8888

8989
val sut = createSut()
9090

9191
// WHEN
92-
sut.checkSyncRequirement()
92+
val result = sut.checkSyncRequirement()
9393

9494
// THEN
95-
// Exception is expected
95+
assertThat(result).isInstanceOf(WooPosFullSyncRequirement.Error::class.java)
96+
assertThat((result as WooPosFullSyncRequirement.Error).message).isEqualTo("No site selected")
9697
}
9798

9899
@Test

0 commit comments

Comments
 (0)