From 22dfea652d5bc1115607251bd0f5172cfe5dd09f Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 6 Apr 2021 23:58:54 +0200 Subject: [PATCH] RRemove unused injection and try to fix tests... It works for LoopPluginTest, but not for ClassicPrefsFormatTest as many other... (don't know if it's my config or not) --- .../androidaps/plugins/aps/loop/LoopPluginTest.kt | 6 ++++-- .../maintenance/formats/ClassicPrefsFormat.kt | 6 ------ .../maintenance/formats/ClassicPrefsFormatTest.kt | 12 +++--------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt index ff7321cd4f..8d40547190 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt @@ -9,6 +9,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration @@ -30,7 +31,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class, RunningConfiguration::class) +@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class, RunningConfiguration::class, UserEntryLogger::class) class LoopPluginTest : TestBase() { @Mock lateinit var sp: SP @@ -48,6 +49,7 @@ class LoopPluginTest : TestBase() { @Mock lateinit var receiverStatusStore: ReceiverStatusStore @Mock lateinit var notificationManager: NotificationManager @Mock lateinit var repository: AppRepository + @Mock lateinit var uel:UserEntryLogger @Mock lateinit var dateUtil: DateUtil @Mock lateinit var runningConfiguration: RunningConfiguration @@ -56,7 +58,7 @@ class LoopPluginTest : TestBase() { val injector = HasAndroidInjector { AndroidInjector { } } @Before fun prepareMock() { - loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, repository, runningConfiguration) + loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, uel, repository, runningConfiguration) `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager) } diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt index 03a1ee69a6..83d699015d 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt @@ -3,9 +3,6 @@ package info.nightscout.androidaps.plugins.general.maintenance.formats import info.nightscout.androidaps.Constants import info.nightscout.androidaps.core.R import info.nightscout.androidaps.database.entities.UserEntry -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.storage.Storage @@ -18,9 +15,6 @@ import javax.inject.Singleton @Singleton class ClassicPrefsFormat @Inject constructor( private var resourceHelper: ResourceHelper, - private var dateUtil: DateUtil, - private var translator: Translator, - private var profileFunction: ProfileFunction, private var userEntryPresentationHelper: UserEntryPresentationHelper, private var storage: Storage ) : PrefsFormat { diff --git a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt index 89634c179f..ae55f7ede9 100644 --- a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt @@ -1,9 +1,6 @@ package info.nightscout.androidaps.plugins.general.maintenance.formats import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert @@ -16,13 +13,10 @@ import org.powermock.modules.junit4.PowerMockRunner import java.io.File @RunWith(PowerMockRunner::class) -@PrepareForTest(File::class, Translator::class) +@PrepareForTest(File::class, UserEntryPresentationHelper::class) class ClassicPrefsFormatTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper - @Mock lateinit var dateUtil: DateUtil - @Mock lateinit var translator: Translator - @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var userEntryPresentationHelper: UserEntryPresentationHelper @Mock lateinit var file: MockedFile @@ -30,7 +24,7 @@ class ClassicPrefsFormatTest : TestBase() { fun preferenceLoadingTest() { val test = "key1::val1\nkeyB::valB" - val classicFormat = ClassicPrefsFormat(resourceHelper, dateUtil, translator, profileFunction, userEntryPresentationHelper, SingleStringStorage(test)) + val classicFormat = ClassicPrefsFormat(resourceHelper, userEntryPresentationHelper, SingleStringStorage(test)) val prefs = classicFormat.loadPreferences(getMockedFile(), "") Assert.assertEquals(prefs.values.size, 2) @@ -42,7 +36,7 @@ class ClassicPrefsFormatTest : TestBase() { @Test fun preferenceSavingTest() { val storage = SingleStringStorage("") - val classicFormat = ClassicPrefsFormat(resourceHelper, dateUtil, translator, profileFunction, userEntryPresentationHelper, storage) + val classicFormat = ClassicPrefsFormat(resourceHelper, userEntryPresentationHelper, storage) val prefs = Prefs( mapOf( "key1" to "A",