diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtils.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtils.kt index 48ab521d87..3fe8b92453 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtils.kt @@ -113,18 +113,7 @@ class VersionCheckerUtils @Inject constructor() { } } - @Deprecated(replaceWith = ReplaceWith("numericVersionPart()"), message = "Will not work if RCs have another index number in it.") - fun String.versionStrip() = this.mapNotNull { - when (it) { - in '0'..'9' -> it - '.' -> it - else -> null - } - }.joinToString(separator = "") - private fun String.numericVersionPart(): String = - "(((\\d+)\\.)+(\\d+))(\\D(.*))?".toRegex().matchEntire(this)?.groupValues?.getOrNull(1) - ?: "" private fun String?.toNumberList() = this?.numericVersionPart().takeIf { !it.isNullOrBlank() }?.split(".")?.map { it.toInt() } @@ -138,4 +127,22 @@ class VersionCheckerUtils @Inject constructor() { private val CHECK_EVERY = TimeUnit.DAYS.toMillis(1) private val WARN_EVERY = TimeUnit.DAYS.toMillis(1) } -} \ No newline at end of file +} + +fun String.numericVersionPart(): String = + "(((\\d+)\\.)+(\\d+))(\\D(.*))?".toRegex().matchEntire(this)?.groupValues?.getOrNull(1) + ?: "" + +fun findVersion(file: String?): String? { + val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex() + return file?.lines()?.filter { regex.matches(it) }?.mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }?.firstOrNull() +} + +@Deprecated(replaceWith = ReplaceWith("numericVersionPart()"), message = "Will not work if RCs have another index number in it.") +fun String.versionStrip() = this.mapNotNull { + when (it) { + in '0'..'9' -> it + '.' -> it + else -> null + } +}.joinToString(separator = "") \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java index c7deb72879..ff4f296a8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java @@ -36,10 +36,10 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper; @DatabaseTable(tableName = Treatment.TABLE_TREATMENTS) public class Treatment implements DataPointWithLabelInterface, DbObjectBase { - @Inject DefaultValueHelper defaultValueHelper; - @Inject ResourceHelper resourceHelper; - @Inject ProfileFunction profileFunction; - @Inject ConfigBuilderPlugin configBuilderPlugin; + @Inject public DefaultValueHelper defaultValueHelper; + @Inject public ResourceHelper resourceHelper; + @Inject public ProfileFunction profileFunction; + @Inject public ConfigBuilderPlugin configBuilderPlugin; public static final String TABLE_TREATMENTS = "Treatments"; diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt index 6d4a37882a..f91b76875f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt @@ -1,15 +1,15 @@ package info.nightscout.androidaps.plugins.constraints.signatureVerifier +import org.junit.Assert.fail import org.junit.Test -import org.junit.Assert.* - class SignatureVerifierPluginTest { @Test fun singleCharUnMapTest() { val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε" - val unmapped = SignatureVerifierPlugin.getPlugin().singleCharUnMap(key) - assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped) + fail() // TODO fix test + //val unmapped = SignatureVerifierPlugin.getPlugin().singleCharUnMap(key) + // assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtilsKtTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtilsKtTest.kt index 7a3bbc65b2..fb1302af7e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtilsKtTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerUtilsKtTest.kt @@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.utils.SP import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert.assertEquals +import org.junit.Assert.fail import org.junit.Before import org.junit.Rule import org.junit.Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.java deleted file mode 100644 index 47ce6a1d02..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.java +++ /dev/null @@ -1,50 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers; - -import com.google.common.base.Optional; - -public class DummyTrigger extends Trigger { - private boolean result; - - public DummyTrigger() { - this.result = false; - } - - public DummyTrigger(boolean result) { - this.result = result; - } - - @Override - public boolean shouldRun() { - return result; - } - - @Override - public String toJSON() { return null; } - - @Override - Trigger fromJSON(String data) { - return null; - } - - @Override - public int friendlyName() { - return 0; - } - - @Override - public String friendlyDescription() { - return null; - } - - @Override - public Optional icon() { - return Optional.absent(); - } - - @Override - public void executed(long time) { - } - - @Override - public Trigger duplicate() { return new DummyTrigger(result); } -} diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.kt new file mode 100644 index 0000000000..fbf9213625 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.kt @@ -0,0 +1,36 @@ +package info.nightscout.androidaps.plugins.general.automation.triggers + +import com.google.common.base.Optional +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector + +class DummyTrigger(var result: Boolean) : Trigger(HasAndroidInjector { AndroidInjector { } }) { + + override fun shouldRun(): Boolean { + return result + } + + override fun toJSON(): String { + return "" + } + + override fun fromJSON(data: String): Trigger { + return DummyTrigger(result) + } + + override fun friendlyName(): Int { + return 0 + } + + override fun friendlyDescription(): String { + return " " + } + + override fun icon(): Optional { + return Optional.absent() + } + + override fun duplicate(): Trigger { + return DummyTrigger(result) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt index 6641e62bc5..fa6b53aee1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt @@ -1,13 +1,15 @@ package info.nightscout.androidaps.plugins.insulin +import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.data.Iob import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA import info.nightscout.androidaps.plugins.treatments.Treatment +import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before @@ -16,7 +18,6 @@ import org.junit.Test import org.mockito.Mock import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule -import org.powermock.core.classloader.annotations.PrepareForTest class InsulinOrefBasePluginTest { @@ -53,12 +54,23 @@ class InsulinOrefBasePluginTest { lateinit var sut: InsulinBaseTest + @Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var aapsLogger: AAPSLogger + @Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin - @Mock lateinit var injector: HasAndroidInjector + var treatmentInjector: HasAndroidInjector = HasAndroidInjector { + AndroidInjector { + if (it is Treatment) { + it.defaultValueHelper = defaultValueHelper + it.resourceHelper = resourceHelper + it.profileFunction = profileFunction + it.configBuilderPlugin = configBuilderPlugin + } + } + } @Before fun setUp() { @@ -77,7 +89,7 @@ class InsulinOrefBasePluginTest { @Test fun testIobCalcForTreatment() { - val treatment = Treatment(injector) + val treatment = Treatment(treatmentInjector) //TODO: this should be a separate sut. I'd prefer a separate class. val expected = Iob() Assert.assertEquals(expected, sut.iobCalcForTreatment(treatment, 0, 0.0)) testPeak = 30 diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt index 5a328f6f16..d82d124f1b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt @@ -41,7 +41,11 @@ class InsulinOrefFreePeakPluginTest { @Before fun setup() { - sut = InsulinOrefFreePeakPlugin(sp, resourceHelper, profileFunction, rxBus, aapsLogger) + sut = InsulinOrefFreePeakPlugin(sp = sp, + resourceHelper = resourceHelper, + rxBus = rxBus, + profileFunction = profileFunction, + aapsLogger = aapsLogger) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/source/GlimpPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/source/GlimpPluginTest.kt index e4387b024c..a0ba8ff70e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/source/GlimpPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/source/GlimpPluginTest.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.source import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Rule @@ -17,9 +18,11 @@ class GlimpPluginTest { @Mock lateinit var aapsLogger: AAPSLogger + @Mock lateinit var resourceHelper: ResourceHelper + @Before fun setup() { - glimpPlugin = GlimpPlugin(aapsLogger) + glimpPlugin = GlimpPlugin(resourceHelper, aapsLogger) } @Test fun advancedFilteringSupported() {