diff --git a/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt b/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt index cd124fc675..97727ab5af 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt @@ -15,6 +15,7 @@ import org.json.JSONObject class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface { var connected = false + var isProfileSet = true override fun isConnected() = connected override fun isConnecting() = false @@ -42,7 +43,7 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface { override fun waitForDisconnectionInSeconds(): Int = 0 override fun getPumpStatus(reason: String) {} override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector) - override fun isThisProfileSet(profile: Profile): Boolean = true + override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet override fun lastDataTime(): Long = lastData override val baseBasalRate: Double = baseBasal override val reservoirLevel: Double = 0.0 diff --git a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt index 3518805b82..90a77637f9 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt @@ -344,6 +344,42 @@ class CommandQueueTest : TestBaseWithProfile() { Assert.assertEquals(1, commandQueue.size()) } + @Test + fun isProfileSetCommandInQueue() { + // given + Assert.assertEquals(0, commandQueue.size()) + + // when + testPumpPlugin.isProfileSet = true + commandQueue.setProfile(validProfile, object : Callback() { + override fun run() { + Assert.assertTrue(result.success) + Assert.assertFalse(result.enacted) + } + }) + + // then + // the same profile -> ignore + Assert.assertEquals(0, commandQueue.size()) + // different should be added + testPumpPlugin.isProfileSet = false + commandQueue.setProfile(validProfile, object : Callback() { + override fun run() { + Assert.assertTrue(result.success) + Assert.assertTrue(result.enacted) + } + }) + Assert.assertEquals(1, commandQueue.size()) + // next should be ignored + commandQueue.setProfile(validProfile, object : Callback() { + override fun run() { + Assert.assertTrue(result.success) + } + }) + Assert.assertEquals(1, commandQueue.size()) + testPumpPlugin.isProfileSet = true + } + @Test fun isStopCommandInQueue() { // given