diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index ee87420641..f4ffc33af5 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentService; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; @@ -176,8 +177,10 @@ public class AAPSMocker { public static DanaRPlugin mockDanaRPlugin() { PowerMockito.mockStatic(DanaRPlugin.class); DanaRPlugin danaRPlugin = mock(DanaRPlugin.class); + DanaRv2Plugin danaRv2Plugin = mock(DanaRv2Plugin.class); DanaRKoreanPlugin danaRKoreanPlugin = mock(DanaRKoreanPlugin.class); when(MainApp.getSpecificPlugin(DanaRPlugin.class)).thenReturn(danaRPlugin); + when(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).thenReturn(danaRv2Plugin); when(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).thenReturn(danaRKoreanPlugin); return danaRPlugin; } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/DanaRv2PluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/DanaRv2PluginTest.java new file mode 100644 index 0000000000..140b0165bd --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/DanaRv2PluginTest.java @@ -0,0 +1,82 @@ +package info.nightscout.androidaps.plugins.PumpdanaRv2; + +import android.content.Context; + +import junit.framework.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.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; +import info.nightscout.utils.SP; +import info.nightscout.utils.ToastUtils; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +/** + * Created by Rumen on 01.08.2018 + */ + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, SP.class}) +public class DanaRv2PluginTest { + DanaRv2Plugin danaRv2Plugin; + + @Test + public void getPlugin() { + danaRv2Plugin.getPlugin(); + } + + @Test + public void basalRateShouldBeLimited() throws Exception { + danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true); + danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true); + DanaRPump.getInstance().maxBasal = 0.8d; + + Constraint c = new Constraint<>(Constants.REALLYHIGHBASALRATE); + danaRv2Plugin.applyBasalConstraints(c, AAPSMocker.getValidProfile()); + Assert.assertEquals(0.8d, c.value()); + Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getReasons()); + Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons()); + } + + @Test + public void percentBasalRateShouldBeLimited() throws Exception { + danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true); + danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true); + DanaRPump.getInstance().maxBasal = 0.8d; + + Constraint c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE); + danaRv2Plugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile()); + Assert.assertEquals((Integer) 200, c.value()); + Assert.assertEquals("DanaRv2: Limiting percent rate to 200% because of pump limit", c.getReasons()); + Assert.assertEquals("DanaRv2: Limiting percent rate to 200% because of pump limit", c.getMostLimitedReasons()); + } + + @Before + public void prepareMocks() throws Exception { + AAPSMocker.mockMainApp(); + AAPSMocker.mockConfigBuilder(); + AAPSMocker.mockBus(); + AAPSMocker.mockStrings(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); + AAPSMocker.mockCommandQueue(); + +// when(SP.getString(R.string.key_danars_address, "")).thenReturn(""); + + danaRv2Plugin = DanaRv2Plugin.getPlugin(); + } +} diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/comm/MessageHashTable_v2Test.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/comm/MessageHashTable_v2Test.java new file mode 100644 index 0000000000..63e3af0fa4 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/comm/MessageHashTable_v2Test.java @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.plugins.PumpdanaRv2.comm; + +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.logging.L; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable_v2; +import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2; +import info.nightscout.utils.SP; + +import static org.junit.Assert.*; +/** + * Created by Rumen Georgiev on 30.10.2018. + */ + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class, L.class}) +public class MessageHashTable_v2Test { + @Test + public void runTest() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); + AAPSMocker.mockL(); + AAPSMocker.mockBus(); + + MessageHashTable_v2 packet = new MessageHashTable_v2(); + + MessageBase forTesting = new MsgStatusAPS_v2(); + MessageBase testPacket = MessageHashTable_v2.findMessage(forTesting.getCommand()); + assertEquals(0xE001, testPacket.getCommand()); + // try putting another command + MessageBase testMessage = new MessageBase(); + testMessage.SetCommand(0xE005); + packet.put(testMessage); + assertEquals(0xE005, packet.findMessage(0xE005).getCommand()); + } + + byte[] createArray(int length, byte fillWith){ + byte[] ret = new byte[length]; + for(int i = 0; i