This commit is contained in:
Milos Kozak 2022-11-21 11:48:26 +01:00
parent 1cbfae2dc1
commit 97cd02d021
8 changed files with 22 additions and 81 deletions

View file

@ -11,14 +11,12 @@ import info.nightscout.androidaps.implementations.ActivityNamesImpl
import info.nightscout.androidaps.interfaces.stats.DexcomTirCalculator
import info.nightscout.androidaps.interfaces.stats.TddCalculator
import info.nightscout.androidaps.interfaces.stats.TirCalculator
import info.nightscout.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImpl
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefsImpl
import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.utils.androidNotification.NotificationHolderImpl
import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl
import info.nightscout.androidaps.utils.buildHelper.ConfigImpl
import info.nightscout.androidaps.utils.resources.IconsProviderImplementation
@ -30,6 +28,7 @@ import info.nightscout.implementation.CarbTimerImpl
import info.nightscout.implementation.LocalAlertUtilsImpl
import info.nightscout.implementation.TrendCalculatorImpl
import info.nightscout.implementation.XDripBroadcastImpl
import info.nightscout.implementation.androidNotification.NotificationHolderImpl
import info.nightscout.implementation.constraints.ConstraintsImpl
import info.nightscout.implementation.pump.PumpSyncImplementation
import info.nightscout.implementation.queue.CommandQueueImplementation
@ -63,6 +62,7 @@ import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.interfaces.ui.IconsProvider
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.interfaces.utils.TrendCalculator
import info.nightscout.plugins.aps.loop.LoopPlugin
import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin
import info.nightscout.plugins.sync.nsclient.DataSyncSelectorImplementation
import info.nightscout.plugins.sync.nsclient.data.ProcessedDeviceStatusData

View file

@ -1,20 +0,0 @@
package info.nightscout.androidaps.utils
import java.util.regex.Pattern
object PercentageSplitter {
// Matches "Profile name (200%,-2h)", "Profile name (50%)
private val splitPattern = Pattern.compile("(.+)\\(\\d+%(,-?\\d+h)?\\)")
/**
* Removes the suffix for percentage and timeshift from a profile name. This is the inverse of what
* [ProfileSwitch.getCustomizedName()] does.
* Since the customized name is used for the PS upload to NS, this is needed get the original profile name
* when retrieving the PS from NS again.
*/
fun pureName(name: String): String {
val percentageMatch = splitPattern.matcher(name)
return if (percentageMatch.find()) (percentageMatch.group(1) as String).trim { it <= ' ' } else name
}
}

View file

@ -1,17 +0,0 @@
package info.nightscout.androidaps.utils
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View file

@ -1,23 +0,0 @@
package info.nightscout.androidaps.utils
import info.nightscout.androidaps.utils.PercentageSplitter.pureName
import org.junit.Assert
import org.junit.Test
/**
* Created by mike on 22.12.2017.
*/
class PercentageSplitterTest {
@Test fun pureNameTestPercentageOnly() {
Assert.assertEquals("Fiasp", pureName("Fiasp(101%)"))
}
@Test fun pureNameTestPercentageAndPositiveTimeShift() {
Assert.assertEquals("Fiasp", pureName("Fiasp (101%,2h)"))
}
@Test fun pureNameTestPercentageAndNegtiveTimeShift() {
Assert.assertEquals("Fiasp", pureName("Fiasp (50%,-2h)"))
}
}

View file

@ -24,7 +24,7 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
val lastData = 0L
val baseBasal = 0.0
override val pumpDescription = PumpDescription()
override var pumpDescription = PumpDescription()
override fun isInitialized(): Boolean = true
override fun isSuspended(): Boolean = false

View file

@ -1,12 +1,12 @@
package info.nightscout.androidaps.utils.wizard
package info.nightscout.core.wizard
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStoreObject
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.core.wizard.BolusWizard
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.constraints.Constraint
@ -18,7 +18,6 @@ import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -41,7 +40,6 @@ class BolusWizardTest : TestBase() {
@Mock lateinit var commandQueue: CommandQueue
@Mock lateinit var loop: Loop
@Mock lateinit var iobCobCalculator: IobCobCalculator
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Mock lateinit var dateUtil: DateUtil
@Mock lateinit var autosensDataStore: AutosensDataStoreObject
@ -63,6 +61,8 @@ class BolusWizardTest : TestBase() {
}
}
val testPumpPlugin = TestPumpPlugin(injector)
@Suppress("SameParameterValue")
private fun setupProfile(targetLow: Double, targetHigh: Double, insulinSensitivityFactor: Double, insulinToCarbRatio: Double): Profile {
val profile = Mockito.mock(Profile::class.java)
@ -74,10 +74,10 @@ class BolusWizardTest : TestBase() {
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
`when`(iobCobCalculator.calculateIobFromBolus()).thenReturn(IobTotal(System.currentTimeMillis()))
`when`(iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(System.currentTimeMillis()))
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
val pumpDescription = PumpDescription()
pumpDescription.bolusStep = pumpBolusStep
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
testPumpPlugin.pumpDescription = PumpDescription().also {
it.bolusStep = pumpBolusStep
}
`when`(iobCobCalculator.ads).thenReturn(autosensDataStore)
Mockito.doAnswer { invocation: InvocationOnMock ->

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.utils.androidNotification
package info.nightscout.implementation.androidNotification
import android.app.Notification
import android.app.NotificationChannel
@ -8,9 +8,9 @@ import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.TaskStackBuilder
import info.nightscout.androidaps.MainActivity
import info.nightscout.core.main.R
import info.nightscout.interfaces.NotificationHolder
import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.interfaces.ui.IconsProvider
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
@ -18,9 +18,10 @@ import javax.inject.Singleton
@Singleton
class NotificationHolderImpl @Inject constructor(
val rh: ResourceHelper,
val context: Context,
val iconsProvider: IconsProvider
private val rh: ResourceHelper,
private val context: Context,
private val iconsProvider: IconsProvider,
private val activityNames: ActivityNames
) : NotificationHolder {
override val channelID = "AndroidAPS-Ongoing"
@ -33,8 +34,8 @@ class NotificationHolderImpl @Inject constructor(
get() = _notification ?: placeholderNotification()
override fun openAppIntent(context: Context): PendingIntent? = TaskStackBuilder.create(context).run {
addParentStack(MainActivity::class.java)
addNextIntent(Intent(context, MainActivity::class.java))
addParentStack(activityNames.mainActivity)
addNextIntent(Intent(context, activityNames.mainActivity))
getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
}

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.utils
package info.nightscout.plugins.constraints.objectives
import info.nightscout.androidaps.TestBase
import info.nightscout.plugins.constraints.objectives.SntpClient
import info.nightscout.shared.utils.DateUtil
import org.junit.Assert
import org.junit.Test
import org.mockito.Mock
import kotlin.math.abs
class SntpClientTest : TestBase() {
@Mock lateinit var dateUtil: DateUtil
@ -24,7 +24,7 @@ class SntpClientTest : TestBase() {
SntpClient(aapsLogger, dateUtil).doNtpTime(object : SntpClient.Callback() {
override fun run() {
Assert.assertTrue(success)
Assert.assertTrue(Math.abs(time - System.currentTimeMillis()) < 60000)
Assert.assertTrue(abs(time - System.currentTimeMillis()) < 60000)
}
})
}