From a590b1590a54975bc0c58ca975415a0e9a4d9d15 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 30 Jul 2018 20:23:48 +0200 Subject: [PATCH] fix tests, add crashlitycs to .ignore --- .gitignore | 4 +++- .../androidaps/interfaces/ConstraintTest.java | 12 +++++++++++- .../ConfigBuilder/ConfigBuilderPluginTest.java | 10 ++++++---- ...cket_APS_Basal_Set_Temporary_BasalTest.java | 18 +++++++++++++++++- .../comm/MsgSetAPSTempBasalStart_v2Test.java | 14 +++++++++++++- .../AbstractSensitivityPluginTest.java | 12 ++++++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7dc3c7a865..98b73cb7cb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ build/ app/src/main/jniLibs full/ debug/ -release/ \ No newline at end of file +release/ +app/com.crashlytics.settings.json +app/session_analytics.tap \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java index 23352a57f9..2a742efc65 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintTest.java @@ -4,17 +4,27 @@ import junit.framework.Assert; 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.utils.SP; + /** * Created by mike on 19.03.2018. */ @RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class}) public class ConstraintTest { @Test - public void doTests() throws Exception { + public void doTests() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); + Constraint b = new Constraint<>(true); Assert.assertEquals(Boolean.TRUE, b.value()); Assert.assertEquals("", b.getReasons()); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java index 59628a8dea..268faa5ab7 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java @@ -12,11 +12,12 @@ import org.powermock.modules.junit4.PowerMockRunner; import info.AAPSMocker; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.utils.SP; import static org.powermock.api.mockito.PowerMockito.mock; @RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class}) +@PrepareForTest({MainApp.class, SP.class}) public class ConfigBuilderPluginTest { @Test @@ -41,9 +42,10 @@ public class ConfigBuilderPluginTest { } @Before - public void prepareMock() throws Exception { - MainApp mainApp = mock(MainApp.class); - PowerMockito.mockStatic(MainApp.class); + public void prepareMock() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); AAPSMocker.prepareMockedBus(); } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.java index bbacbb485c..6831f889d7 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.java @@ -1,7 +1,18 @@ package info.nightscout.androidaps.plugins.PumpDanaRS.comm; +import android.content.Context; + 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.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.utils.SP; +import info.nightscout.utils.ToastUtils; import static org.junit.Assert.assertEquals; @@ -9,10 +20,15 @@ import static org.junit.Assert.assertEquals; * Created by mike on 20.11.2017. */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class}) public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest extends DanaRS_Packet_APS_Basal_Set_Temporary_Basal { @Test - public void runTest() throws Exception { + public void runTest() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); // under 100% should last 30 min setParams(0); assertEquals(0, temporaryBasalRatio); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/comm/MsgSetAPSTempBasalStart_v2Test.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/comm/MsgSetAPSTempBasalStart_v2Test.java index e36c5a7c24..d587363d60 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/comm/MsgSetAPSTempBasalStart_v2Test.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpdanaRv2/comm/MsgSetAPSTempBasalStart_v2Test.java @@ -2,9 +2,15 @@ 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.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_Basal_Set_Temporary_Basal; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2; +import info.nightscout.utils.SP; import static org.junit.Assert.assertEquals; @@ -12,10 +18,16 @@ import static org.junit.Assert.assertEquals; * Created by mike on 20.11.2017. */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class}) public class MsgSetAPSTempBasalStart_v2Test extends MsgSetAPSTempBasalStart_v2 { @Test - public void runTest() throws Exception { + public void runTest() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); + // under 100% should last 30 min setParams(0); assertEquals(0, intFromBuff(buffer, 0, 2)); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Sensitivity/AbstractSensitivityPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Sensitivity/AbstractSensitivityPluginTest.java index ec6c6e818f..e6d6caaf56 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/Sensitivity/AbstractSensitivityPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Sensitivity/AbstractSensitivityPluginTest.java @@ -1,13 +1,21 @@ package info.nightscout.androidaps.plugins.Sensitivity; 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.interfaces.PluginDescription; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.utils.SP; import static org.junit.Assert.assertEquals; +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class}) public class AbstractSensitivityPluginTest { private class SensitivityTestClass extends AbstractSensitivityPlugin { @@ -28,6 +36,10 @@ public class AbstractSensitivityPluginTest { @Test public void fillResultTest() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); + SensitivityTestClass sut = new SensitivityTestClass(); AutosensResult ar = sut.fillResult(1d, 1d, "1",