From 699413dd6f2ee4301ac7a88f1b3e63a929479bf1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 1 Apr 2021 00:37:15 +0200 Subject: [PATCH] fix tests --- .../plugins/general/smsCommunicator/Sms.kt | 1 - .../nightscout/androidaps/utils/TimeListEdit.java | 1 - .../data/defaultProfile/DefaultProfileTest.kt | 0 .../androidaps/interfaces/ConstraintsCheckerTest.kt | 2 +- .../androidaps/plugins/aps/loop/LoopPluginTest.kt | 12 +++++------- .../general/automation/elements/LabelWithElement.kt | 2 -- .../utils/extensions/DeviceStatusExtension.kt | 2 +- .../info/nightscout/androidaps/data/ProfileTest.kt | 3 --- .../androidaps/plugins/pump/danaR/DanaRPluginTest.kt | 4 +++- .../plugins/pump/danaRv2/DanaRv2PluginTest.kt | 4 +++- .../pump/medtronic/data/dto/BasalProfileUTest.java | 3 +-- 11 files changed, 14 insertions(+), 20 deletions(-) rename {core => app}/src/test/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileTest.kt (100%) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt index bab25dfe3e..5952a0da66 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator import android.telephony.SmsMessage -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.utils.DateUtil class Sms { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java index af6fd3e742..33a24e3244 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java @@ -95,7 +95,6 @@ public class TimeListEdit { LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); llp.setMargins(0, 5, 0, 5); textlabel.setLayoutParams(llp); - //textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground)); TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium); layout.addView(textlabel); diff --git a/core/src/test/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileTest.kt b/app/src/test/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileTest.kt similarity index 100% rename from core/src/test/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileTest.kt rename to app/src/test/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileTest.kt diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 73a23cdaa1..79894eba45 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -143,7 +143,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, repository) objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config(), uel) comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsInterface, sp, commandQueue, context, databaseHelper) - danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy) + danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync) danaRSPlugin = DanaRSPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsInterface, sp, commandQueue, profileFunction, nsUpload, context, uploadQueue, Config(), dateUtil, databaseHelper, pumpSync) openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsInterface, iobCobCalculator, hardLimits, profiler, sp, dateUtil, repository, glucoseStatusProvider) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt index f2cef5f7bf..721d4402c8 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt @@ -8,13 +8,10 @@ import info.nightscout.androidaps.Config import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.database.AppRepository -import info.nightscout.androidaps.interfaces.ActivePluginProvider -import info.nightscout.androidaps.interfaces.CommandQueueProvider -import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.interfaces.PumpDescription +import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin @@ -34,7 +31,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class) +@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class, RunningConfiguration::class) class LoopPluginTest : TestBase() { @Mock lateinit var sp: SP @@ -54,13 +51,14 @@ class LoopPluginTest : TestBase() { @Mock lateinit var notificationManager: NotificationManager @Mock lateinit var repository: AppRepository @Mock lateinit var dateUtil: DateUtil + @Mock lateinit var runningConfiguration: RunningConfiguration private lateinit var loopPlugin: LoopPlugin val injector = HasAndroidInjector { AndroidInjector { } } @Before fun prepareMock() { - loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, nsUpload, dateUtil, repository) + loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, nsUpload, dateUtil, repository, runningConfiguration) `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt index 4ea68104f3..adc29fdb1e 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt @@ -25,7 +25,6 @@ class LabelWithElement( textViewPre.text = textPre textViewPre.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) - //textViewPre.setWidth(MainApp.dpToPx(120)); textViewPre.setPadding(px, px, px, px) textViewPre.setTypeface(textViewPre.typeface, Typeface.BOLD) layout.addView(textViewPre) @@ -40,7 +39,6 @@ class LabelWithElement( textViewPost.text = textPost textViewPost.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) - //textViewPost.setWidth(MainApp.dpToPx(45)); textViewPost.setPadding(px, px, px, px) textViewPost.setTypeface(textViewPost.typeface, Typeface.BOLD) layout.addView(textViewPost) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/extensions/DeviceStatusExtension.kt b/core/src/main/java/info/nightscout/androidaps/utils/extensions/DeviceStatusExtension.kt index db61c992a9..97af8a73aa 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/extensions/DeviceStatusExtension.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/extensions/DeviceStatusExtension.kt @@ -37,7 +37,7 @@ fun buildDeviceStatus( version: String ): DeviceStatus? { val profile = profileFunction.getProfile() ?: return null - val profileName = profileFunction.getProfileName() ?: return null + val profileName = profileFunction.getProfileName() val lastRun = loopPlugin.lastRun var apsResult: JSONObject? = null diff --git a/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt b/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt index 38b85fef53..b5a0ecb3e1 100644 --- a/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt @@ -105,7 +105,6 @@ class ProfileTest : TestBaseWithProfile() { //Test basal profile below limit p = Profile(profileInjector, JSONObject(belowLimitValidProfile), 100, 0) p.isValid("Test") - //Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); // Test profile w/o units p = Profile(profileInjector, JSONObject(noUnitsValidProfile), 100, 0) @@ -142,9 +141,7 @@ class ProfileTest : TestBaseWithProfile() { // Test hour alignment testPumpPlugin.pumpDescription.is30minBasalRatesCapable = false - //((AAPSMocker.MockedBus) MainApp.bus()).notificationSent = false; p = Profile(profileInjector, JSONObject(notAlignedBasalValidProfile), 100, 0) p.isValid("Test") - //Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); } } \ No newline at end of file diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt index 834c549718..8c5daf0fa3 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert @@ -30,6 +31,7 @@ class DanaRPluginTest : TestBaseWithProfile() { @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var sp: SP @Mock lateinit var commandQueue: CommandQueueProvider + @Mock lateinit var pumpSync: PumpSync lateinit var danaPump: DanaPump @@ -46,7 +48,7 @@ class DanaRPluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") danaPump = DanaPump(aapsLogger, sp, injector) - danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy) + danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync) } @Test @Throws(Exception::class) diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt index 2e0cee2135..471071290b 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import org.junit.Before @@ -30,6 +31,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { @Mock lateinit var sp: info.nightscout.androidaps.utils.sharedPreferences.SP @Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage + @Mock lateinit var pumpSync: PumpSync lateinit var danaPump: DanaPump @@ -46,7 +48,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") danaPump = DanaPump(aapsLogger, sp, injector) - danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, danaPump, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, detailedBolusInfoStorage, dateUtil, fabricPrivacy) + danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, danaPump, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, detailedBolusInfoStorage, dateUtil, fabricPrivacy, pumpSync) } @Test diff --git a/medtronic/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfileUTest.java b/medtronic/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfileUTest.java index 8b2eaa3e7e..7564a9edc2 100644 --- a/medtronic/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfileUTest.java +++ b/medtronic/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfileUTest.java @@ -9,11 +9,10 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; * Created by andy on 6/16/18. */ //@RunWith(PowerMockRunner.class) -//@PrepareForTest({ MainApp.class, DatabaseHelper.class, DateUtil.class, SP.class }) +//@PrepareForTest({ DatabaseHelper.class, DateUtil.class, SP.class }) @Ignore public class BasalProfileUTest { /* - // MainApp mainApp = new MainApp(); @Before public void initMocking() {