add tests
This commit is contained in:
parent
6ddb0c418d
commit
950fedfef3
|
@ -49,4 +49,8 @@ files:
|
|||
translation: /pump-common/src/main/res/values-%android_code%/strings.xml
|
||||
- source: /openhumans/src/main/res/values/strings.xml
|
||||
translation: /openhumans/src/main/res/values-%android_code%/strings.xml
|
||||
- source: /implementation/src/main/res/values/strings.xml
|
||||
translation: /implementation/src/main/res/values-%android_code%/strings.xml
|
||||
- source: /ui/src/main/res/values/strings.xml
|
||||
translation: /ui/src/main/res/values-%android_code%/strings.xml
|
||||
translate_attributes: 0
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import info.nightscout.shared.logging.AAPSLoggerTest
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
import java.util.*
|
||||
|
||||
open class TestBase {
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
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
|
||||
fun setupLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
}
|
||||
|
||||
// Workaround for Kotlin nullability.
|
||||
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
||||
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
||||
fun <T> anyObject(): T {
|
||||
Mockito.any<T>()
|
||||
return uninitialized()
|
||||
}
|
||||
|
||||
@Suppress("Unchecked_Cast")
|
||||
fun <T> uninitialized(): T = null as T
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package info.nightscout.implementation
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.interfaces.Loop
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin
|
||||
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger
|
||||
import info.nightscout.androidaps.services.LocationServiceHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.anyInt
|
||||
import org.mockito.Mockito.`when`
|
||||
|
||||
class BolusTimerImplTest : TestBase() {
|
||||
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var loop: Loop
|
||||
@Mock lateinit var rxBus: RxBus
|
||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||
@Mock lateinit var config: Config
|
||||
@Mock lateinit var locationServiceHelper: LocationServiceHelper
|
||||
@Mock lateinit var activePlugin: ActivePlugin
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
|
||||
private val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Trigger) {
|
||||
it.profileFunction = profileFunction
|
||||
it.rh = rh
|
||||
}
|
||||
}
|
||||
}
|
||||
private lateinit var dateUtil: DateUtil
|
||||
|
||||
private lateinit var automationPlugin: AutomationPlugin
|
||||
private lateinit var sut: BolusTimerImpl
|
||||
|
||||
@Before
|
||||
fun init() {
|
||||
`when`(rh.gs(anyInt())).thenReturn("")
|
||||
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
||||
dateUtil = DateUtil(context)
|
||||
automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin)
|
||||
sut = BolusTimerImpl(injector, rh, automationPlugin)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun doTest() {
|
||||
Assert.assertEquals(0, automationPlugin.size())
|
||||
sut.scheduleAutomationEventBolusReminder()
|
||||
Assert.assertEquals(1, automationPlugin.size())
|
||||
sut.removeAutomationEventBolusReminder()
|
||||
Assert.assertEquals(0, automationPlugin.size())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package info.nightscout.implementation
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.interfaces.Loop
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin
|
||||
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger
|
||||
import info.nightscout.androidaps.services.LocationServiceHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.TimerUtil
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.anyInt
|
||||
import org.mockito.Mockito.`when`
|
||||
|
||||
class CarbTimerImplTest : TestBase() {
|
||||
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var loop: Loop
|
||||
@Mock lateinit var rxBus: RxBus
|
||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||
@Mock lateinit var config: Config
|
||||
@Mock lateinit var locationServiceHelper: LocationServiceHelper
|
||||
@Mock lateinit var activePlugin: ActivePlugin
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var timerUtil: TimerUtil
|
||||
|
||||
private val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Trigger) {
|
||||
it.profileFunction = profileFunction
|
||||
it.rh = rh
|
||||
}
|
||||
}
|
||||
}
|
||||
private lateinit var dateUtil: DateUtil
|
||||
|
||||
private lateinit var automationPlugin: AutomationPlugin
|
||||
private lateinit var sut: CarbTimerImpl
|
||||
|
||||
@Before
|
||||
fun init() {
|
||||
`when`(rh.gs(anyInt())).thenReturn("")
|
||||
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
||||
dateUtil = DateUtil(context)
|
||||
automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin)
|
||||
sut = CarbTimerImpl(injector, rh, automationPlugin, timerUtil)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun doTest() {
|
||||
Assert.assertEquals(0, automationPlugin.size())
|
||||
sut.scheduleAutomationEventEatReminder()
|
||||
Assert.assertEquals(1, automationPlugin.size())
|
||||
sut.removeAutomationEventEatReminder()
|
||||
Assert.assertEquals(0, automationPlugin.size())
|
||||
|
||||
sut.scheduleTimeToEatReminder(1)
|
||||
Mockito.verify(timerUtil, Mockito.times(1)).scheduleReminder(1, "")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue