Skip to content

Commit

Permalink
style: ktfmt format
Browse files Browse the repository at this point in the history
  • Loading branch information
coaguila committed Nov 20, 2024
1 parent 292c8b8 commit e5ca8f0
Showing 1 changed file with 41 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,72 +315,58 @@ class AlertViewModelTest {

@Test
fun getPalAlertsSuccess() = runBlocking {
doAnswer {
it.getArgument<() -> Unit>(1)()
}.`when`(alertModelSupabase)
.addAlert(
any<Alert>(),
any<() -> Unit>(),
any<(Exception) -> Unit>()
)
var count = 0
doAnswer {
doAnswer { it.getArgument<() -> Unit>(1)() }
.`when`(alertModelSupabase)
.addAlert(any<Alert>(), any<() -> Unit>(), any<(Exception) -> Unit>())
var count = 0
doAnswer {
if (count == 0) {
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert))
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert))
} else {
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert, alertOther))
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert, alertOther))
}
count++
}.`when`(alertModelSupabase)
.getAllAlerts(
any<(List<Alert>) -> Unit>(),
any<(Exception) -> Unit>()
)
assertEquals(listOf<Alert>(), viewModel.alerts.value)
viewModel.createAlert(alert)
assertEquals(listOf(alert), viewModel.alerts.value)
viewModel.createAlert(alertOther)
assertEquals(listOf(alert, alertOther), viewModel.alerts.value)

val result: List<Alert>? = viewModel.getPalAlerts(alert.uid)

assertNotNull(result)
assert(result!!.isNotEmpty())
assertEquals(listOf(alertOther), result)
}
.`when`(alertModelSupabase)
.getAllAlerts(any<(List<Alert>) -> Unit>(), any<(Exception) -> Unit>())
assertEquals(listOf<Alert>(), viewModel.alerts.value)
viewModel.createAlert(alert)
assertEquals(listOf(alert), viewModel.alerts.value)
viewModel.createAlert(alertOther)
assertEquals(listOf(alert, alertOther), viewModel.alerts.value)

val result: List<Alert>? = viewModel.getPalAlerts(alert.uid)

assertNotNull(result)
assert(result!!.isNotEmpty())
assertEquals(listOf(alertOther), result)
}

@Test
fun getPalAlertsFailure() = runBlocking {
doAnswer {
it.getArgument<() -> Unit>(1)()
}.`when`(alertModelSupabase)
.addAlert(
any<Alert>(),
any<() -> Unit>(),
any<(Exception) -> Unit>()
)
var count = 0
doAnswer {
doAnswer { it.getArgument<() -> Unit>(1)() }
.`when`(alertModelSupabase)
.addAlert(any<Alert>(), any<() -> Unit>(), any<(Exception) -> Unit>())
var count = 0
doAnswer {
if (count == 0) {
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert))
} else if (count == 1){
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert, alertOther))
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert))
} else if (count == 1) {
it.getArgument<(List<Alert>) -> Unit>(0)(listOf(alert, alertOther))
} else {
it.getArgument<(Exception) -> Unit>(1)(Exception("Supabase fail :("))
it.getArgument<(Exception) -> Unit>(1)(Exception("Supabase fail :("))
}
count++
}.`when`(alertModelSupabase)
.getAllAlerts(
any<(List<Alert>) -> Unit>(),
any<(Exception) -> Unit>()
)
assertEquals(listOf<Alert>(), viewModel.alerts.value)
viewModel.createAlert(alert)
assertEquals(listOf(alert), viewModel.alerts.value)
viewModel.createAlert(alertOther)
assertEquals(listOf(alert, alertOther), viewModel.alerts.value)

val result: List<Alert>? = viewModel.getPalAlerts(alert.uid)
assertNull(result)
}
.`when`(alertModelSupabase)
.getAllAlerts(any<(List<Alert>) -> Unit>(), any<(Exception) -> Unit>())
assertEquals(listOf<Alert>(), viewModel.alerts.value)
viewModel.createAlert(alert)
assertEquals(listOf(alert), viewModel.alerts.value)
viewModel.createAlert(alertOther)
assertEquals(listOf(alert, alertOther), viewModel.alerts.value)

val result: List<Alert>? = viewModel.getPalAlerts(alert.uid)
assertNull(result)
}
}

0 comments on commit e5ca8f0

Please sign in to comment.