Dana module test & lints
This commit is contained in:
parent
c249e50fa3
commit
b6788d210b
|
@ -25,6 +25,7 @@ import org.powermock.api.mockito.PowerMockito
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(FabricPrivacy::class, MainApp::class, DatabaseHelper::class)
|
@PrepareForTest(FabricPrivacy::class, MainApp::class, DatabaseHelper::class)
|
||||||
class TreatmentsPluginTest : TestBaseWithProfile() {
|
class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||||
|
@ -47,8 +48,8 @@ class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var insulinOrefRapidActingPlugin: InsulinOrefRapidActingPlugin
|
private lateinit var insulinOrefRapidActingPlugin: InsulinOrefRapidActingPlugin
|
||||||
lateinit var sot: TreatmentsPlugin
|
private lateinit var sot: TreatmentsPlugin
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun prepare() {
|
fun prepare() {
|
||||||
|
@ -77,7 +78,7 @@ class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `90% TBR and should produce less absolute insulin`() {
|
fun `90pct TBR and should produce less absolute insulin`() {
|
||||||
val now = DateUtil.now()
|
val now = DateUtil.now()
|
||||||
val tbrs: MutableList<TemporaryBasal> = ArrayList()
|
val tbrs: MutableList<TemporaryBasal> = ArrayList()
|
||||||
`when`(databaseHelper.getTemporaryBasalsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(tbrs)
|
`when`(databaseHelper.getTemporaryBasalsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(tbrs)
|
||||||
|
@ -91,7 +92,7 @@ class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `110% TBR and should produce 10% more absolute insulin`() {
|
fun `110pct TBR and should produce 10pct more absolute insulin`() {
|
||||||
val now = DateUtil.now()
|
val now = DateUtil.now()
|
||||||
val tbrs: MutableList<TemporaryBasal> = ArrayList()
|
val tbrs: MutableList<TemporaryBasal> = ArrayList()
|
||||||
`when`(databaseHelper.getTemporaryBasalsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(tbrs)
|
`when`(databaseHelper.getTemporaryBasalsDataFromTime(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(tbrs)
|
||||||
|
|
39
dana/src/test/java/info/nightscout/androidaps/TestBase.kt
Normal file
39
dana/src/test/java/info/nightscout/androidaps/TestBase.kt
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package info.nightscout.androidaps
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.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,82 @@
|
||||||
|
package info.nightscout.androidaps
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
import info.nightscout.androidaps.db.ProfileSwitch
|
||||||
|
import info.nightscout.androidaps.db.Treatment
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
|
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileStore
|
||||||
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.Before
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
|
@PrepareForTest(FabricPrivacy::class)
|
||||||
|
open class TestBaseWithProfile : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
||||||
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||||
|
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||||
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||||
|
@Mock lateinit var dateUtil: DateUtil
|
||||||
|
@Mock lateinit var configInterface: ConfigInterface
|
||||||
|
|
||||||
|
val rxBus = RxBusWrapper(aapsSchedulers)
|
||||||
|
|
||||||
|
val profileInjector = HasAndroidInjector {
|
||||||
|
AndroidInjector {
|
||||||
|
if (it is Profile) {
|
||||||
|
it.aapsLogger = aapsLogger
|
||||||
|
it.activePlugin = activePluginProvider
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.rxBus = rxBus
|
||||||
|
it.fabricPrivacy = fabricPrivacy
|
||||||
|
it.configInterface = configInterface
|
||||||
|
}
|
||||||
|
if (it is ProfileSwitch) {
|
||||||
|
it.treatmentsPlugin = treatmentsInterface
|
||||||
|
it.aapsLogger = aapsLogger
|
||||||
|
it.rxBus = rxBus
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
it.dateUtil = dateUtil
|
||||||
|
}
|
||||||
|
if (it is Treatment) {
|
||||||
|
it.activePlugin = activePluginProvider
|
||||||
|
it.profileFunction = profileFunction
|
||||||
|
it.defaultValueHelper = defaultValueHelper
|
||||||
|
it.resourceHelper = resourceHelper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private lateinit var validProfileJSON: String
|
||||||
|
lateinit var validProfile: Profile
|
||||||
|
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun prepareMock() {
|
||||||
|
validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
|
validProfile = Profile(profileInjector, JSONObject(validProfileJSON), Constants.MGDL)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getValidProfileStore(): ProfileStore {
|
||||||
|
val json = JSONObject()
|
||||||
|
val store = JSONObject()
|
||||||
|
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
|
||||||
|
json.put("defaultProfile", TESTPROFILENAME)
|
||||||
|
json.put("store", store)
|
||||||
|
return ProfileStore(profileInjector, json)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package info.nightscout.androidaps.dana
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
class DanaPumpTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
|
@Mock lateinit var sp: SP
|
||||||
|
|
||||||
|
private lateinit var sut: DanaPump
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
sut = DanaPump(aapsLogger, sp, profileInjector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun detectDanaRS() {
|
||||||
|
sut.hwModel = 0x05
|
||||||
|
Assert.assertTrue(sut.modelFriendlyName().contains("DanaRS"))
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import static org.junit.Assert.assertArrayEquals;
|
||||||
public class SetUniqueIdCommandTest {
|
public class SetUniqueIdCommandTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEncoding() throws DecoderException {
|
public void testEncoding() throws DecoderException {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
byte[] encoded = new SetUniqueIdCommand(37879811, (short) 6, 135556289, 681767, new Date(2021, 1, 10, 14, 41), false) //
|
byte[] encoded = new SetUniqueIdCommand(37879811, (short) 6, 135556289, 681767, new Date(2021, 1, 10, 14, 41), false) //
|
||||||
.getEncoded();
|
.getEncoded();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue