Skip to content

Commit 45c874b

Browse files
committed
plugins/main: adapt NFC command tests
1 parent 8ecd0cc commit 45c874b

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

plugins/main/src/test/kotlin/app/aaps/plugins/main/general/nfcCommands/NfcCommandsPluginTest.kt

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,9 @@ class NfcCommandsPluginTest : TestBaseWithProfile() {
939939
whenever(enactResult.comment).thenReturn("ok")
940940
callbackCaptor.firstValue.result(enactResult).run()
941941

942-
verify(persistenceLayer).insertAndCancelCurrentTemporaryTarget(any(), eq(Action.TT), eq(Sources.NfcCommands), anyOrNull(), any())
942+
runTest {
943+
verify(persistenceLayer).insertAndCancelCurrentTemporaryTarget(any(), eq(Action.TT), eq(Sources.NfcCommands), anyOrNull(), any())
944+
}
943945
}
944946

945947
@Test
@@ -966,7 +968,9 @@ class NfcCommandsPluginTest : TestBaseWithProfile() {
966968
whenever(enactResult.comment).thenReturn("ok")
967969
callbackCaptor.firstValue.result(enactResult).run()
968970

969-
verify(persistenceLayer, never()).insertAndCancelCurrentTemporaryTarget(any(), any(), any(), anyOrNull(), any())
971+
runTest {
972+
verify(persistenceLayer, never()).insertAndCancelCurrentTemporaryTarget(any(), any(), any(), anyOrNull(), any())
973+
}
970974
}
971975

972976
// ── processCarbs tests ─────────────────────────────────────────────────────
@@ -1064,7 +1068,9 @@ class NfcCommandsPluginTest : TestBaseWithProfile() {
10641068
val result = plugin.executeCommand("TARGET CANCEL")
10651069

10661070
assertThat(result.success).isTrue()
1067-
verify(persistenceLayer).cancelCurrentTemporaryTargetIfAny(any(), eq(Action.CANCEL_TT), eq(Sources.NfcCommands), anyOrNull(), any())
1071+
runTest {
1072+
verify(persistenceLayer).cancelCurrentTemporaryTargetIfAny(any(), eq(Action.CANCEL_TT), eq(Sources.NfcCommands), anyOrNull(), any())
1073+
}
10681074
}
10691075

10701076
@Test
@@ -1117,27 +1123,32 @@ class NfcCommandsPluginTest : TestBaseWithProfile() {
11171123
fun `executeCommand PROFILE should create profile switch with default percentage`() {
11181124
whenever(localProfileManager.profile).thenReturn(mockProfileStore)
11191125
whenever(mockProfileStore.getProfileList()).thenReturn(arrayListOf("Default"))
1120-
whenever(profileFunction.createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any()))
1121-
.thenReturn(true)
1126+
runTest {
1127+
whenever(profileFunction.createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any(), any()))
1128+
.thenReturn(mock())
1129+
}
11221130
whenever(rh.gs(R.string.nfccommands_profile_switch_created)).thenReturn("Profile switch created")
11231131
whenever(rh.gsNotLocalised(R.string.nfccommands_profile_switch_created)).thenReturn("Profile switch created")
11241132
whenever(dateUtil.now()).thenReturn(55_000L)
11251133

11261134
val result = plugin.executeCommand("PROFILE 1")
11271135

11281136
assertThat(result.success).isTrue()
1129-
verify(profileFunction).createProfileSwitch(
1130-
eq(mockProfileStore),
1131-
eq("Default"),
1132-
eq(0),
1133-
eq(100),
1134-
eq(0),
1135-
eq(55_000L),
1136-
eq(Action.PROFILE_SWITCH),
1137-
eq(Sources.NfcCommands),
1138-
eq("Profile switch created"),
1139-
any(),
1140-
)
1137+
runTest {
1138+
verify(profileFunction).createProfileSwitch(
1139+
eq(mockProfileStore),
1140+
eq("Default"),
1141+
eq(0),
1142+
eq(100),
1143+
eq(0),
1144+
eq(55_000L),
1145+
eq(Action.PROFILE_SWITCH),
1146+
eq(Sources.NfcCommands),
1147+
eq("Profile switch created"),
1148+
any(),
1149+
any(),
1150+
)
1151+
}
11411152
}
11421153

11431154
@Test
@@ -1155,8 +1166,10 @@ class NfcCommandsPluginTest : TestBaseWithProfile() {
11551166
fun `executeCommand PROFILE should fail when profile switch creation fails`() {
11561167
whenever(localProfileManager.profile).thenReturn(mockProfileStore)
11571168
whenever(mockProfileStore.getProfileList()).thenReturn(arrayListOf("Default"))
1158-
whenever(profileFunction.createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any()))
1159-
.thenReturn(false)
1169+
runTest {
1170+
whenever(profileFunction.createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any(), any()))
1171+
.thenReturn(null)
1172+
}
11601173
whenever(rh.gs(R.string.nfccommands_profile_switch_created)).thenReturn("Profile switch created")
11611174
whenever(rh.gsNotLocalised(R.string.nfccommands_profile_switch_created)).thenReturn("Profile switch created")
11621175
whenever(rh.gs(app.aaps.core.ui.R.string.invalid_profile)).thenReturn("Invalid profile")
@@ -1635,7 +1648,9 @@ class NfcCommandsPluginTest : TestBaseWithProfile() {
16351648
val result = plugin.executeCommand("PROFILE 0")
16361649

16371650
assertThat(result.success).isFalse()
1638-
verify(profileFunction, never()).createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any())
1651+
runTest {
1652+
verify(profileFunction, never()).createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any(), any())
1653+
}
16391654
}
16401655

16411656
@Test
@@ -1646,7 +1661,9 @@ class NfcCommandsPluginTest : TestBaseWithProfile() {
16461661
val result = plugin.executeCommand("PROFILE 99")
16471662

16481663
assertThat(result.success).isFalse()
1649-
verify(profileFunction, never()).createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any())
1664+
runTest {
1665+
verify(profileFunction, never()).createProfileSwitch(any(), any(), any(), any(), any(), any(), any(), any(), anyOrNull(), any(), any())
1666+
}
16501667
}
16511668

16521669
// processAapsClient – wrong argument count

0 commit comments

Comments
 (0)