ObjectivesPluginTest
This commit is contained in:
parent
89d1de9710
commit
e8819897f3
4 changed files with 94 additions and 95 deletions
|
@ -146,37 +146,37 @@ class ObjectivesPlugin @Inject constructor(
|
|||
*/
|
||||
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[FIRST_OBJECTIVE].isStarted)
|
||||
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, FIRST_OBJECTIVE + 1), this)
|
||||
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted)
|
||||
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
|
||||
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[AUTOSENS_OBJECTIVE].isStarted)
|
||||
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTOSENS_OBJECTIVE + 1), this)
|
||||
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isAMAModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[AMA_OBJECTIVE].isStarted)
|
||||
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AMA_OBJECTIVE + 1), this)
|
||||
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!objectives[SMB_OBJECTIVE].isStarted)
|
||||
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, SMB_OBJECTIVE + 1), this)
|
||||
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
|
||||
if (objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted && !objectives[MAXIOB_ZERO_CL_OBJECTIVE].isAccomplished)
|
||||
maxIob.set(aapsLogger, 0.0, resourceHelper.gs(R.string.objectivenotfinished, MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
|
||||
maxIob.set(aapsLogger, 0.0, String.format(resourceHelper.gs(R.string.objectivenotfinished), MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
|
||||
return maxIob
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
|||
|
||||
public abstract class Objective {
|
||||
@Inject public SP sp;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
@Inject public ResourceHelper resourceHelper;
|
||||
|
||||
private String spName;
|
||||
@StringRes private int objective;
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.objectives;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 23.03.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class})
|
||||
public class ObjectivesPluginTest {
|
||||
|
||||
ObjectivesPlugin objectivesPlugin;
|
||||
|
||||
@Test
|
||||
public void notStartedObjectivesShouldLimitLoopInvocation() {
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getFIRST_OBJECTIVE()).setStartedOn(0);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isLoopInvocationAllowed(c);
|
||||
Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons());
|
||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getFIRST_OBJECTIVE()).setStartedOn(DateUtil.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notStartedObjective6ShouldLimitClosedLoop() {
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getMAXIOB_ZERO_CL_OBJECTIVE()).setStartedOn(0);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isClosedLoopAllowed(c);
|
||||
Assert.assertEquals(true, c.getReasons().contains("Objective 6 not started"));
|
||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notStartedObjective8ShouldLimitAutosensMode() {
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getAUTOSENS_OBJECTIVE()).setStartedOn(0);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isAutosensModeEnabled(c);
|
||||
Assert.assertEquals(true, c.getReasons().contains("Objective 8 not started"));
|
||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notStartedObjective9ShouldLimitAMAMode() {
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getAMA_OBJECTIVE()).setStartedOn(0);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isAMAModeEnabled(c);
|
||||
Assert.assertEquals(true, c.getReasons().contains("Objective 9 not started"));
|
||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notStartedObjective10ShouldLimitSMBMode() {
|
||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getSMB_OBJECTIVE()).setStartedOn(0);
|
||||
|
||||
Constraint<Boolean> c = new Constraint<>(true);
|
||||
c = objectivesPlugin.isSMBModeEnabled(c);
|
||||
Assert.assertEquals(true, c.getReasons().contains("Objective 10 not started"));
|
||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepareMock() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockStrings();
|
||||
|
||||
objectivesPlugin = ObjectivesPlugin.INSTANCE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.objectives
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
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.`when`
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class ObjectivesPluginTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||
@Mock lateinit var sp: SP
|
||||
|
||||
private lateinit var objectivesPlugin: ObjectivesPlugin
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Objective) {
|
||||
it.sp = sp
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before fun prepareMock() {
|
||||
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp)
|
||||
objectivesPlugin.onStart()
|
||||
`when`(resourceHelper.gs(R.string.objectivenotstarted)).thenReturn("Objective %1\$d not started")
|
||||
}
|
||||
|
||||
@Test fun notStartedObjectivesShouldLimitLoopInvocation() {
|
||||
objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].startedOn = 0
|
||||
var c = Constraint(true)
|
||||
c = objectivesPlugin.isLoopInvocationAllowed(c)
|
||||
Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons(aapsLogger))
|
||||
Assert.assertEquals(false, c.value())
|
||||
objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].startedOn = DateUtil.now()
|
||||
}
|
||||
|
||||
@Test fun notStartedObjective6ShouldLimitClosedLoop() {
|
||||
objectivesPlugin.objectives[ObjectivesPlugin.MAXIOB_ZERO_CL_OBJECTIVE].startedOn = 0
|
||||
var c = Constraint(true)
|
||||
c = objectivesPlugin.isClosedLoopAllowed(c)
|
||||
Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 6 not started"))
|
||||
Assert.assertEquals(false, c.value())
|
||||
}
|
||||
|
||||
@Test fun notStartedObjective8ShouldLimitAutosensMode() {
|
||||
objectivesPlugin.objectives[ObjectivesPlugin.AUTOSENS_OBJECTIVE].startedOn = 0
|
||||
var c = Constraint(true)
|
||||
c = objectivesPlugin.isAutosensModeEnabled(c)
|
||||
Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 8 not started"))
|
||||
Assert.assertEquals(false, c.value())
|
||||
}
|
||||
|
||||
@Test fun notStartedObjective9ShouldLimitAMAMode() {
|
||||
objectivesPlugin.objectives[ObjectivesPlugin.AMA_OBJECTIVE].startedOn = 0
|
||||
var c = Constraint(true)
|
||||
c = objectivesPlugin.isAMAModeEnabled(c)
|
||||
Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 9 not started"))
|
||||
Assert.assertEquals(false, c.value())
|
||||
}
|
||||
|
||||
@Test fun notStartedObjective10ShouldLimitSMBMode() {
|
||||
objectivesPlugin.objectives[ObjectivesPlugin.SMB_OBJECTIVE].startedOn = 0
|
||||
var c = Constraint(true)
|
||||
c = objectivesPlugin.isSMBModeEnabled(c)
|
||||
Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 10 not started"))
|
||||
Assert.assertEquals(false, c.value())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue