migrate to junit5

This commit is contained in:
Milos Kozak 2022-11-29 15:03:25 +01:00
parent bb6841ecf2
commit 7de42fe282
356 changed files with 849 additions and 901 deletions

View file

@ -1,7 +1,7 @@
package info.nightscout.shared package info.nightscout.shared
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
class SafeParseTest { class SafeParseTest {

View file

@ -3,24 +3,22 @@ package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Rule import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.MockitoRule import org.mockito.junit.jupiter.MockitoSettings
import java.util.* import org.mockito.quality.Strictness
import java.util.Locale
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase { open class TestBase {
val aapsLogger = AAPSLoggerTest() val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
// Add a JUnit rule that will setup the @Mock annotated vars and log. @BeforeEach
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
@Before
fun setupLocale() { fun setupLocale() {
Locale.setDefault(Locale.ENGLISH) Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true") System.setProperty("disableFirebase", "true")

View file

@ -18,7 +18,7 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.mockito.ArgumentMatchers.anyDouble import org.mockito.ArgumentMatchers.anyDouble
import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
@ -49,7 +49,7 @@ open class TestBaseWithProfile : TestBase() {
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@Before @BeforeEach
fun prepareMock() { fun prepareMock() {
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +

View file

@ -11,8 +11,8 @@ import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.json.JSONArray import org.json.JSONArray
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -47,7 +47,7 @@ class QuickWizardTest : TestBase() {
private lateinit var quickWizard: QuickWizard private lateinit var quickWizard: QuickWizard
@Before @BeforeEach
fun mock() { fun mock() {
`when`(sp.getString(R.string.key_quickwizard, "[]")).thenReturn("[]") `when`(sp.getString(R.string.key_quickwizard, "[]")).thenReturn("[]")

View file

@ -10,8 +10,8 @@ import info.nightscout.androidaps.implementations.ConfigImpl
import info.nightscout.androidaps.insight.database.InsightDatabase import info.nightscout.androidaps.insight.database.InsightDatabase
import info.nightscout.androidaps.insight.database.InsightDatabaseDao import info.nightscout.androidaps.insight.database.InsightDatabaseDao
import info.nightscout.androidaps.insight.database.InsightDbHelper import info.nightscout.androidaps.insight.database.InsightDbHelper
import info.nightscout.core.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
import info.nightscout.core.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.implementation.constraints.ConstraintsImpl import info.nightscout.implementation.constraints.ConstraintsImpl
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
@ -45,8 +45,8 @@ import info.nightscout.pump.dana.DanaPump
import info.nightscout.pump.dana.database.DanaHistoryDatabase import info.nightscout.pump.dana.database.DanaHistoryDatabase
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -99,7 +99,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
} }
} }
@Before @BeforeEach
fun prepare() { fun prepare() {
`when`(rh.gs(R.string.closed_loop_disabled_on_dev_branch)).thenReturn("Running dev version. Closed loop is disabled.") `when`(rh.gs(R.string.closed_loop_disabled_on_dev_branch)).thenReturn("Running dev version. Closed loop is disabled.")
`when`(rh.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences") `when`(rh.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences")

View file

@ -6,30 +6,30 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.configBuilder.RunningConfiguration
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.pump.defs.PumpDescription import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.plugins.aps.loop.LoopFragment import info.nightscout.plugins.aps.loop.LoopFragment
import info.nightscout.plugins.aps.loop.LoopPlugin import info.nightscout.plugins.aps.loop.LoopPlugin
import info.nightscout.interfaces.configBuilder.RunningConfiguration
import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -58,7 +58,7 @@ class LoopPluginTest : TestBase() {
private lateinit var loopPlugin: LoopPlugin private lateinit var loopPlugin: LoopPlugin
val injector = HasAndroidInjector { AndroidInjector { } } val injector = HasAndroidInjector { AndroidInjector { } }
@Before fun prepareMock() { @BeforeEach fun prepareMock() {
loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, config, loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, config,
constraintChecker, rh, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, uel, constraintChecker, rh, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, uel,

View file

@ -3,15 +3,15 @@ package info.nightscout.androidaps.plugins.configBuilder
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.configuration.configBuilder.ConfigBuilderPlugin
import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.configuration.configBuilder.ConfigBuilderPlugin
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
class ConfigBuilderPluginTest : TestBase() { class ConfigBuilderPluginTest : TestBase() {
@ -31,7 +31,7 @@ class ConfigBuilderPluginTest : TestBase() {
} }
@Before @BeforeEach
fun prepareMock() { fun prepareMock() {
configBuilderPlugin = ConfigBuilderPlugin(injector, aapsLogger, rh, sp, RxBus(aapsSchedulers, aapsLogger), activePlugin, uel, pumpSync) configBuilderPlugin = ConfigBuilderPlugin(injector, aapsLogger, rh, sp, RxBus(aapsSchedulers, aapsLogger), activePlugin, uel, pumpSync)
} }

View file

@ -11,8 +11,8 @@ import info.nightscout.interfaces.nsclient.NSSettingsStatus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import java.io.File import java.io.File
@ -30,7 +30,7 @@ class MaintenancePluginTest : TestBase() {
private lateinit var sut: MaintenancePlugin private lateinit var sut: MaintenancePlugin
@Before @BeforeEach
fun mock() { fun mock() {
sut = MaintenancePlugin(injector, context, rh, sp, nsSettingsStatus, aapsLogger, config, fileListProvider, loggerUtils) sut = MaintenancePlugin(injector, context, rh, sp, nsSettingsStatus, aapsLogger, config, fileListProvider, loggerUtils)
`when`(loggerUtils.suffix).thenReturn(".log.zip") `when`(loggerUtils.suffix).thenReturn(".log.zip")

View file

@ -22,8 +22,8 @@ import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.plugins.source.GlimpPlugin import info.nightscout.plugins.source.GlimpPlugin
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -46,7 +46,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
private val injector = HasAndroidInjector { AndroidInjector { } } private val injector = HasAndroidInjector { AndroidInjector { } }
private val pumpDescription = PumpDescription() private val pumpDescription = PumpDescription()
@Before @BeforeEach
fun prepare() { fun prepare() {
`when`(rh.gs(R.string.hardlimit)).thenReturn("hard limit") `when`(rh.gs(R.string.hardlimit)).thenReturn("hard limit")
`when`(rh.gs(R.string.itmustbepositivevalue)).thenReturn("it must be positive value") `when`(rh.gs(R.string.itmustbepositivevalue)).thenReturn("it must be positive value")

View file

@ -13,7 +13,7 @@ import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
class AbstractSensitivityPluginTest : TestBase() { class AbstractSensitivityPluginTest : TestBase() {

View file

@ -11,8 +11,8 @@ import info.nightscout.plugins.extensions.toText
import info.nightscout.plugins.sync.nsShared.extensions.log import info.nightscout.plugins.sync.nsShared.extensions.log
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert import org.skyscreamer.jsonassert.JSONAssert
@ -26,7 +26,7 @@ class PumpEnactResultTest : TestBaseWithProfile() {
} }
} }
@Before @BeforeEach
fun mock() { fun mock() {
`when`(rh.gs(R.string.success)).thenReturn("Success") `when`(rh.gs(R.string.success)).thenReturn("Success")
`when`(rh.gs(R.string.enacted)).thenReturn("Enacted") `when`(rh.gs(R.string.enacted)).thenReturn("Enacted")

View file

@ -32,14 +32,15 @@ buildscript {
swipe_version = '1.1.0' swipe_version = '1.1.0'
junit_version = '4.13.2' junit_version = '4.13.2'
mockito_version = '4.4.0' junit_jupiter_version = '5.7.0'
mockito_version = '4.6.1'
dexmaker_version = '1.2' dexmaker_version = '1.2'
retrofit2_version = '2.9.0' retrofit2_version = '2.9.0'
okhttp3_version = '4.10.0' okhttp3_version = '4.10.0'
byteBuddy_version = '1.12.8' byteBuddy_version = '1.12.8'
androidx_junit_version = '1.1.3' androidx_junit_version = '1.1.4'
androidx_rules_version = '1.4.0' androidx_rules_version = '1.5.0'
rxandroidble_version = '1.12.1' rxandroidble_version = '1.12.1'
replayshare_version = '2.2.0' replayshare_version = '2.2.0'

View file

@ -1,6 +1,7 @@
package info.nightscout.core.iob.iobCobCalculator package info.nightscout.core.iob.iobCobCalculator
import dagger.Reusable import dagger.Reusable
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.core.iob.asRounded import info.nightscout.core.iob.asRounded
import info.nightscout.core.iob.log import info.nightscout.core.iob.log
import info.nightscout.interfaces.iob.GlucoseStatus import info.nightscout.interfaces.iob.GlucoseStatus
@ -12,6 +13,7 @@ import javax.inject.Inject
import kotlin.math.roundToLong import kotlin.math.roundToLong
@Reusable @Reusable
@OpenForTesting
class GlucoseStatusProvider @Inject constructor( class GlucoseStatusProvider @Inject constructor(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private val iobCobCalculator: IobCobCalculator, private val iobCobCalculator: IobCobCalculator,

View file

@ -4,23 +4,21 @@ import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.MockitoRule import org.mockito.junit.jupiter.MockitoSettings
import java.util.* import org.mockito.quality.Strictness
import java.util.Locale
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase { open class TestBase {
val aapsLogger = AAPSLoggerTest() val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
// Add a JUnit rule that will setup the @Mock annotated vars and log.
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
@Before @Before
fun setupLocale() { fun setupLocale() {
Locale.setDefault(Locale.ENGLISH) Locale.setDefault(Locale.ENGLISH)

View file

@ -17,7 +17,7 @@ import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -57,7 +57,7 @@ open class TestBaseWithProfile : TestBase() {
lateinit var invalidProfile: Profile lateinit var invalidProfile: Profile
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@Before @BeforeEach
fun prepareMock() { fun prepareMock() {
invalidProfileJSON = "{\"dia\":\"1\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + invalidProfileJSON = "{\"dia\":\"1\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +

View file

@ -3,8 +3,8 @@ package info.nightscout.androidaps.data
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
/** /**
* Created by mike on 19.03.2018. * Created by mike on 19.03.2018.
@ -49,7 +49,7 @@ class ConstraintTest : TestBase() {
Assert.assertEquals(10.0, d.originalValue(), 0.01) Assert.assertEquals(10.0, d.originalValue(), 0.01)
} }
@Before @BeforeEach
fun prepareMock() { fun prepareMock() {
} }
} }

View file

@ -9,7 +9,7 @@ import info.nightscout.database.entities.TherapyEvent
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import org.apache.commons.lang3.builder.EqualsBuilder import org.apache.commons.lang3.builder.EqualsBuilder
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
class DetailedBolusInfoTest : TestBase() { class DetailedBolusInfoTest : TestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.data
import info.nightscout.interfaces.iob.Iob import info.nightscout.interfaces.iob.Iob
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class IobTest { class IobTest {

View file

@ -11,8 +11,8 @@ import info.nightscout.core.iob.round
import info.nightscout.interfaces.iob.IobTotal import info.nightscout.interfaces.iob.IobTotal
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -23,7 +23,7 @@ class IobTotalTest : TestBase() {
private lateinit var dateUtil: DateUtil private lateinit var dateUtil: DateUtil
private var now = 0L private var now = 0L
@Before @BeforeEach
fun prepare() { fun prepare() {
dateUtil = DateUtil(context) dateUtil = DateUtil(context)
now = dateUtil.now() now = dateUtil.now()

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.data
import info.nightscout.interfaces.iob.MealData import info.nightscout.interfaces.iob.MealData
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class MealDataTest { class MealDataTest {

View file

@ -20,8 +20,8 @@ import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.anyInt import org.mockito.Mockito.anyInt
import org.mockito.Mockito.anyString import org.mockito.Mockito.anyString
@ -59,7 +59,7 @@ class ProfileTest : TestBase() {
//String profileStore = "{\"defaultProfile\":\"Default\",\"store\":{\"Default\":" + validProfile + "}}"; //String profileStore = "{\"defaultProfile\":\"Default\",\"store\":{\"Default\":" + validProfile + "}}";
@Before @BeforeEach
fun prepare() { fun prepare() {
testPumpPlugin = TestPumpPlugin { AndroidInjector { } } testPumpPlugin = TestPumpPlugin { AndroidInjector { } }
dateUtil = DateUtil(context) dateUtil = DateUtil(context)
@ -159,7 +159,7 @@ class ProfileTest : TestBase() {
00:00 6.2 mmol/U 00:00 6.2 mmol/U
01:00 6.0 mmol/U 01:00 6.0 mmol/U
03:00 6.2 mmol/U 03:00 6.2 mmol/U
""".trimIndent(), p.getIsfList(rh, dateUtil) """.trimIndent(), p.getIsfList(rh, dateUtil).replace(',', '.')
) )
// Test hour alignment // Test hour alignment

View file

@ -12,7 +12,7 @@ import info.nightscout.database.entities.data.checkSanity
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class BlockExtensionKtTest { class BlockExtensionKtTest {

View file

@ -4,7 +4,7 @@ import androidx.fragment.app.Fragment
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class PluginDescriptionTest { class PluginDescriptionTest {

View file

@ -3,7 +3,7 @@ package info.nightscout.androidaps.interfaces
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.interfaces.profile.PureProfile import info.nightscout.interfaces.profile.PureProfile
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
internal class ProfileStoreTest : TestBaseWithProfile() { internal class ProfileStoreTest : TestBaseWithProfile() {

View file

@ -5,7 +5,7 @@ import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.pump.defs.PumpTempBasalType import info.nightscout.interfaces.pump.defs.PumpTempBasalType
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class PumpDescriptionTest { class PumpDescriptionTest {

View file

@ -12,8 +12,8 @@ import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.utils.JsonHelper.safeGetDouble import info.nightscout.interfaces.utils.JsonHelper.safeGetDouble
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -329,7 +329,7 @@ class APSResultTest : TestBaseWithProfile() {
Assert.assertEquals(false, apsResult.json()?.has("rate")) Assert.assertEquals(false, apsResult.json()?.has("rate"))
} }
@Before @BeforeEach
fun prepare() { fun prepare() {
`when`(constraints.isClosedLoopAllowed(anyObject())).thenReturn(closedLoopEnabled) `when`(constraints.isClosedLoopAllowed(anyObject())).thenReturn(closedLoopEnabled)
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin) `when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)

View file

@ -1,8 +1,8 @@
package info.nightscout.androidaps.plugins.iob.iobCalculator package info.nightscout.androidaps.plugins.iob.iobCalculator
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.core.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.core.iob.asRounded import info.nightscout.core.iob.asRounded
import info.nightscout.core.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.core.iob.log import info.nightscout.core.iob.log
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.aps.AutosensDataStore import info.nightscout.interfaces.aps.AutosensDataStore
@ -11,8 +11,8 @@ import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -26,7 +26,7 @@ class GlucoseStatusTest : TestBase() {
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculator @Mock lateinit var iobCobCalculatorPlugin: IobCobCalculator
@Mock lateinit var autosensDataStore: AutosensDataStore @Mock lateinit var autosensDataStore: AutosensDataStore
@Before @BeforeEach
fun prepare() { fun prepare() {
`when`(iobCobCalculatorPlugin.ads).thenReturn(autosensDataStore) `when`(iobCobCalculatorPlugin.ads).thenReturn(autosensDataStore)
} }
@ -103,7 +103,7 @@ class GlucoseStatusTest : TestBase() {
Assert.assertEquals(1514766900000L, glucoseStatus.date) // latest date Assert.assertEquals(1514766900000L, glucoseStatus.date) // latest date
} }
@Before @BeforeEach
fun initMocking() { fun initMocking() {
`when`(dateUtil.now()).thenReturn(1514766900000L + T.mins(1).msecs()) `when`(dateUtil.now()).thenReturn(1514766900000L + T.mins(1).msecs())
`when`(iobCobCalculatorPlugin.ads).thenReturn(autosensDataStore) `when`(iobCobCalculatorPlugin.ads).thenReturn(autosensDataStore)

View file

@ -7,8 +7,8 @@ import info.nightscout.database.entities.GlucoseValue
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
class AutosensDataStoreTest : TestBase() { class AutosensDataStoreTest : TestBase() {
@ -19,7 +19,7 @@ class AutosensDataStoreTest : TestBase() {
private val autosensDataStore = AutosensDataStoreObject() private val autosensDataStore = AutosensDataStoreObject()
@Before @BeforeEach
fun mock() { fun mock() {
dateUtil = DateUtil(context) dateUtil = DateUtil(context)
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.pump.common.utils; package info.nightscout.androidaps.pump.common.utils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.jupiter.api.Test;
import info.nightscout.core.utils.DateTimeUtil; import info.nightscout.core.utils.DateTimeUtil;

View file

@ -6,7 +6,7 @@ import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.not import org.hamcrest.CoreMatchers.not
import org.junit.Assert import org.junit.Assert
import org.junit.Assume.assumeThat import org.junit.Assume.assumeThat
import org.junit.Test import org.junit.jupiter.api.Test
// https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size // https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size
// https://stackoverflow.com/questions/47708951/can-aes-256-work-on-android-devices-with-api-level-26 // https://stackoverflow.com/questions/47708951/can-aes-256-work-on-android-devices-with-api-level-26

View file

@ -7,10 +7,10 @@ import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import java.util.* import java.util.Date
class DateUtilTest : TestBase() { class DateUtilTest : TestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.utils
import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.interfaces.utils.DecimalFormatter
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class DecimalFormatterTest { class DecimalFormatterTest {

View file

@ -3,7 +3,7 @@ package info.nightscout.androidaps.utils
import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.interfaces.utils.JsonHelper
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
class JsonHelperTest { class JsonHelperTest {

View file

@ -2,8 +2,8 @@ package info.nightscout.androidaps.utils
import info.nightscout.interfaces.utils.MidnightTime import info.nightscout.interfaces.utils.MidnightTime
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import java.util.* import java.util.Calendar
class MidnightTimeTest { class MidnightTimeTest {

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.utils
import info.nightscout.interfaces.utils.Round import info.nightscout.interfaces.utils.Round
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class RoundTest { class RoundTest {

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.utils
import info.nightscout.core.utils.receivers.StringUtils import info.nightscout.core.utils.receivers.StringUtils
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class StringUtilsTest { class StringUtilsTest {

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.utils
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import kotlin.math.abs import kotlin.math.abs
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")

View file

@ -22,7 +22,7 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`

View file

@ -1,14 +1,17 @@
dependencies { dependencies {
testImplementation "junit:junit:$junit_version" //testImplementation "junit:junit:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter:$junit_jupiter_version"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
testImplementation "org.json:json:$json_version" testImplementation "org.json:json:$json_version"
testImplementation "org.mockito:mockito-core:$mockito_version" testImplementation "org.mockito:mockito-junit-jupiter:$mockito_version"
testImplementation "org.mockito:mockito-inline:$mockito_version" testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
//testImplementation "org.mockito:mockito-inline:$mockito_version"
testImplementation "joda-time:joda-time:$jodatime_version" testImplementation "joda-time:joda-time:$jodatime_version"
testImplementation "com.google.truth:truth:1.1.3" testImplementation "com.google.truth:truth:1.1.3"
testImplementation "org.skyscreamer:jsonassert:1.5.0" testImplementation "org.skyscreamer:jsonassert:1.5.0"
testImplementation "org.hamcrest:hamcrest-all:1.3" testImplementation "org.hamcrest:hamcrest-all:1.3"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
androidTestImplementation "androidx.test.ext:junit-ktx:$androidx_junit_version" androidTestImplementation "androidx.test.ext:junit-ktx:$androidx_junit_version"
androidTestImplementation "androidx.test:rules:$androidx_rules_version" androidTestImplementation "androidx.test:rules:$androidx_rules_version"
@ -20,6 +23,7 @@ tasks.matching { it instanceof Test }.all {
// use to display stdout in travis // use to display stdout in travis
testLogging.events = ["failed", "skipped", "started", "standard_out"] testLogging.events = ["failed", "skipped", "started", "standard_out"]
testLogging.exceptionFormat = "full" testLogging.exceptionFormat = "full"
useJUnitPlatform()
} }
android { android {

View file

@ -71,7 +71,7 @@ abstract class PluginBase(
* So far plugin can have it's main type + ConstraintInterface * So far plugin can have it's main type + ConstraintInterface
* ConstraintInterface is enabled if main plugin is enabled * ConstraintInterface is enabled if main plugin is enabled
*/ */
fun setPluginEnabled(type: PluginType, newState: Boolean) { open fun setPluginEnabled(type: PluginType, newState: Boolean) {
if (type == pluginDescription.mainType) { if (type == pluginDescription.mainType) {
if (newState) { // enabling plugin if (newState) { // enabling plugin
if (state != State.ENABLED) { if (state != State.ENABLED) {
@ -91,7 +91,7 @@ abstract class PluginBase(
} }
} }
fun setFragmentVisible(type: PluginType, fragmentVisible: Boolean) { open fun setFragmentVisible(type: PluginType, fragmentVisible: Boolean) {
if (type == pluginDescription.mainType) { if (type == pluginDescription.mainType) {
this.fragmentVisible = fragmentVisible && specialEnableCondition() this.fragmentVisible = fragmentVisible && specialEnableCondition()
} }

View file

@ -3,11 +3,13 @@ package info.nightscout.interfaces.utils
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.provider.AlarmClock import android.provider.AlarmClock
import info.nightscout.androidaps.annotations.OpenForTesting
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@OpenForTesting
@Singleton @Singleton
class TimerUtil @Inject constructor( open class TimerUtil @Inject constructor(
private val context: Context private val context: Context
) { ) {

View file

@ -1,23 +0,0 @@
package info.nightscout.core.validators
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("info.nightscout.core.validators.test", appContext.packageName)
}
}

View file

@ -1,17 +0,0 @@
package info.nightscout.core.validators
import org.junit.Assert.assertEquals
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View file

@ -3,24 +3,22 @@ package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Rule import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.MockitoRule import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale import java.util.Locale
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase { open class TestBase {
val aapsLogger = AAPSLoggerTest() val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
// Add a JUnit rule that will setup the @Mock annotated vars and log. @BeforeEach
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
@Before
fun setupLocale() { fun setupLocale() {
Locale.setDefault(Locale.ENGLISH) Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true") System.setProperty("disableFirebase", "true")

View file

@ -18,7 +18,7 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.mockito.ArgumentMatchers.anyDouble import org.mockito.ArgumentMatchers.anyDouble
import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
@ -49,7 +49,7 @@ open class TestBaseWithProfile : TestBase() {
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@Before @BeforeEach
fun prepareMock() { fun prepareMock() {
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps package info.nightscout.androidaps
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.interfaces.pump.Pump import info.nightscout.interfaces.pump.Pump
@ -13,6 +14,7 @@ import info.nightscout.interfaces.utils.TimeChangeType
import org.json.JSONObject import org.json.JSONObject
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
@OpenForTesting
class TestPumpPlugin(val injector: HasAndroidInjector) : Pump { class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
var connected = false var connected = false

View file

@ -19,8 +19,8 @@ import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.anyInt import org.mockito.Mockito.anyInt
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -52,7 +52,7 @@ class BolusTimerImplTest : TestBase() {
private lateinit var automationPlugin: AutomationPlugin private lateinit var automationPlugin: AutomationPlugin
private lateinit var sut: BolusTimerImpl private lateinit var sut: BolusTimerImpl
@Before @BeforeEach
fun init() { fun init() {
`when`(rh.gs(anyInt())).thenReturn("") `when`(rh.gs(anyInt())).thenReturn("")
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)

View file

@ -20,10 +20,11 @@ import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.any
import org.mockito.Mockito.anyInt import org.mockito.Mockito.anyInt
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -40,7 +41,6 @@ class CarbTimerImplTest : TestBase() {
@Mock lateinit var locationServiceHelper: LocationServiceHelper @Mock lateinit var locationServiceHelper: LocationServiceHelper
@Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var timerUtil: TimerUtil
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -51,15 +51,17 @@ class CarbTimerImplTest : TestBase() {
} }
} }
private lateinit var dateUtil: DateUtil private lateinit var dateUtil: DateUtil
private lateinit var timerUtil: TimerUtil
private lateinit var automationPlugin: AutomationPlugin private lateinit var automationPlugin: AutomationPlugin
private lateinit var sut: CarbTimerImpl private lateinit var sut: CarbTimerImpl
@Before @BeforeEach
fun init() { fun init() {
`when`(rh.gs(anyInt())).thenReturn("") `when`(rh.gs(anyInt())).thenReturn("")
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
dateUtil = DateUtil(context) dateUtil = DateUtil(context)
timerUtil = TimerUtil(context)
automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin) automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin)
sut = CarbTimerImpl(injector, rh, automationPlugin, timerUtil) sut = CarbTimerImpl(injector, rh, automationPlugin, timerUtil)
} }
@ -73,6 +75,6 @@ class CarbTimerImplTest : TestBase() {
Assert.assertEquals(0, automationPlugin.size()) Assert.assertEquals(0, automationPlugin.size())
sut.scheduleTimeToEatReminder(1) sut.scheduleTimeToEatReminder(1)
Mockito.verify(timerUtil, Mockito.times(1)).scheduleReminder(1, "") Mockito.verify(context, Mockito.times(1)).startActivity(any())
} }
} }

View file

@ -4,8 +4,8 @@ import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
class DetailedBolusInfoStorageTest : TestBase() { class DetailedBolusInfoStorageTest : TestBase() {
@ -24,7 +24,7 @@ class DetailedBolusInfoStorageTest : TestBase() {
info3.insulin = 5.0 info3.insulin = 5.0
} }
@Before @BeforeEach
fun prepare() { fun prepare() {
detailedBolusInfoStorage = DetailedBolusInfoStorageImpl(aapsLogger) detailedBolusInfoStorage = DetailedBolusInfoStorageImpl(aapsLogger)
} }

View file

@ -1,12 +1,11 @@
package info.nightscout.implementation.pump package info.nightscout.implementation.pump
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.pump.TemporaryBasalStorage
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
class TemporaryBasalStorageTest : TestBase() { class TemporaryBasalStorageTest : TestBase() {
@ -16,7 +15,7 @@ class TemporaryBasalStorageTest : TestBase() {
private lateinit var temporaryBasalStorage: TemporaryBasalStorageImpl private lateinit var temporaryBasalStorage: TemporaryBasalStorageImpl
@Before @BeforeEach
fun prepare() { fun prepare() {
temporaryBasalStorage = TemporaryBasalStorageImpl(aapsLogger) temporaryBasalStorage = TemporaryBasalStorageImpl(aapsLogger)
} }

View file

@ -39,8 +39,8 @@ import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.anyLong import org.mockito.Mockito.anyLong
import org.mockito.Mockito.mock import org.mockito.Mockito.mock
@ -118,7 +118,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
private lateinit var commandQueue: CommandQueueImplementation private lateinit var commandQueue: CommandQueueImplementation
private lateinit var testPumpPlugin: TestPumpPlugin private lateinit var testPumpPlugin: TestPumpPlugin
@Before @BeforeEach
fun prepare() { fun prepare() {
commandQueue = CommandQueueMocked( commandQueue = CommandQueueMocked(
injector, aapsLogger, rxBus, aapsSchedulers, rh, injector, aapsLogger, rxBus, aapsSchedulers, rh,

View file

@ -20,8 +20,8 @@ import info.nightscout.interfaces.queue.Command
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
@ -54,7 +54,7 @@ class QueueThreadTest : TestBaseWithProfile() {
private lateinit var commandQueue: CommandQueueImplementation private lateinit var commandQueue: CommandQueueImplementation
private lateinit var sut: QueueThread private lateinit var sut: QueueThread
@Before @BeforeEach
fun prepare() { fun prepare() {
pumpPlugin = TestPumpPlugin(injector) pumpPlugin = TestPumpPlugin(injector)
commandQueue = CommandQueueImplementation( commandQueue = CommandQueueImplementation(

View file

@ -1,5 +1,6 @@
package info.nightscout.plugins.general.autotune package info.nightscout.plugins.general.autotune
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.interfaces.logging.LoggerUtils import info.nightscout.interfaces.logging.LoggerUtils
import info.nightscout.plugins.aps.R import info.nightscout.plugins.aps.R
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
@ -23,6 +24,7 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
@OpenForTesting
class AutotuneFS @Inject constructor( class AutotuneFS @Inject constructor(
private val rh: ResourceHelper, private val rh: ResourceHelper,
private val loggerUtils: LoggerUtils private val loggerUtils: LoggerUtils

View file

@ -3,24 +3,22 @@ package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Rule import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.MockitoRule import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale import java.util.Locale
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase { open class TestBase {
val aapsLogger = AAPSLoggerTest() val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
// Add a JUnit rule that will setup the @Mock annotated vars and log. @BeforeEach
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
@Before
fun setupLocale() { fun setupLocale() {
Locale.setDefault(Locale.ENGLISH) Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true") System.setProperty("disableFirebase", "true")

View file

@ -17,7 +17,7 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.mockito.ArgumentMatchers.anyDouble import org.mockito.ArgumentMatchers.anyDouble
import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
@ -48,7 +48,7 @@ open class TestBaseWithProfile : TestBase() {
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@Before @BeforeEach
fun prepareMock() { fun prepareMock() {
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +

View file

@ -16,8 +16,8 @@ import info.nightscout.shared.utils.T
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import java.io.File import java.io.File
@ -33,7 +33,7 @@ class AutotuneCoreTest : TestBaseWithProfile() {
private var autotuneMin = 0.0 private var autotuneMin = 0.0
private var autotuneMax = 0.0 private var autotuneMax = 0.0
@Before @BeforeEach
fun initData() { fun initData() {
autotuneCore = AutotuneCore(sp, autotuneFS) autotuneCore = AutotuneCore(sp, autotuneFS)
TimeZone.setDefault(TimeZone.getTimeZone("GMT+2")) TimeZone.setDefault(TimeZone.getTimeZone("GMT+2"))

View file

@ -24,8 +24,8 @@ import info.nightscout.shared.utils.T
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import java.io.File import java.io.File
@ -45,7 +45,7 @@ class AutotunePrepTest : TestBaseWithProfile() {
private var autotuneMax = 0.0 private var autotuneMax = 0.0
private var startDayTime = 0L private var startDayTime = 0L
@Before @BeforeEach
fun initData() { fun initData() {
ts = T.msecs(TimeZone.getDefault().getOffset(System.currentTimeMillis()).toLong()).hours().toInt() - 2 ts = T.msecs(TimeZone.getDefault().getOffset(System.currentTimeMillis()).toLong()).hours().toInt() - 2
} }

View file

@ -1,11 +1,13 @@
package info.nightscout.plugins.general.autotune package info.nightscout.plugins.general.autotune
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.plugins.general.autotune.data.BGDatum
import info.nightscout.plugins.general.autotune.data.CRDatum
import info.nightscout.plugins.general.autotune.data.PreppedGlucose import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import java.io.File import java.io.File
class PreppedGlucoseTest : TestBaseWithProfile() { class PreppedGlucoseTest : TestBaseWithProfile() {
@ -13,7 +15,7 @@ class PreppedGlucoseTest : TestBaseWithProfile() {
private lateinit var prep1: PreppedGlucose private lateinit var prep1: PreppedGlucose
private lateinit var prepJson1: String private lateinit var prepJson1: String
@Before @BeforeEach
fun initData() { fun initData() {
prepJson1 = File("src/test/res/autotune/test1/autotune.2022-05-21.json").readText() prepJson1 = File("src/test/res/autotune/test1/autotune.2022-05-21.json").readText()
prep1 = PreppedGlucose(JSONObject(prepJson1), dateUtil) prep1 = PreppedGlucose(JSONObject(prepJson1), dateUtil)
@ -22,22 +24,22 @@ class PreppedGlucoseTest : TestBaseWithProfile() {
@Test @Test
fun preppedGlucoseLoadTest() { // Test if load from file of OpenAPS categorisation is Ok fun preppedGlucoseLoadTest() { // Test if load from file of OpenAPS categorisation is Ok
val crData0 = val crData0 =
info.nightscout.plugins.general.autotune.data.CRDatum( CRDatum(
JSONObject("{\"CRInitialIOB\":13.594,\"CRInitialBG\":123,\"CRInitialCarbTime\":\"2022-05-21T07:54:09.000Z\",\"CREndIOB\":-0.155,\"CREndBG\":98,\"CREndTime\":\"2022-05-21T11:19:08.000Z\",\"CRCarbs\":70,\"CRInsulin\":-2.13}"), JSONObject("{\"CRInitialIOB\":13.594,\"CRInitialBG\":123,\"CRInitialCarbTime\":\"2022-05-21T07:54:09.000Z\",\"CREndIOB\":-0.155,\"CREndBG\":98,\"CREndTime\":\"2022-05-21T11:19:08.000Z\",\"CRCarbs\":70,\"CRInsulin\":-2.13}"),
dateUtil dateUtil
) )
val csfDataEnd = val csfDataEnd =
info.nightscout.plugins.general.autotune.data.BGDatum( BGDatum(
JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653176050000,\"dateString\":\"2022-05-21T23:34:10.000Z\",\"isValid\":true,\"sgv\":127,\"direction\":\"Flat\",\"type\":\"sgv\",\"_id\":\"6289771371a363000480abc1\",\"glucose\":127,\"avgDelta\":\"2.50\",\"BGI\":-2.93,\"deviation\":\"5.43\",\"mealCarbs\":0,\"mealAbsorption\":\"end\"}"), JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653176050000,\"dateString\":\"2022-05-21T23:34:10.000Z\",\"isValid\":true,\"sgv\":127,\"direction\":\"Flat\",\"type\":\"sgv\",\"_id\":\"6289771371a363000480abc1\",\"glucose\":127,\"avgDelta\":\"2.50\",\"BGI\":-2.93,\"deviation\":\"5.43\",\"mealCarbs\":0,\"mealAbsorption\":\"end\"}"),
dateUtil dateUtil
) )
val isfData0 = val isfData0 =
info.nightscout.plugins.general.autotune.data.BGDatum( BGDatum(
JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653108249000,\"dateString\":\"2022-05-21T04:44:09.000Z\",\"isValid\":true,\"sgv\":123,\"direction\":\"FortyFiveDown\",\"type\":\"sgv\",\"_id\":\"62886e2919e2e60004989bba\",\"glucose\":123,\"avgDelta\":\"-7.50\",\"BGI\":-7.59,\"deviation\":\"0.09\"}"), JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653108249000,\"dateString\":\"2022-05-21T04:44:09.000Z\",\"isValid\":true,\"sgv\":123,\"direction\":\"FortyFiveDown\",\"type\":\"sgv\",\"_id\":\"62886e2919e2e60004989bba\",\"glucose\":123,\"avgDelta\":\"-7.50\",\"BGI\":-7.59,\"deviation\":\"0.09\"}"),
dateUtil dateUtil
) )
val basalDataEnd = val basalDataEnd =
info.nightscout.plugins.general.autotune.data.BGDatum( BGDatum(
JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653180549000,\"dateString\":\"2022-05-22T00:49:09.000Z\",\"isValid\":true,\"sgv\":121,\"direction\":\"FortyFiveDown\",\"type\":\"sgv\",\"_id\":\"628988a3da46aa0004d1e0f5\",\"glucose\":121,\"avgDelta\":\"-5.25\",\"BGI\":-3.32,\"deviation\":\"-1.93\"}"), JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653180549000,\"dateString\":\"2022-05-22T00:49:09.000Z\",\"isValid\":true,\"sgv\":121,\"direction\":\"FortyFiveDown\",\"type\":\"sgv\",\"_id\":\"628988a3da46aa0004d1e0f5\",\"glucose\":121,\"avgDelta\":\"-5.25\",\"BGI\":-3.32,\"deviation\":\"-1.93\"}"),
dateUtil dateUtil
) )

View file

@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection import android.content.ServiceConnection
import android.os.IBinder import android.os.IBinder
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.interfaces.NotificationHolder import info.nightscout.interfaces.NotificationHolder
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -19,6 +20,7 @@ import javax.inject.Singleton
*/ */
@Singleton @Singleton
@OpenForTesting
class LocationServiceHelper @Inject constructor( class LocationServiceHelper @Inject constructor(
private val notificationHolder: NotificationHolder private val notificationHolder: NotificationHolder
) { ) {

View file

@ -3,26 +3,24 @@ package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Rule import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.ArgumentMatcher import org.mockito.ArgumentMatcher
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.MockitoRule import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale import java.util.Locale
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase { open class TestBase {
val aapsLogger = AAPSLoggerTest() val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
// Add a JUnit rule that will setup the @Mock annotated vars and log. @BeforeEach
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
@Before
fun setupLocale() { fun setupLocale() {
Locale.setDefault(Locale.ENGLISH) Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true") System.setProperty("disableFirebase", "true")

View file

@ -16,7 +16,7 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.mockito.Mock import org.mockito.Mock
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -42,7 +42,7 @@ open class TestBaseWithProfile : TestBase() {
lateinit var validProfile: Profile lateinit var validProfile: Profile
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@Before @BeforeEach
fun prepareMock() { fun prepareMock() {
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +

View file

@ -15,7 +15,7 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
class AutomationEventTest : TestBase() { class AutomationEventTest : TestBase() {

View file

@ -7,7 +7,7 @@ import info.nightscout.automation.triggers.Trigger
import info.nightscout.automation.triggers.TriggerConnector import info.nightscout.automation.triggers.TriggerConnector
import info.nightscout.automation.triggers.TriggerDummy import info.nightscout.automation.triggers.TriggerDummy
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class ComposeTriggerTest : TestBase() { class ComposeTriggerTest : TestBase() {

View file

@ -14,8 +14,8 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -25,10 +25,10 @@ class ActionAlarmTest : TestBase() {
@Mock lateinit var rh: ResourceHelper @Mock lateinit var rh: ResourceHelper
@Mock lateinit var rxBus: RxBus @Mock lateinit var rxBus: RxBus
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var timerUtil: TimerUtil
@Mock lateinit var dateUtil: DateUtil @Mock lateinit var dateUtil: DateUtil
@Mock lateinit var config: Config @Mock lateinit var config: Config
private lateinit var timerUtil: TimerUtil
private lateinit var sut: ActionAlarm private lateinit var sut: ActionAlarm
var injector: HasAndroidInjector = HasAndroidInjector { var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -46,12 +46,12 @@ class ActionAlarmTest : TestBase() {
} }
} }
@Before @BeforeEach
fun setup() { fun setup() {
`when`(context.getString(info.nightscout.core.main.R.string.ok)).thenReturn("OK") `when`(context.getString(info.nightscout.core.main.R.string.ok)).thenReturn("OK")
`when`(context.getString(info.nightscout.core.main.R.string.alarm)).thenReturn("Alarm") `when`(context.getString(info.nightscout.core.main.R.string.alarm)).thenReturn("Alarm")
`when`(rh.gs(ArgumentMatchers.eq(R.string.alarm_message), ArgumentMatchers.anyString())).thenReturn("Alarm: %s") `when`(rh.gs(ArgumentMatchers.eq(R.string.alarm_message), ArgumentMatchers.anyString())).thenReturn("Alarm: %s")
timerUtil = TimerUtil(context)
sut = ActionAlarm(injector) sut = ActionAlarm(injector)
} }
@ -69,6 +69,7 @@ class ActionAlarmTest : TestBase() {
} }
@Test fun doActionTest() { @Test fun doActionTest() {
sut.text = InputString("Asd")
sut.doAction(object : Callback() { sut.doAction(object : Callback() {
override fun run() { override fun run() {
Assert.assertTrue(result.success) Assert.assertTrue(result.success)

View file

@ -1,16 +1,16 @@
package info.nightscout.automation.actions package info.nightscout.automation.actions
import info.nightscout.automation.elements.InputCarePortalMenu
import info.nightscout.automation.elements.InputDuration
import info.nightscout.automation.elements.InputString
import info.nightscout.database.impl.transactions.InsertIfNewByTimestampTherapyEventTransaction import info.nightscout.database.impl.transactions.InsertIfNewByTimestampTherapyEventTransaction
import info.nightscout.database.impl.transactions.Transaction import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import info.nightscout.automation.elements.InputCarePortalMenu
import info.nightscout.automation.elements.InputDuration
import info.nightscout.automation.elements.InputString
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -18,7 +18,7 @@ class ActionCarePortalEventTest : ActionsTestBase() {
private lateinit var sut: ActionCarePortalEvent private lateinit var sut: ActionCarePortalEvent
@Before @BeforeEach
fun setup() { fun setup() {
`when`(sp.getString(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn("AAPS") `when`(sp.getString(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn("AAPS")
`when`( `when`(

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.actions
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class ActionDummyTest : ActionsTestBase() { class ActionDummyTest : ActionsTestBase() {

View file

@ -4,8 +4,8 @@ import info.nightscout.automation.R
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.eq import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -14,7 +14,7 @@ class ActionLoopDisableTest : ActionsTestBase() {
lateinit var sut: ActionLoopDisable lateinit var sut: ActionLoopDisable
@Before @BeforeEach
fun setup() { fun setup() {
testPumpPlugin.pumpDescription.isTempBasalCapable = true testPumpPlugin.pumpDescription.isTempBasalCapable = true

View file

@ -4,8 +4,8 @@ import info.nightscout.automation.R
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -13,7 +13,7 @@ class ActionLoopEnableTest : ActionsTestBase() {
lateinit var sut: ActionLoopEnable lateinit var sut: ActionLoopEnable
@Before @BeforeEach
fun setup() { fun setup() {
testPumpPlugin.pumpDescription.isTempBasalCapable = true testPumpPlugin.pumpDescription.isTempBasalCapable = true

View file

@ -7,15 +7,15 @@ import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class ActionLoopResumeTest : ActionsTestBase() { class ActionLoopResumeTest : ActionsTestBase() {
lateinit var sut: ActionLoopResume lateinit var sut: ActionLoopResume
@Before @BeforeEach
fun setup() { fun setup() {
`when`(rh.gs(info.nightscout.core.main.R.string.resumeloop)).thenReturn("Resume loop") `when`(rh.gs(info.nightscout.core.main.R.string.resumeloop)).thenReturn("Resume loop")

View file

@ -4,8 +4,8 @@ import info.nightscout.automation.R
import info.nightscout.automation.elements.InputDuration import info.nightscout.automation.elements.InputDuration
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -14,7 +14,7 @@ class ActionLoopSuspendTest : ActionsTestBase() {
lateinit var sut: ActionLoopSuspend lateinit var sut: ActionLoopSuspend
@Before @BeforeEach
fun setup() { fun setup() {
`when`(context.getString(info.nightscout.core.main.R.string.suspendloop)).thenReturn("Suspend loop") `when`(context.getString(info.nightscout.core.main.R.string.suspendloop)).thenReturn("Suspend loop")

View file

@ -15,8 +15,8 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.core.Completable
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
@ -43,7 +43,7 @@ class ActionNotificationTest : TestBase() {
} }
} }
@Before @BeforeEach
fun setup() { fun setup() {
`when`(context.getString(info.nightscout.core.main.R.string.ok)).thenReturn("OK") `when`(context.getString(info.nightscout.core.main.R.string.ok)).thenReturn("OK")
`when`(rh.gs(info.nightscout.core.main.R.string.notification)).thenReturn("Notification") `when`(rh.gs(info.nightscout.core.main.R.string.notification)).thenReturn("Notification")

View file

@ -1,12 +1,12 @@
package info.nightscout.automation.actions package info.nightscout.automation.actions
import info.nightscout.interfaces.queue.Callback
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.automation.elements.InputDuration import info.nightscout.automation.elements.InputDuration
import info.nightscout.automation.elements.InputPercent import info.nightscout.automation.elements.InputPercent
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -14,7 +14,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
private lateinit var sut: ActionProfileSwitchPercent private lateinit var sut: ActionProfileSwitchPercent
@Before @BeforeEach
fun setup() { fun setup() {
`when`(rh.gs(R.string.startprofileforever)).thenReturn("Start profile %d%%") `when`(rh.gs(R.string.startprofileforever)).thenReturn("Start profile %d%%")

View file

@ -4,8 +4,8 @@ import info.nightscout.automation.R
import info.nightscout.automation.elements.InputProfileName import info.nightscout.automation.elements.InputProfileName
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyLong import org.mockito.ArgumentMatchers.anyLong
import org.mockito.Mockito import org.mockito.Mockito
@ -19,7 +19,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"ActionProfileSwitch\"}" private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"ActionProfileSwitch\"}"
@Before fun setUp() { @BeforeEach fun setUp() {
`when`(rh.gs(R.string.profilename)).thenReturn("Change profile to") `when`(rh.gs(R.string.profilename)).thenReturn("Change profile to")
`when`(rh.gs(ArgumentMatchers.eq(R.string.changengetoprofilename), ArgumentMatchers.anyString())).thenReturn("Change profile to %s") `when`(rh.gs(ArgumentMatchers.eq(R.string.changengetoprofilename), ArgumentMatchers.anyString())).thenReturn("Change profile to %s")
`when`(context.getString(R.string.alreadyset)).thenReturn("Already set") `when`(context.getString(R.string.alreadyset)).thenReturn("Already set")

View file

@ -1,11 +1,11 @@
package info.nightscout.automation.actions package info.nightscout.automation.actions
import info.nightscout.interfaces.queue.Callback
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.automation.elements.InputString import info.nightscout.automation.elements.InputString
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
import org.mockito.ArgumentMatchers.eq import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -14,7 +14,7 @@ class ActionSendSMSTest : ActionsTestBase() {
private lateinit var sut: ActionSendSMS private lateinit var sut: ActionSendSMS
@Before @BeforeEach
fun setup() { fun setup() {
`when`(rh.gs(eq(R.string.sendsmsactionlabel), anyString())).thenReturn("Send SMS: %s") `when`(rh.gs(eq(R.string.sendsmsactionlabel), anyString())).thenReturn("Send SMS: %s")

View file

@ -1,17 +1,17 @@
package info.nightscout.automation.actions package info.nightscout.automation.actions
import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction
import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.automation.elements.InputDuration import info.nightscout.automation.elements.InputDuration
import info.nightscout.automation.elements.InputTempTarget import info.nightscout.automation.elements.InputTempTarget
import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction
import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -19,7 +19,7 @@ class ActionStartTempTargetTest : ActionsTestBase() {
private lateinit var sut: ActionStartTempTarget private lateinit var sut: ActionStartTempTarget
@Before @BeforeEach
fun setup() { fun setup() {
`when`(rh.gs(R.string.starttemptarget)).thenReturn("Start temp target") `when`(rh.gs(R.string.starttemptarget)).thenReturn("Start temp target")

View file

@ -1,17 +1,17 @@
package info.nightscout.automation.actions package info.nightscout.automation.actions
import info.nightscout.interfaces.queue.Callback
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class ActionStopProcessingTest : ActionsTestBase() { class ActionStopProcessingTest : ActionsTestBase() {
lateinit var sut: ActionStopProcessing lateinit var sut: ActionStopProcessing
@Before @BeforeEach
fun setup() { fun setup() {
`when`(rh.gs(R.string.stop_processing)).thenReturn("Stop processing") `when`(rh.gs(R.string.stop_processing)).thenReturn("Stop processing")

View file

@ -1,14 +1,14 @@
package info.nightscout.automation.actions package info.nightscout.automation.actions
import info.nightscout.database.impl.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.database.impl.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -16,7 +16,7 @@ class ActionStopTempTargetTest : ActionsTestBase() {
private lateinit var sut: ActionStopTempTarget private lateinit var sut: ActionStopTempTarget
@Before @BeforeEach
fun setup() { fun setup() {
`when`(rh.gs(R.string.stoptemptarget)).thenReturn("Stop temp target") `when`(rh.gs(R.string.stoptemptarget)).thenReturn("Stop temp target")

View file

@ -5,7 +5,6 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.automation.triggers.Trigger import info.nightscout.automation.triggers.Trigger
import info.nightscout.database.entities.DeviceStatus import info.nightscout.database.entities.DeviceStatus
import info.nightscout.database.entities.OfflineEvent import info.nightscout.database.entities.OfflineEvent
@ -15,9 +14,11 @@ import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.configBuilder.RunningConfiguration import info.nightscout.interfaces.configBuilder.RunningConfiguration
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.profile.ProfileSource import info.nightscout.interfaces.profile.ProfileSource
@ -30,7 +31,7 @@ import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -74,6 +75,7 @@ ActionsTestBase : TestBaseWithProfile() {
runningConfiguration: RunningConfiguration, runningConfiguration: RunningConfiguration,
version: String version: String
): DeviceStatus? = null ): DeviceStatus? = null
override fun setPluginEnabled(type: PluginType, newState: Boolean) {}
} }
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@ -191,7 +193,7 @@ ActionsTestBase : TestBaseWithProfile() {
} }
} }
@Before @BeforeEach
fun mock() { fun mock() {
testPumpPlugin = TestPumpPlugin(pluginDescription, aapsLogger, rh, injector) testPumpPlugin = TestPumpPlugin(pluginDescription, aapsLogger, rh, injector)
`when`(activePlugin.activePump).thenReturn(testPumpPlugin) `when`(activePlugin.activePump).thenReturn(testPumpPlugin)

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class ComparatorConnectTest : TriggerTestBase() { class ComparatorConnectTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class ComparatorExistsTest : TriggerTestBase() { class ComparatorExistsTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class ComparatorTest : TriggerTestBase() { class ComparatorTest : TriggerTestBase() {

View file

@ -1,10 +1,10 @@
package info.nightscout.automation.elements package info.nightscout.automation.elements
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import info.nightscout.interfaces.GlucoseUnit
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class InputBgTest : TriggerTestBase() { class InputBgTest : TriggerTestBase() {
@ -20,7 +20,7 @@ class InputBgTest : TriggerTestBase() {
Assert.assertEquals(GlucoseUnit.MGDL, i.units) Assert.assertEquals(GlucoseUnit.MGDL, i.units)
} }
@Before @BeforeEach
fun prepare() { fun prepare() {
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
} }

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class InputCarePortalEventTest : TriggerTestBase() { class InputCarePortalEventTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class InputDurationTest : TriggerTestBase() { class InputDurationTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class InputInsulinTest : TriggerTestBase() { class InputInsulinTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class InputPercentTest : TriggerTestBase() { class InputPercentTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class InputProfileNameTest : TriggerTestBase() { class InputProfileNameTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class InputStringTest : TriggerTestBase() { class InputStringTest : TriggerTestBase() {

View file

@ -1,9 +1,9 @@
package info.nightscout.automation.elements package info.nightscout.automation.elements
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import info.nightscout.interfaces.GlucoseUnit
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class InputTempTargetTest : TriggerTestBase() { class InputTempTargetTest : TriggerTestBase() {

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class LabelWithElementTest : TriggerTestBase() { class LabelWithElementTest : TriggerTestBase() {

View file

@ -4,7 +4,7 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class LayoutBuilderTest : TestBase() { class LayoutBuilderTest : TestBase() {

View file

@ -3,7 +3,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerDummy import info.nightscout.automation.triggers.TriggerDummy
import info.nightscout.automation.triggers.TriggerTestBase import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class StaticLabelTest : TriggerTestBase() { class StaticLabelTest : TriggerTestBase() {

View file

@ -1,13 +1,13 @@
package info.nightscout.automation.triggers package info.nightscout.automation.triggers
import com.google.common.base.Optional import com.google.common.base.Optional
import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.automation.elements.Comparator import info.nightscout.automation.elements.Comparator
import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -105,7 +105,7 @@ class TriggerAutosensValueTest : TriggerTestBase() {
Assert.assertEquals(Optional.of(R.drawable.ic_as), TriggerAutosensValue(injector).icon()) Assert.assertEquals(Optional.of(R.drawable.ic_as), TriggerAutosensValue(injector).icon())
} }
@Before @BeforeEach
fun mock() { fun mock() {
`when`(dateUtil.now()).thenReturn(now) `when`(dateUtil.now()).thenReturn(now)
} }

View file

@ -4,7 +4,7 @@ import com.google.common.base.Optional
import info.nightscout.automation.elements.ComparatorConnect import info.nightscout.automation.elements.ComparatorConnect
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
class TriggerBTDeviceTest : TriggerTestBase() { class TriggerBTDeviceTest : TriggerTestBase() {

View file

@ -6,15 +6,15 @@ import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class TriggerBgTest : TriggerTestBase() { class TriggerBgTest : TriggerTestBase() {
var now = 1514766900000L var now = 1514766900000L
@Before @BeforeEach
fun prepare() { fun prepare() {
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
`when`(dateUtil.now()).thenReturn(now) `when`(dateUtil.now()).thenReturn(now)

View file

@ -8,15 +8,15 @@ import io.reactivex.rxjava3.core.Single
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class TriggerBolusAgoTest : TriggerTestBase() { class TriggerBolusAgoTest : TriggerTestBase() {
var now = 1514766900000L var now = 1514766900000L
@Before @BeforeEach
fun mock() { fun mock() {
`when`(dateUtil.now()).thenReturn(now) `when`(dateUtil.now()).thenReturn(now)
} }

View file

@ -5,8 +5,8 @@ import info.nightscout.automation.elements.Comparator
import info.nightscout.interfaces.iob.CobInfo import info.nightscout.interfaces.iob.CobInfo
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
@ -14,7 +14,7 @@ class TriggerCOBTest : TriggerTestBase() {
var now = 1514766900000L var now = 1514766900000L
@Before fun mock() { @BeforeEach fun mock() {
`when`(dateUtil.now()).thenReturn(now) `when`(dateUtil.now()).thenReturn(now)
`when`(sp.getInt(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(48) `when`(sp.getInt(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(48)
} }

View file

@ -3,7 +3,7 @@ package info.nightscout.automation.triggers
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class TriggerConnectorTest : TriggerTestBase() { class TriggerConnectorTest : TriggerTestBase() {

View file

@ -8,15 +8,15 @@ import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.jupiter.api.BeforeEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class TriggerDeltaTest : TriggerTestBase() { class TriggerDeltaTest : TriggerTestBase() {
var now = 1514766900000L var now = 1514766900000L
@Before @BeforeEach
fun mock() { fun mock() {
`when`(dateUtil.now()).thenReturn(now) `when`(dateUtil.now()).thenReturn(now)
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.triggers
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.jupiter.api.Test
class TriggerDummyTest : TriggerTestBase() { class TriggerDummyTest : TriggerTestBase() {

Some files were not shown because too many files have changed in this diff Show more