From e5dc655c64aca2e9f90bfc47c90fce3aaf76f636 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 30 Mar 2019 22:53:19 +0100 Subject: [PATCH] ActionLoopResumeTest --- .../actions/ActionLoopResumeTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.java new file mode 100644 index 0000000000..ed5181dc9a --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.java @@ -0,0 +1,67 @@ +package info.nightscout.androidaps.plugins.general.automation.actions; + +import com.google.common.base.Optional; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.AAPSMocker; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.queue.Callback; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, NSUpload.class}) +public class ActionLoopResumeTest { + ActionLoopResume actionLoopResume = new ActionLoopResume(); + + @Test + public void friendlyNameTest() { + Assert.assertEquals(R.string.resumeloop, actionLoopResume.friendlyName()); + } + + @Test + public void iconTest() { + Assert.assertEquals(Optional.of(R.drawable.ic_replay_24dp), actionLoopResume.icon()); + } + + @Test + public void doActionTest() { + LoopPlugin.getPlugin().suspendTo(DateUtil.now() + T.hours(1).msecs()); + actionLoopResume.doAction(new Callback() { + @Override + public void run() { + } + }); + Assert.assertEquals(false, LoopPlugin.getPlugin().isSuspended()); + // another call should keep it resumed + actionLoopResume.doAction(new Callback() { + @Override + public void run() { + } + }); + Assert.assertEquals(false, LoopPlugin.getPlugin().isSuspended()); + } + + @Before + public void prepareTest() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockBus(); + AAPSMocker.mockSP(); + AAPSMocker.mockConfigBuilder(); + AAPSMocker.mockNSUpload(); + AAPSMocker.mockCommandQueue(); + + } +}