Merge branch 'dev' into wip

This commit is contained in:
Milos Kozak 2018-03-31 00:39:35 +02:00
commit 3b3662af80
9 changed files with 280 additions and 102 deletions

View file

@ -21,19 +21,19 @@ public class PumpEnactResult {
public String comment = "";
// Result of basal change
public Integer duration = -1; // duration set [minutes]
public int duration = -1; // duration set [minutes]
public double absolute = -1d; // absolute rate [U/h] , isPercent = false
public int percent = -1; // percent of current basal [%] (100% = current basal), isPercent = true
public boolean isPercent = false; // if true percent is used, otherwise absolute
public boolean isTempCancel = false; // if true we are caceling temp basal
// Result of treatment delivery
public Double bolusDelivered = 0d; // real value of delivered insulin
public Double carbsDelivered = 0d; // real value of delivered carbs
public double bolusDelivered = 0d; // real value of delivered insulin
public double carbsDelivered = 0d; // real value of delivered carbs
public boolean queued = false;
public PumpEnactResult success(boolean success) {
this.success = success;
this.success = success;
return this;
}
@ -87,76 +87,83 @@ public class PumpEnactResult {
return this;
}
public String log() {
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
public String log() {
return "Success: " + success +
" Enacted: " + enacted +
" Comment: " + comment +
" Duration: " + duration +
" Absolute: " + absolute +
" Percent: " + percent +
" IsPercent: " + isPercent +
" IsTempCancel: " + isTempCancel +
" bolusDelivered: " + bolusDelivered +
" carbsDelivered: " + carbsDelivered +
" Queued: " + queued;
}
public String toString() {
String ret = MainApp.sResources.getString(R.string.success) + ": " + success;
String ret = MainApp.gs(R.string.success) + ": " + success;
if (enacted) {
if (bolusDelivered > 0) {
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
ret += "\n" + MainApp.sResources.getString(R.string.smb_shortname)
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
ret += "\n" + MainApp.gs(R.string.smb_shortname)
+ ": " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname);
} else if (isTempCancel) {
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
if (!comment.isEmpty())
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
ret += MainApp.sResources.getString(R.string.canceltemp);
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
ret += "\n" + MainApp.gs(R.string.canceltemp);
} else if (isPercent) {
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
if (!comment.isEmpty())
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min";
ret += "\n" + MainApp.sResources.getString(R.string.percent) + ": " + percent + "%";
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 + "%";
} else {
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.gs(R.string.enacted) + ": " + enacted;
if (!comment.isEmpty())
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
ret += "\n" + MainApp.sResources.getString(R.string.duration) + ": " + duration + " min";
ret += "\n" + MainApp.sResources.getString(R.string.absolute) + ": " + absolute + " U/h";
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";
}
} else {
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
ret += "\n" + MainApp.gs(R.string.comment) + ": " + comment;
}
return ret;
}
public Spanned toSpanned() {
String ret = "<b>" + MainApp.sResources.getString(R.string.success) + "</b>: " + success;
public String toHtml() {
String ret = "<b>" + MainApp.gs(R.string.success) + "</b>: " + success;
if (queued) {
ret = MainApp.sResources.getString(R.string.waitingforpumpresult);
ret = MainApp.gs(R.string.waitingforpumpresult);
} else if (enacted) {
if (bolusDelivered > 0) {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
if (!comment.isEmpty())
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
ret += "<br><b>" + MainApp.sResources.getString(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname);
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);
} else if (isTempCancel) {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment +
"<br>" + MainApp.sResources.getString(R.string.canceltemp);
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);
} else if (isPercent && percent != -1) {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
if (!comment.isEmpty())
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
ret += "<br><b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + duration + " min";
ret += "<br><b>" + MainApp.sResources.getString(R.string.percent) + "</b>: " + percent + "%";
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 + "%";
} else if (absolute != -1) {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted;
if (!comment.isEmpty())
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
ret += "<br><b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + duration + " min";
ret += "<br><b>" + MainApp.sResources.getString(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h";
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";
}
} else {
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment;
}
return Html.fromHtml(ret);
}
public PumpEnactResult() {
return ret;
}
public JSONObject json(Profile profile) {

View file

@ -741,21 +741,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
profileSwitch.timeshift = timeshift;
profileSwitch.percentage = percentage;
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
@Override
public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
MainApp.bus().post(new EventNewBasalProfile());
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
}
@ -773,21 +758,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
profileSwitch.timeshift = timeshift;
profileSwitch.percentage = percentage;
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
@Override
public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
MainApp.bus().post(new EventNewBasalProfile());
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
} else {
log.error("No profile switch existing");

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.plugins.ConfigBuilder;
import android.content.Intent;
import android.support.annotation.Nullable;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,6 +33,8 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppInitialized;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.Constraint;
@ -45,6 +49,7 @@ import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
@ -703,6 +708,24 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa
NSUpload.uploadProfileSwitch(profileSwitch);
}
@Subscribe
public void onProfileSwitch(EventProfileSwitchChange ignored) {
getCommandQueue().setProfile(getProfile(), new Callback() {
@Override
public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
MainApp.bus().post(new EventNewBasalProfile());
}
});
}
@Override
public long oldestDataAvailable() {
return activeTreatments.oldestDataAvailable();

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Loop;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -95,8 +96,8 @@ public class LoopFragment extends SubscriberFragment {
sourceView.setText(lastRun.source != null ? lastRun.source : "");
lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : "");
lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : "");
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? lastRun.tbrSetByPump.toSpanned() : "");
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? lastRun.smbSetByPump.toSpanned() : "");
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? Html.fromHtml(lastRun.tbrSetByPump.toHtml()) : "");
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? Html.fromHtml(lastRun.smbSetByPump.toHtml()) : "");
String constraints = "";
if (lastRun.constraintsProcessed != null) {

View file

@ -84,7 +84,7 @@ public class CommandQueue {
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.sResources.getString(R.string.executingrightnow));
}
private boolean isRunning(Command.CommandType type) {
public boolean isRunning(Command.CommandType type) {
if (performing != null && performing.commandType == type)
return true;
return false;
@ -296,21 +296,6 @@ public class CommandQueue {
return false;
}
// Check that there is a valid profileSwitch NOW
if (MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis())==null) {
// wait for DatabaseHelper.scheduleProfiSwitch() to do the profile switch // TODO clean this crap up
SystemClock.sleep(5000);
if (MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis())==null) {
Notification noProfileSwitchNotif = new Notification(Notification.PROFILE_SWITCH_MISSING, MainApp.gs(R.string.profileswitch_ismissing), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(noProfileSwitchNotif));
if (callback != null) {
PumpEnactResult result = new PumpEnactResult().success(false).enacted(false).comment("Refuse to send profile to pump! No ProfileSwitch!");
callback.result(result).run();
}
return false;
}
}
if (!MainApp.isEngineeringModeOrRelease()) {
Notification notification = new Notification(Notification.NOT_ENG_MODE_OR_RELEASE, MainApp.sResources.getString(R.string.not_eng_mode_or_release), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));

View file

@ -18,11 +18,12 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.utils.LocalAlertUtils;
import info.nightscout.utils.SP;
public class KeepAliveReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class);
@ -59,12 +60,12 @@ public class KeepAliveReceiver extends BroadcastReceiver {
LocalAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated);
if (!pump.isThisProfileSet(profile)) {
MainApp.getConfigBuilder().getCommandQueue().setProfile(profile, null);
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
MainApp.bus().post(new EventProfileSwitchChange());
} else if (isStatusOutdated && !pump.isBusy()) {
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
ConfigBuilderPlugin.getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
} else if (isBasalOutdated && !pump.isBusy()) {
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Basal outdated.", null);
ConfigBuilderPlugin.getCommandQueue().readStatus("KeepAlive. Basal outdated.", null);
}
}
}

View file

@ -66,6 +66,16 @@ public class AAPSMocker {
when(MainApp.gs(R.string.short_avgdelta)).thenReturn("Short avg. delta");
when(MainApp.gs(R.string.long_avgdelta)).thenReturn("Long avg. delta");
when(MainApp.gs(R.string.zerovalueinprofile)).thenReturn("Invalid profile: %s");
when(MainApp.gs(R.string.success)).thenReturn("Success");
when(MainApp.gs(R.string.enacted)).thenReturn("Enacted");
when(MainApp.gs(R.string.comment)).thenReturn("Comment");
when(MainApp.gs(R.string.smb_shortname)).thenReturn("SMB");
when(MainApp.gs(R.string.canceltemp)).thenReturn("Cancel temp basal");
when(MainApp.gs(R.string.duration)).thenReturn("Duration");
when(MainApp.gs(R.string.percent)).thenReturn("Percent");
when(MainApp.gs(R.string.absolute)).thenReturn("Absolute");
when(MainApp.gs(R.string.waitingforpumpresult)).thenReturn("Waiting for result");
when(MainApp.gs(R.string.insulin_unit_shortname)).thenReturn("U");
}
public static MainApp mockMainApp() {

View file

@ -0,0 +1,182 @@
package info.nightscout.androidaps.data;
import android.text.Html;
import android.text.Spanned;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.skyscreamer.jsonassert.JSONAssert;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import static org.mockito.ArgumentMatchers.anyString;
import static org.powermock.api.mockito.PowerMockito.when;
/**
* Created by mike on 29.03.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, Html.class})
public class PumpEnactResultTest {
PumpEnactResult per = new PumpEnactResult();
@Test
public void successTest() throws Exception {
per.success(true);
Assert.assertEquals(true, per.success);
}
@Test
public void enactedTest() throws Exception {
per.enacted(true);
Assert.assertEquals(true, per.enacted);
}
@Test
public void commentTest() throws Exception {
per.comment("SomeComment");
Assert.assertEquals("SomeComment", per.comment);
}
@Test
public void durationTest() throws Exception {
per.duration(10);
Assert.assertEquals(10, per.duration);
}
@Test
public void absoluteTest() throws Exception {
per.absolute(11d);
Assert.assertEquals(11d, per.absolute, 0.01d);
}
@Test
public void percentTest() throws Exception {
per.percent(10);
Assert.assertEquals((int) 10, per.percent);
}
@Test
public void isPercentTest() throws Exception {
per.isPercent(true);
Assert.assertEquals(true, per.isPercent);
}
@Test
public void isTempCancelTest() throws Exception {
per.isTempCancel(true);
Assert.assertEquals(true, per.isTempCancel);
}
@Test
public void bolusDeliveredTest() throws Exception {
per.bolusDelivered(11d);
Assert.assertEquals(11d, per.bolusDelivered, 0.01d);
}
@Test
public void carbsDeliveredTest() throws Exception {
per.carbsDelivered(11d);
Assert.assertEquals(11d, per.carbsDelivered, 0.01d);
}
@Test
public void queuedTest() throws Exception {
per.queued(true);
Assert.assertEquals(true, per.queued);
}
@Test
public void logTest() throws Exception {
per = new PumpEnactResult();
Assert.assertEquals("Success: false Enacted: false Comment: Duration: -1 Absolute: -1.0 Percent: -1 IsPercent: false IsTempCancel: false bolusDelivered: 0.0 carbsDelivered: 0.0 Queued: false", per.log());
}
@Test
public void toStringTest() throws Exception {
per = new PumpEnactResult().enacted(true).bolusDelivered(10).comment("AAA");
Assert.assertEquals("Success: false\n" +
"Enacted: true\n" +
"Comment: AAA\n" +
"SMB: 10.0 U", per.toString());
per = new PumpEnactResult().enacted(true).isTempCancel(true).comment("AAA");
Assert.assertEquals("Success: false\n" +
"Enacted: true\n" +
"Comment: AAA\n" +
"Cancel temp basal", per.toString());
per = new PumpEnactResult().enacted(true).isPercent(true).percent(90).duration(20).comment("AAA");
Assert.assertEquals("Success: false\n" +
"Enacted: true\n" +
"Comment: AAA\n" +
"Duration: 20 min\n" +
"Percent: 90%", per.toString());
per = new PumpEnactResult().enacted(true).isPercent(false).absolute(1).duration(30).comment("AAA");
Assert.assertEquals("Success: false\n" +
"Enacted: true\n" +
"Comment: AAA\n" +
"Duration: 30 min\n" +
"Absolute: 1.0 U/h", per.toString());
per = new PumpEnactResult().enacted(false).comment("AAA");
Assert.assertEquals("Success: false\n" +
"Comment: AAA", per.toString());
}
@Test
public void toHtmlTest() throws Exception {
per = new PumpEnactResult().enacted(true).bolusDelivered(10).comment("AAA");
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>SMB</b>: 10.0 U", per.toHtml());
per = new PumpEnactResult().enacted(true).isTempCancel(true).comment("AAA");
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br>Cancel temp basal", per.toHtml());
per = new PumpEnactResult().enacted(true).isPercent(true).percent(90).duration(20).comment("AAA");
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 20 min<br><b>Percent</b>: 90%", per.toHtml());
per = new PumpEnactResult().enacted(true).isPercent(false).absolute(1).duration(30).comment("AAA");
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 30 min<br><b>Absolute</b>: 1.00 U/h", per.toHtml());
per = new PumpEnactResult().enacted(false).comment("AAA");
Assert.assertEquals("<b>Success</b>: false<br><b>Comment</b>: AAA", per.toHtml());
}
@Test
public void jsonTest() throws Exception {
JSONObject o;
per = new PumpEnactResult().enacted(true).bolusDelivered(10).comment("AAA");
o = per.json(AAPSMocker.getValidProfile());
JSONAssert.assertEquals("{\"smb\":10}", o, false);
per = new PumpEnactResult().enacted(true).isTempCancel(true).comment("AAA");
o = per.json(AAPSMocker.getValidProfile());
JSONAssert.assertEquals("{\"rate\":0,\"duration\":0}", o, false);
per = new PumpEnactResult().enacted(true).isPercent(true).percent(90).duration(20).comment("AAA");
o = per.json(AAPSMocker.getValidProfile());
JSONAssert.assertEquals("{\"rate\":0.9,\"duration\":20}", o, false);
per = new PumpEnactResult().enacted(true).isPercent(false).absolute(1).duration(30).comment("AAA");
o = per.json(AAPSMocker.getValidProfile());
JSONAssert.assertEquals("{\"rate\":1,\"duration\":30}", o, false);
}
@Before
public void prepareMock() {
AAPSMocker.mockMainApp();
AAPSMocker.mockStrings();
}
}

View file

@ -88,18 +88,17 @@ public class CommandQueueTest extends CommandQueue {
extendedBolus(1, 30, null);
Assert.assertEquals(2, size());
// add setProfile (command is not queued before unless a ProfileSwitch exists)
// TODO test with profile switch set
// add setProfile
setProfile(profile, null);
Assert.assertEquals(2, size());
Assert.assertEquals(3, size());
// add loadHistory
loadHistory((byte) 0, null);
Assert.assertEquals(3, size());
Assert.assertEquals(4, size());
// add loadEvents
loadEvents(null);
Assert.assertEquals(4, size());
Assert.assertEquals(5, size());
clear();
tempBasalAbsolute(0, 30, true, profile, null);