ActionLoopDisableTest
This commit is contained in:
parent
5c89c8eb26
commit
8799c30b8e
4 changed files with 63 additions and 53 deletions
|
@ -2,18 +2,18 @@ package info.nightscout.androidaps.data;
|
|||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.Round;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
|
||||
public class PumpEnactResult {
|
||||
private static Logger log = StacktraceLoggerWrapper.getLogger(L.APS);
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
|
||||
public boolean success = false; // request was processed successfully (but possible no change was needed)
|
||||
public boolean enacted = false; // request was processed successfully and change has been made
|
||||
|
@ -47,7 +47,7 @@ public class PumpEnactResult {
|
|||
}
|
||||
|
||||
public PumpEnactResult comment(int comment) {
|
||||
this.comment = MainApp.gs(comment);
|
||||
this.comment = resourceHelper.gs(comment);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -106,66 +106,66 @@ public class PumpEnactResult {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
String ret = MainApp.gs(R.string.success) + ": " + success;
|
||||
String ret = resourceHelper.gs(R.string.success) + ": " + success;
|
||||
if (enacted) {
|
||||
if (bolusDelivered > 0) {
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.configbuilder_insulin)
|
||||
+ ": " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname);
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.configbuilder_insulin)
|
||||
+ ": " + bolusDelivered + " " + resourceHelper.gs(R.string.insulin_unit_shortname);
|
||||
} else if (isTempCancel) {
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.canceltemp);
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.canceltemp);
|
||||
} else if (isPercent) {
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + MainApp.gs(R.string.percent) + ": " + percent + "%";
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + resourceHelper.gs(R.string.percent) + ": " + percent + "%";
|
||||
} else {
|
||||
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + MainApp.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + MainApp.gs(R.string.absolute) + ": " + absolute + " U/h";
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + resourceHelper.gs(R.string.absolute) + ": " + absolute + " U/h";
|
||||
}
|
||||
} else {
|
||||
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toHtml() {
|
||||
String ret = "<b>" + MainApp.gs(R.string.success) + "</b>: " + success;
|
||||
String ret = "<b>" + resourceHelper.gs(R.string.success) + "</b>: " + success;
|
||||
if (queued) {
|
||||
ret = MainApp.gs(R.string.waitingforpumpresult);
|
||||
ret = resourceHelper.gs(R.string.waitingforpumpresult);
|
||||
} else if (enacted) {
|
||||
if (bolusDelivered > 0) {
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname);
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + resourceHelper.gs(R.string.insulin_unit_shortname);
|
||||
} else if (isTempCancel) {
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment +
|
||||
"<br>" + MainApp.gs(R.string.canceltemp);
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment +
|
||||
"<br>" + resourceHelper.gs(R.string.canceltemp);
|
||||
} else if (isPercent && percent != -1) {
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + MainApp.gs(R.string.percent) + "</b>: " + percent + "%";
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.percent) + "</b>: " + percent + "%";
|
||||
} else if (absolute != -1) {
|
||||
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + MainApp.gs(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h";
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h";
|
||||
}
|
||||
} else {
|
||||
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ public class PumpEnactResult {
|
|||
result.put("duration", duration);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import dagger.android.AndroidInjectionModule
|
|||
import dagger.android.AndroidInjector
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.data.ProfileStore
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.db.BgReading
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.*
|
||||
|
@ -38,6 +39,7 @@ import javax.inject.Singleton
|
|||
interface AppComponent : AndroidInjector<MainApp> {
|
||||
|
||||
fun injectProfileStore(profileStore: ProfileStore)
|
||||
fun injectPumpEnactResult(pumpEnactResult: PumpEnactResult)
|
||||
|
||||
fun injectCommandQueue(commandQueue: CommandQueue)
|
||||
fun injectCommandBolus(commandBolus: CommandBolus)
|
||||
|
|
|
@ -10,6 +10,7 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.BuildConfig
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.data.ProfileStore
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.db.BgReading
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
|
@ -78,6 +79,8 @@ open class AppModule {
|
|||
|
||||
@ContributesAndroidInjector fun profileStoreInjector(): ProfileStore
|
||||
|
||||
@ContributesAndroidInjector fun pumpEnactResultInjector(): PumpEnactResult
|
||||
|
||||
@ContributesAndroidInjector fun commandQueueInjector(): CommandQueue
|
||||
@ContributesAndroidInjector fun commandBolusInjector(): CommandBolus
|
||||
@ContributesAndroidInjector
|
||||
|
|
|
@ -25,24 +25,23 @@ 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.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class)
|
||||
class ActionLoopDisableTest : TestBase() {
|
||||
|
||||
@Mock lateinit var rxBus: RxBusWrapper
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
||||
@Mock lateinit var lazyActionStringHandler: Lazy<ActionStringHandler>
|
||||
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
@Mock lateinit var loopPlugin: LoopPlugin
|
||||
|
||||
lateinit var sut: ActionLoopDisable
|
||||
|
@ -54,6 +53,8 @@ class ActionLoopDisableTest : TestBase() {
|
|||
val pumpDescription = PumpDescription().apply { isTempBasalCapable = true }
|
||||
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
||||
`when`(configBuilderPlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||
`when`(resourceHelper.gs(R.string.disableloop)).thenReturn("Disable loop")
|
||||
`when`(resourceHelper.gs(R.string.alreadydisabled)).thenReturn("Disable loop")
|
||||
|
||||
sut = ActionLoopDisable(HasAndroidInjector { AndroidInjector { Unit } }) // do nothing injector
|
||||
.also { // inject the mocks
|
||||
|
@ -65,19 +66,23 @@ class ActionLoopDisableTest : TestBase() {
|
|||
}
|
||||
}
|
||||
|
||||
@Test fun friendlyNameTest() {
|
||||
@Test
|
||||
fun friendlyNameTest() {
|
||||
Assert.assertEquals(R.string.disableloop.toLong(), sut.friendlyName().toLong())
|
||||
}
|
||||
|
||||
@Test fun shortDescriptionTest() {
|
||||
@Test
|
||||
fun shortDescriptionTest() {
|
||||
Assert.assertEquals("Disable loop", sut.shortDescription())
|
||||
}
|
||||
|
||||
@Test fun iconTest() {
|
||||
Assert.assertEquals(Optional.of(R.drawable.ic_stop_24dp), sut.icon())
|
||||
@Test
|
||||
fun iconTest() {
|
||||
Assert.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
|
||||
}
|
||||
|
||||
@Test fun doActionTest() {
|
||||
@Test
|
||||
fun doActionTest() {
|
||||
sut.doAction(object : Callback() {
|
||||
override fun run() {}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue