Logging in tests

This commit is contained in:
Milos Kozak 2020-03-31 15:49:57 +02:00
parent 416f5b7cab
commit 7e6501bded
32 changed files with 86 additions and 52 deletions

View file

@ -0,0 +1,60 @@
package info.nightscout.androidaps.logging
/**
* Created by adrian on 2019-12-27.
*/
class AAPSLoggerTest : AAPSLogger {
override fun debug(message: String) {
println("DEBUG: $message")
}
override fun debug(enable: Boolean, tag: LTag, message: String) {
println("DEBUG: " + message)
}
override fun debug(tag: LTag, message: String) {
println("DEBUG: : " + tag.tag + " " + message)
}
override fun debug(tag: LTag, format: String, vararg arguments: Any?) {
println("DEBUG: : " + tag.tag + " " + String.format(format, arguments))
}
override fun warn(tag: LTag, message: String) {
println("WARN: " + tag.tag + " " + message)
}
override fun info(tag: LTag, message: String) {
println("INFO: " + tag.tag + " " + message)
}
override fun info(tag: LTag, format: String, vararg arguments: Any?) {
println("INFO: : " + tag.tag + " " + String.format(format, arguments))
}
override fun error(tag: LTag, message: String) {
println("ERROR: " + tag.tag + " " + message)
}
override fun error(message: String) {
println("ERROR: " + message)
}
override fun error(message: String, throwable: Throwable) {
println("ERROR: " + message + " " + throwable)
}
override fun error(format: String, vararg arguments: Any?) {
println("ERROR: : " + String.format(format, arguments))
}
override fun error(tag: LTag, message: String, throwable: Throwable) {
println("ERROR: " + tag.tag + " " + message + " " + throwable)
}
override fun error(tag: LTag, format: String, vararg arguments: Any?) {
println("ERROR: : " + tag.tag + " " + String.format(format, arguments))
}
}

View file

@ -1,30 +1,30 @@
package info.nightscout.androidaps.logging package info.nightscout.androidaps.logging
enum class LTag(val tag: String, val defaultValue : Boolean = false, val requiresRestart: Boolean = false) { enum class LTag(val tag: String, val defaultValue : Boolean = true, val requiresRestart: Boolean = false) {
CORE("CORE", defaultValue = false), CORE("CORE"),
APS("APS", defaultValue = false), APS("APS"),
AUTOSENS("AUTOSENS"), AUTOSENS("AUTOSENS", defaultValue = false),
AUTOMATION("AUTOMATION", defaultValue = false), AUTOMATION("AUTOMATION"),
BGSOURCE("BGSOURCE", defaultValue = false), BGSOURCE("BGSOURCE"),
CONFIGBUILDER("CONFIGBUILDER"), CONFIGBUILDER("CONFIGBUILDER"),
CONSTRAINTS("CONSTRAINTS", defaultValue = false), CONSTRAINTS("CONSTRAINTS"),
DATABASE("DATABASE", defaultValue = false), DATABASE("DATABASE"),
DATAFOOD("DATAFOOD"), DATAFOOD("DATAFOOD", defaultValue = false),
DATASERVICE("DATASERVICE", defaultValue = false), DATASERVICE("DATASERVICE"),
DATATREATMENTS("DATATREATMENTS", defaultValue = false), DATATREATMENTS("DATATREATMENTS"),
EVENTS("EVENTS", defaultValue = false, requiresRestart = true), EVENTS("EVENTS", defaultValue = false, requiresRestart = true),
GLUCOSE("GLUCOSE"), GLUCOSE("GLUCOSE"),
LOCATION("LOCATION", defaultValue = false), LOCATION("LOCATION"),
NOTIFICATION("NOTIFICATION", defaultValue = false), NOTIFICATION("NOTIFICATION"),
NSCLIENT("NSCLIENT", defaultValue = false), NSCLIENT("NSCLIENT"),
OVERVIEW("OVERVIEW", defaultValue = false), OVERVIEW("OVERVIEW", defaultValue = false),
PUMP("PUMP", defaultValue = false), PUMP("PUMP"),
PUMPBTCOMM("PUMPBTCOMM"), PUMPBTCOMM("PUMPBTCOMM", defaultValue = false),
PUMPCOMM("PUMPCOMM", defaultValue = false), PUMPCOMM("PUMPCOMM"),
PUMPQUEUE("PUMPQUEUE", defaultValue = false), PUMPQUEUE("PUMPQUEUE"),
PROFILE("PROFILE", defaultValue = false), PROFILE("PROFILE"),
SMS("SMS", defaultValue = false), SMS("SMS"),
TIDEPOOL("TIDEPOOL"), TIDEPOOL("TIDEPOOL"),
UI("UI", defaultValue = false), UI("UI", defaultValue = false),
WEAR("WEAR") WEAR("WEAR", defaultValue = false)
} }

View file

@ -4,6 +4,7 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.logging.AAPSLoggerTest
import org.json.JSONObject import org.json.JSONObject
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@ -13,6 +14,9 @@ import org.mockito.junit.MockitoRule
import java.util.* import java.util.*
open class TestBase { open class TestBase {
val aapsLogger = AAPSLoggerTest()
// Add a JUnit rule that will setup the @Mock annotated vars and log. // 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. // Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule @get:Rule

View file

@ -7,6 +7,7 @@ import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.db.ProfileSwitch import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.AAPSLoggerTest
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
@ -18,7 +19,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest
@PrepareForTest(FabricPrivacy::class) @PrepareForTest(FabricPrivacy::class)
open class TestBaseWithProfile : TestBase() { open class TestBaseWithProfile : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var activePluginProvider: ActivePluginProvider @Mock lateinit var activePluginProvider: ActivePluginProvider
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var treatmentsPlugin: TreatmentsPlugin

View file

@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(Profile::class) @PrepareForTest(Profile::class)
class QuickWizardTest : TestBase() { class QuickWizardTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var treatmentsPlugin: TreatmentsPlugin

View file

@ -30,7 +30,6 @@ import java.util.logging.Logger
@PrepareForTest(MainApp::class, Logger::class, L::class, SP::class, GlucoseStatus::class) @PrepareForTest(MainApp::class, Logger::class, L::class, SP::class, GlucoseStatus::class)
class BgReadingTest : TestBase() { class BgReadingTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper

View file

@ -19,8 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(MainApp::class, SP::class) @PrepareForTest(MainApp::class, SP::class)
class ConstraintTest : TestBase() { class ConstraintTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Test fun doTests() { @Test fun doTests() {
val b = Constraint(true) val b = Constraint(true)
Assert.assertEquals(true, b.value()) Assert.assertEquals(true, b.value())

View file

@ -33,7 +33,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class) @PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class)
class LoopPluginTest : TestBase() { class LoopPluginTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
private val rxBus: RxBusWrapper = RxBusWrapper() private val rxBus: RxBusWrapper = RxBusWrapper()
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker

View file

@ -25,7 +25,6 @@ class ConfigBuilderPluginTest : TestBase() {
@Mock lateinit var treatmentsPlugin: Lazy<TreatmentsPlugin> @Mock lateinit var treatmentsPlugin: Lazy<TreatmentsPlugin>
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider

View file

@ -22,7 +22,6 @@ import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class DstHelperPluginTest : TestBase() { class DstHelperPluginTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider

View file

@ -22,7 +22,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class ObjectivesPluginTest : TestBase() { class ObjectivesPluginTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var sp: SP @Mock lateinit var sp: SP

View file

@ -13,7 +13,6 @@ import org.junit.Test
import org.mockito.Mock import org.mockito.Mock
class SignatureVerifierPluginTest : TestBase() { class SignatureVerifierPluginTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var context: Context @Mock lateinit var context: Context

View file

@ -20,7 +20,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class StorageConstraintPluginTest : TestBase() { class StorageConstraintPluginTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
private val rxBusWrapper = RxBusWrapper() private val rxBusWrapper = RxBusWrapper()

View file

@ -15,7 +15,6 @@ class VersionCheckerUtilsKtTest : TestBase() {
lateinit var versionCheckerUtils: VersionCheckerUtils lateinit var versionCheckerUtils: VersionCheckerUtils
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var context: Context @Mock lateinit var context: Context

View file

@ -21,7 +21,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class AutomationEventTest : TestBase() { class AutomationEventTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var loopPlugin: LoopPlugin @Mock lateinit var loopPlugin: LoopPlugin
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin @Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin

View file

@ -27,7 +27,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(NSUpload::class, RxBusWrapper::class) @PrepareForTest(NSUpload::class, RxBusWrapper::class)
class ActionNotificationTest : TestBase() { class ActionNotificationTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper

View file

@ -26,7 +26,6 @@ class MaintenancePluginTest : TestBase() {
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var nsSettingsStatus: NSSettingsStatus @Mock lateinit var nsSettingsStatus: NSSettingsStatus
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var buildHelper: BuildHelper @Mock lateinit var buildHelper: BuildHelper
lateinit var sut: MaintenancePlugin lateinit var sut: MaintenancePlugin

View file

@ -32,7 +32,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(MainApp::class, SP::class, Context::class) @PrepareForTest(MainApp::class, SP::class, Context::class)
class NsClientReceiverDelegateTest : TestBase() { class NsClientReceiverDelegateTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper

View file

@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(SmsCommunicatorPlugin::class, DateUtil::class, OneTimePassword::class) @PrepareForTest(SmsCommunicatorPlugin::class, DateUtil::class, OneTimePassword::class)
class AuthRequestTest : TestBase() { class AuthRequestTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin @Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var otp: OneTimePassword @Mock lateinit var otp: OneTimePassword

View file

@ -30,7 +30,6 @@ class InsulinOrefFreePeakPluginTest : TestBase() {
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var aapsLogger: AAPSLogger
private var injector: HasAndroidInjector = HasAndroidInjector { private var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector { AndroidInjector {

View file

@ -30,7 +30,6 @@ import java.util.*
@PrepareForTest(IobCobCalculatorPlugin::class, DateUtil::class) @PrepareForTest(IobCobCalculatorPlugin::class, DateUtil::class)
class GlucoseStatusTest : TestBase() { class GlucoseStatusTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin @Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
val injector = HasAndroidInjector { val injector = HasAndroidInjector {

View file

@ -32,7 +32,6 @@ import java.util.*
@PrepareForTest(FabricPrivacy::class) @PrepareForTest(FabricPrivacy::class)
class IobCobCalculatorPluginTest : TestBase() { class IobCobCalculatorPluginTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
private val rxBus: RxBusWrapper = RxBusWrapper() private val rxBus: RxBusWrapper = RxBusWrapper()
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper

View file

@ -33,7 +33,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, Context::class, CommandQueue::class) @PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, Context::class, CommandQueue::class)
class ComboPluginTest : TestBase() { class ComboPluginTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker

View file

@ -14,8 +14,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class DetailedBolusInfoStorageTest : TestBase() { class DetailedBolusInfoStorageTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
private val info1 = DetailedBolusInfo() private val info1 = DetailedBolusInfo()
private val info2 = DetailedBolusInfo() private val info2 = DetailedBolusInfo()
private val info3 = DetailedBolusInfo() private val info3 = DetailedBolusInfo()

View file

@ -10,7 +10,6 @@ import org.mockito.Mock
open class DanaRTestBase : TestBase() { open class DanaRTestBase : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var injector: HasAndroidInjector @Mock lateinit var injector: HasAndroidInjector

View file

@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(FabricPrivacy::class) @PrepareForTest(FabricPrivacy::class)
class VirtualPumpPluginUTest : TestBase() { class VirtualPumpPluginUTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
val rxBus = RxBusWrapper() val rxBus = RxBusWrapper()
@Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper

View file

@ -19,7 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner
class AbstractSensitivityPluginTest : TestBase() { class AbstractSensitivityPluginTest : TestBase() {
@Mock lateinit var pluginDescription: PluginDescription @Mock lateinit var pluginDescription: PluginDescription
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP @Mock lateinit var sp: SP

View file

@ -13,7 +13,6 @@ import org.mockito.Mock
class GlimpPluginTest : TestBase() { class GlimpPluginTest : TestBase() {
private lateinit var glimpPlugin: GlimpPlugin private lateinit var glimpPlugin: GlimpPlugin
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Before @Before

View file

@ -17,7 +17,6 @@ class MM640GPluginTest : TestBase() {
private lateinit var mM640gPlugin: MM640gPlugin private lateinit var mM640gPlugin: MM640gPlugin
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Before @Before

View file

@ -18,7 +18,6 @@ class NSClientPluginTest : TestBase() {
private lateinit var nsClientSourcePlugin: NSClientSourcePlugin private lateinit var nsClientSourcePlugin: NSClientSourcePlugin
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP @Mock lateinit var sp: SP

View file

@ -17,7 +17,6 @@ class XdripPluginTest : TestBase() {
private lateinit var xdripPlugin: XdripPlugin private lateinit var xdripPlugin: XdripPlugin
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Before @Before

View file

@ -37,7 +37,6 @@ class BolusWizardTest : TestBase() {
private val PUMP_BOLUS_STEP = 0.1 private val PUMP_BOLUS_STEP = 0.1
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker