More tests

This commit is contained in:
Milos Kozak 2020-03-19 18:02:24 +01:00
parent e8af7b5ffc
commit 451cea156f
60 changed files with 392 additions and 554 deletions

View file

@ -14,6 +14,7 @@ import javax.inject.Inject;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
@ -30,10 +31,10 @@ import info.nightscout.androidaps.utils.MidnightTime;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class Profile { public class Profile {
@Inject AAPSLogger aapsLogger; @Inject public AAPSLogger aapsLogger;
@Inject ActivePluginProvider activePlugin; @Inject public ActivePluginProvider activePlugin;
@Inject ResourceHelper resourceHelper; @Inject public ResourceHelper resourceHelper;
@Inject RxBusWrapper rxBus; @Inject public RxBusWrapper rxBus;
private HasAndroidInjector injector; private HasAndroidInjector injector;
@ -58,6 +59,11 @@ public class Profile {
protected boolean isValid; protected boolean isValid;
protected boolean isValidated; protected boolean isValidated;
// Default constructor for DB
public Profile() {
MainApp.instance().injector.androidInjector().inject(this);
}
protected Profile(HasAndroidInjector injector) { protected Profile(HasAndroidInjector injector) {
injector.androidInjector().inject(this); injector.androidInjector().inject(this);
this.injector = injector; this.injector = injector;

View file

@ -1710,7 +1710,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void createProfileSwitchFromJsonIfNotExists(JSONObject trJson) { public void createProfileSwitchFromJsonIfNotExists(JSONObject trJson) {
try { try {
ProfileSwitch profileSwitch = new ProfileSwitch(); ProfileSwitch profileSwitch = new ProfileSwitch(MainApp.instance().injector);
profileSwitch.date = trJson.getLong("mills"); profileSwitch.date = trJson.getLong("mills");
if (trJson.has("duration")) if (trJson.has("duration"))
profileSwitch.durationInMinutes = trJson.getInt("duration"); profileSwitch.durationInMinutes = trJson.getInt("duration");

View file

@ -9,18 +9,19 @@ import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable; import com.j256.ormlite.table.DatabaseTable;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import info.nightscout.androidaps.MainApp; import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries;
@ -30,10 +31,10 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_PROFILESWITCHES) @DatabaseTable(tableName = DatabaseHelper.DATABASE_PROFILESWITCHES)
public class ProfileSwitch implements Interval, DataPointWithLabelInterface { public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATABASE);
@DatabaseField(id = true) @DatabaseField(id = true)
public long date; public long date;
@ -67,6 +68,17 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
private Profile profile = null; private Profile profile = null;
HasAndroidInjector injector;
@Inject public TreatmentsPlugin treatmentsPlugin;
@Inject public AAPSLogger aapsLogger;
@Inject public RxBusWrapper rxBus;
@Inject public ResourceHelper resourceHelper;
public ProfileSwitch(HasAndroidInjector injector) {
injector.androidInjector().inject(this);
this.injector = injector;
}
public ProfileSwitch date(long date) { public ProfileSwitch date(long date) {
this.date = date; this.date = date;
return this; return this;
@ -96,10 +108,10 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
public Profile getProfileObject() { public Profile getProfileObject() {
if (profile == null) if (profile == null)
try { try {
profile = new Profile(MainApp.instance().injector, new JSONObject(profileJson), percentage, timeshift); profile = new Profile(injector, new JSONObject(profileJson), percentage, timeshift);
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e); aapsLogger.error("Unhandled exception", e);
log.error("Unhandled exception", profileJson); aapsLogger.error("Unhandled exception: " + profileJson);
} }
return profile; return profile;
} }
@ -217,7 +229,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
@Override @Override
public boolean isValid() { public boolean isValid() {
boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date)); boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date));
ProfileSwitch active = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now()); ProfileSwitch active = treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now());
long activeProfileSwitchDate = active != null ? active.date : -1L; long activeProfileSwitchDate = active != null ? active.date : -1L;
if (!isValid && date == activeProfileSwitchDate) if (!isValid && date == activeProfileSwitchDate)
createNotificationInvalidProfile(DateUtil.dateAndTimeString(date)); createNotificationInvalidProfile(DateUtil.dateAndTimeString(date));
@ -225,23 +237,23 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
} }
private void createNotificationInvalidProfile(String detail) { private void createNotificationInvalidProfile(String detail) {
Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, String.format(MainApp.gs(R.string.zerovalueinprofile), detail), Notification.LOW, 5); Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, resourceHelper.gs(R.string.zerovalueinprofile, detail), Notification.LOW, 5);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification)); rxBus.send(new EventNewNotification(notification));
} }
public static boolean isEvent5minBack(List<ProfileSwitch> list, long time, boolean zeroDurationOnly) { public static boolean isEvent5minBack(AAPSLogger aapsLogger, List<ProfileSwitch> list, long time, boolean zeroDurationOnly) {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
ProfileSwitch event = list.get(i); ProfileSwitch event = list.get(i);
if (event.date <= time && event.date > (time - T.mins(5).msecs())) { if (event.date <= time && event.date > (time - T.mins(5).msecs())) {
if (zeroDurationOnly) { if (zeroDurationOnly) {
if (event.durationInMinutes == 0) { if (event.durationInMinutes == 0) {
if (L.isEnabled(L.DATABASE)) if (L.isEnabled(L.DATABASE))
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); aapsLogger.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString());
return true; return true;
} }
} else { } else {
if (L.isEnabled(L.DATABASE)) if (L.isEnabled(L.DATABASE))
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); aapsLogger.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString());
return true; return true;
} }
} }

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.db.BgReading
import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.plugins.aps.loop.APSResult import info.nightscout.androidaps.plugins.aps.loop.APSResult
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
import info.nightscout.androidaps.plugins.aps.openAPSMA.DetermineBasalResultMA import info.nightscout.androidaps.plugins.aps.openAPSMA.DetermineBasalResultMA
@ -144,6 +145,7 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectTreatment(treatment: Treatment) fun injectTreatment(treatment: Treatment)
fun injectBgReading(bgReading: BgReading) fun injectBgReading(bgReading: BgReading)
fun injectProfileSwitch(profileSwitch: ProfileSwitch)
fun injectNotification(notificationWithAction: NotificationWithAction) fun injectNotification(notificationWithAction: NotificationWithAction)

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.db.BgReading
import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -59,8 +60,8 @@ open class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideProfileFunction(aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider): ProfileFunction { fun provideProfileFunction(injector: HasAndroidInjector, aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider): ProfileFunction {
return ProfileFunctionImplementation(aapsLogger, sp, resourceHelper, activePlugin) return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin)
} }
@Provides @Provides
@ -198,6 +199,7 @@ open class AppModule {
@ContributesAndroidInjector fun bgReadingInjector(): BgReading @ContributesAndroidInjector fun bgReadingInjector(): BgReading
@ContributesAndroidInjector fun treatmentInjector(): Treatment @ContributesAndroidInjector fun treatmentInjector(): Treatment
@ContributesAndroidInjector fun profileSwitchInjector(): ProfileSwitch
@ContributesAndroidInjector fun notificationWithActionInjector(): NotificationWithAction @ContributesAndroidInjector fun notificationWithActionInjector(): NotificationWithAction

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.configBuilder
import android.os.Bundle import android.os.Bundle
import com.google.firebase.analytics.FirebaseAnalytics import com.google.firebase.analytics.FirebaseAnalytics
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
@ -21,6 +22,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class ProfileFunctionImplementation @Inject constructor( class ProfileFunctionImplementation @Inject constructor(
private val injector: HasAndroidInjector,
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private val sp: SP, private val sp: SP,
private val resourceHelper: ResourceHelper, private val resourceHelper: ResourceHelper,
@ -99,7 +101,7 @@ class ProfileFunctionImplementation @Inject constructor(
override fun prepareProfileSwitch(profileStore: ProfileStore, profileName: String, duration: Int, percentage: Int, timeShift: Int, date: Long): ProfileSwitch { override fun prepareProfileSwitch(profileStore: ProfileStore, profileName: String, duration: Int, percentage: Int, timeShift: Int, date: Long): ProfileSwitch {
val profile = profileStore.getSpecificProfile(profileName) val profile = profileStore.getSpecificProfile(profileName)
?: throw InvalidParameterSpecException(profileName) ?: throw InvalidParameterSpecException(profileName)
val profileSwitch = ProfileSwitch() val profileSwitch = ProfileSwitch(injector)
profileSwitch.date = date profileSwitch.date = date
profileSwitch.source = Source.USER profileSwitch.source = Source.USER
profileSwitch.profileName = profileName profileSwitch.profileName = profileName

View file

@ -50,6 +50,7 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.CareportalEvent;
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.StacktraceLoggerWrapper; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
@ -71,6 +72,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
@Inject HasAndroidInjector injector; @Inject HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger;
@Inject DefaultValueHelper defaultValueHelper; @Inject DefaultValueHelper defaultValueHelper;
@Inject ProfileFunction profileFunction; @Inject ProfileFunction profileFunction;
@Inject ResourceHelper resourceHelper; @Inject ResourceHelper resourceHelper;
@ -80,8 +82,6 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
@Inject TreatmentsPlugin treatmentsPlugin; @Inject TreatmentsPlugin treatmentsPlugin;
@Inject HardLimits hardLimits; @Inject HardLimits hardLimits;
private static Logger log = StacktraceLoggerWrapper.getLogger(NewNSTreatmentDialog.class);
private static OptionsToShow options; private static OptionsToShow options;
private static @StringRes int event; private static @StringRes int event;
@ -182,7 +182,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
profileStore = activePlugin.getActiveProfileInterface().getProfile(); profileStore = activePlugin.getActiveProfileInterface().getProfile();
if (profileStore == null) { if (profileStore == null) {
if (options.eventType == R.id.careportal_profileswitch) { if (options.eventType == R.id.careportal_profileswitch) {
log.error("Profile switch called but plugin doesn't contain valid profile"); aapsLogger.error("Profile switch called but plugin doesn't contain valid profile");
} }
} else { } else {
ArrayList<CharSequence> profileList; ArrayList<CharSequence> profileList;
@ -604,7 +604,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(editSplit.getText())) / 100 / SafeParse.stringToDouble(editDuration.getText()) * 60); data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(editSplit.getText())) / 100 / SafeParse.stringToDouble(editDuration.getText()) * 60);
} }
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error("Unhandled exception", e);
} }
return data; return data;
} }
@ -715,26 +715,10 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O
private void confirmNSTreatmentCreation() { private void confirmNSTreatmentCreation() {
final JSONObject data = gatherData(); final JSONObject data = gatherData();
OKDialog.showConfirmation(getContext(), Translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> createNSTreatment(data)); OKDialog.showConfirmation(getContext(), Translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> NSUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime()));
} }
void createNSTreatment(JSONObject data) {
if (JsonHelper.safeGetString(data, "eventType", "").equals(CareportalEvent.PROFILESWITCH)) {
ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch(
profileStore,
JsonHelper.safeGetString(data, "profile"),
JsonHelper.safeGetInt(data, "duration"),
JsonHelper.safeGetInt(data, "percentage"),
JsonHelper.safeGetInt(data, "timeshift"),
eventTime.getTime()
);
NSUpload.uploadProfileSwitch(profileSwitch);
} else {
NSUpload.uploadCareportalEntryToNS(data);
}
}
@Override @Override
public void onSaveInstanceState(Bundle savedInstanceState) { public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString("notesEdit", notesEdit.getText().toString()); savedInstanceState.putString("notesEdit", notesEdit.getText().toString());

View file

@ -25,6 +25,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.db.DbRequest;
@ -39,9 +40,11 @@ import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.PluginStore; import info.nightscout.androidaps.plugins.configBuilder.PluginStore;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.utils.BatteryLevel; import info.nightscout.androidaps.utils.BatteryLevel;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
/** /**
@ -463,6 +466,22 @@ public class NSUpload {
} }
public static void createNSTreatment(JSONObject data, ProfileStore profileStore, ProfileFunction profileFunction, long eventTime) {
if (JsonHelper.safeGetString(data, "eventType", "").equals(CareportalEvent.PROFILESWITCH)) {
ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch(
profileStore,
JsonHelper.safeGetString(data, "profile"),
JsonHelper.safeGetInt(data, "duration"),
JsonHelper.safeGetInt(data, "percentage"),
JsonHelper.safeGetInt(data, "timeshift"),
eventTime
);
uploadProfileSwitch(profileSwitch);
} else {
uploadCareportalEntryToNS(data);
}
}
public static boolean isIdValid(String _id) { public static boolean isIdValid(String _id) {
if (_id == null) if (_id == null)
return false; return false;

View file

@ -115,7 +115,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
} }
// reset deviations after profile switch // reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) {
deviationsArray.clear(); deviationsArray.clear();
pastSensitivity += "(PROFILESWITCH)"; pastSensitivity += "(PROFILESWITCH)";
} }

View file

@ -107,7 +107,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
} }
// reset deviations after profile switch // reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) {
deviationsArray.clear(); deviationsArray.clear();
pastSensitivity += "(PROFILESWITCH)"; pastSensitivity += "(PROFILESWITCH)";
} }

View file

@ -106,7 +106,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
} }
// reset deviations after profile switch // reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) {
deviationsArray.clear(); deviationsArray.clear();
pastSensitivity += "(PROFILESWITCH)"; pastSensitivity += "(PROFILESWITCH)";
} }

View file

@ -117,7 +117,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
} }
// reset deviations after profile switch // reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) {
data.clear(); data.clear();
pastSensitivity += "(PROFILESWITCH)"; pastSensitivity += "(PROFILESWITCH)";
} }

View file

@ -731,7 +731,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
public void doProfileSwitch(final int duration, final int percentage, final int timeShift) { public void doProfileSwitch(final int duration, final int percentage, final int timeShift) {
ProfileSwitch profileSwitch = treatmentsPlugin.getProfileSwitchFromHistory(System.currentTimeMillis()); ProfileSwitch profileSwitch = treatmentsPlugin.getProfileSwitchFromHistory(System.currentTimeMillis());
if (profileSwitch != null) { if (profileSwitch != null) {
profileSwitch = new ProfileSwitch(); profileSwitch = new ProfileSwitch(getInjector());
profileSwitch.date = System.currentTimeMillis(); profileSwitch.date = System.currentTimeMillis();
profileSwitch.source = Source.USER; profileSwitch.source = Source.USER;
profileSwitch.profileName = profileFunction.getProfileName(System.currentTimeMillis(), false, false); profileSwitch.profileName = profileFunction.getProfileName(System.currentTimeMillis(), false, false);

View file

@ -13,19 +13,6 @@ import org.mockito.junit.MockitoRule
import java.util.* import java.util.*
open class TestBase { open class TestBase {
val validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
val validProfile: Profile = Profile(HasAndroidInjector { AndroidInjector { Unit } }, JSONObject(validProfileJSON), Constants.MGDL)
val TESTPROFILENAME = "someProfile"
fun getValidProfileStore(): ProfileStore {
val json = JSONObject()
val store = JSONObject()
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(HasAndroidInjector { AndroidInjector { Unit } }, json)
}
// 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

@ -0,0 +1,60 @@
package info.nightscout.androidaps
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.json.JSONObject
import org.junit.Before
import org.mockito.Mock
open class TestBaseWithProfile : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var activePluginProvider: ActivePluginProvider
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var treatmentsPlugin :TreatmentsPlugin
val rxBus = RxBusWrapper()
val profileInjector = HasAndroidInjector {
AndroidInjector {
if (it is Profile) {
it.aapsLogger = aapsLogger
it.activePlugin = activePluginProvider
it.resourceHelper = resourceHelper
it.rxBus = rxBus
}
if (it is ProfileSwitch) {
it.treatmentsPlugin = treatmentsPlugin
it.aapsLogger = aapsLogger
it.rxBus = rxBus
it.resourceHelper = resourceHelper
}
}
}
lateinit var validProfileJSON : String
lateinit var validProfile: Profile
val TESTPROFILENAME = "someProfile"
@Before
fun prepareMock() {
validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
validProfile = Profile(profileInjector, JSONObject(validProfileJSON), Constants.MGDL)
}
fun getValidProfileStore(): ProfileStore {
val json = JSONObject()
val store = JSONObject()
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json)
}
}

View file

@ -1,58 +0,0 @@
package info.nightscout.androidaps.data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T;
/**
* Created by mike on 26.03.2018.
*/
@RunWith(PowerMockRunner.class)
public class NonOverapingIntervalsTest {
private final long startDate = DateUtil.now();
NonOverlappingIntervals<TemporaryBasal> list = new NonOverlappingIntervals<>();
@Test
public void doTests() {
// create one 10h interval and test value in and out
list.add(new TemporaryBasal().date(startDate).duration((int) T.hours(10).mins()).absolute(1));
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()));
Assert.assertEquals(1d, list.getValueByInterval(startDate).absoluteRate, 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1));
// stop temp after 5h
list.add(new TemporaryBasal().date(startDate + T.hours(5).msecs()).duration(0));
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()));
Assert.assertEquals(1d, list.getValueByInterval(startDate).absoluteRate, 0.01d);
Assert.assertEquals(1d, list.getValueByInterval(startDate + T.hours(5).msecs() - 1).absoluteRate, 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1));
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1));
// insert 1h interval inside
list.add(new TemporaryBasal().date(startDate + T.hours(3).msecs()).duration((int) T.hours(1).mins()).absolute(2));
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()));
Assert.assertEquals(1d, list.getValueByInterval(startDate).absoluteRate, 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() - 1));
Assert.assertEquals(2d, list.getValueByInterval(startDate + T.hours(3).msecs()).absoluteRate, 0.01d);
Assert.assertEquals(2d, list.getValueByInterval(startDate + T.hours(4).msecs() - 1).absoluteRate, 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(4).msecs() + 1));
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1));
}
@Test
public void testCopyConstructor() {
list.reset();
list.add(new TemporaryBasal().date(startDate).duration((int) T.hours(10).mins()).absolute(1));
NonOverlappingIntervals<TemporaryBasal> list2 = new NonOverlappingIntervals<>(list);
Assert.assertEquals(1, list2.getList().size());
}
}

View file

@ -0,0 +1,51 @@
package info.nightscout.androidaps.data
import info.nightscout.androidaps.db.TemporaryBasal
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class NonOverlappingIntervalsTest {
private val startDate = DateUtil.now()
var list = NonOverlappingIntervals<TemporaryBasal>()
@Test
fun doTests() {
// create one 10h interval and test value in and out
list.add(TemporaryBasal().date(startDate).duration(T.hours(10).mins().toInt()).absolute(1.0))
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
// stop temp after 5h
list.add(TemporaryBasal().date(startDate + T.hours(5).msecs()).duration(0))
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01)
Assert.assertEquals(1.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.absoluteRate, 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1))
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
// insert 1h interval inside
list.add(TemporaryBasal().date(startDate + T.hours(3).msecs()).duration(T.hours(1).mins().toInt()).absolute(2.0))
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() - 1))
Assert.assertEquals(2.0, list.getValueByInterval(startDate + T.hours(3).msecs())!!.absoluteRate, 0.01)
Assert.assertEquals(2.0, list.getValueByInterval(startDate + T.hours(4).msecs() - 1)!!.absoluteRate, 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(4).msecs() + 1))
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
}
@Test
fun testCopyConstructor() {
list.reset()
list.add(TemporaryBasal().date(startDate).duration(T.hours(10).mins().toInt()).absolute(1.0))
val list2 = NonOverlappingIntervals(list)
Assert.assertEquals(1, list2.list.size.toLong())
}
}

View file

@ -1,72 +0,0 @@
package info.nightscout.androidaps.data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T;
/**
* Created by mike on 26.03.2018.
*/
@RunWith(PowerMockRunner.class)
public class OverapingIntervalsTest {
private final long startDate = DateUtil.now();
OverlappingIntervals<TempTarget> list = new OverlappingIntervals<>();
@Test
public void doTests() {
// create one 10h interval and test value in and out
list.add(new TempTarget().date(startDate).duration((int) T.hours(10).mins()).low(100).high(100));
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()));
Assert.assertEquals(100d, list.getValueByInterval(startDate).target(), 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1));
// stop temp target after 5h
list.add(new TempTarget().date(startDate + T.hours(5).msecs()).duration(0));
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()));
Assert.assertEquals(100d, list.getValueByInterval(startDate).target(), 0.01d);
Assert.assertEquals(100d, list.getValueByInterval(startDate + T.hours(5).msecs() - 1).target(), 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1));
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1));
// insert 1h interval inside
list.add(new TempTarget().date(startDate + T.hours(3).msecs()).duration((int) T.hours(1).mins()).low(200).high(200));
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()));
Assert.assertEquals(100d, list.getValueByInterval(startDate).target(), 0.01d);
Assert.assertEquals(100d, list.getValueByInterval(startDate + T.hours(5).msecs() - 1).target(), 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1));
Assert.assertEquals(200d, list.getValueByInterval(startDate + T.hours(3).msecs()).target(), 0.01d);
Assert.assertEquals(100d, list.getValueByInterval(startDate + T.hours(4).msecs() + 1).target(), 0.01d);
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1));
}
@Test
public void testCopyConstructor() {
list.reset();
list.add(new TempTarget().date(startDate).duration((int) T.hours(10).mins()).low(100).high(100));
OverlappingIntervals<TempTarget> list2 = new OverlappingIntervals<>(list);
Assert.assertEquals(1, list2.getList().size());
}
@Test
public void testReversingArrays() {
List<TempTarget> someList = new ArrayList<>();
someList.add(new TempTarget().date(startDate).duration((int) T.hours(3).mins()).low(200).high(200));
someList.add(new TempTarget().date(startDate + T.hours(1).msecs()).duration((int) T.hours(1).mins()).low(100).high(100));
list.reset();
list.add(someList);
Assert.assertEquals(startDate, list.get(0).date);
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date);
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversedList().get(0).date);
}
}

View file

@ -0,0 +1,60 @@
package info.nightscout.androidaps.data
import info.nightscout.androidaps.db.TempTarget
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class)
class OverlappingIntervalsTest {
private val startDate = DateUtil.now()
var list = OverlappingIntervals<TempTarget>()
@Test fun doTests() {
// create one 10h interval and test value in and out
list.add(TempTarget().date(startDate).duration(T.hours(10).mins().toInt()).low(100.0).high(100.0))
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
// stop temp target after 5h
list.add(TempTarget().date(startDate + T.hours(5).msecs()).duration(0))
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01)
Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.target(), 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1))
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
// insert 1h interval inside
list.add(TempTarget().date(startDate + T.hours(3).msecs()).duration(T.hours(1).mins().toInt()).low(200.0).high(200.0))
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01)
Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.target(), 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1))
Assert.assertEquals(200.0, list.getValueByInterval(startDate + T.hours(3).msecs())!!.target(), 0.01)
Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(4).msecs() + 1)!!.target(), 0.01)
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
}
@Test fun testCopyConstructor() {
list.reset()
list.add(TempTarget().date(startDate).duration(T.hours(10).mins().toInt()).low(100.0).high(100.0))
val list2 = OverlappingIntervals(list)
Assert.assertEquals(1, list2.list.size.toLong())
}
@Test fun testReversingArrays() {
val someList: MutableList<TempTarget> = ArrayList()
someList.add(TempTarget().date(startDate).duration(T.hours(3).mins().toInt()).low(200.0).high(200.0))
someList.add(TempTarget().date(startDate + T.hours(1).msecs()).duration(T.hours(1).mins().toInt()).low(100.0).high(100.0))
list.reset()
list.add(someList)
Assert.assertEquals(startDate, list[0].date)
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date)
Assert.assertEquals(startDate + T.hours(1).msecs(), list.reversedList[0].date)
}
}

View file

@ -1,95 +0,0 @@
package info.nightscout.androidaps.data;
import org.junit.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 java.util.ArrayList;
import java.util.List;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T;
/**
* Created by mike on 26.03.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, TreatmentsPlugin.class, TreatmentService.class})
public class ProfileIntervalsTest {
private final long startDate = DateUtil.now();
ProfileIntervals<ProfileSwitch> list = new ProfileIntervals<>();
@Test
public void doTests() {
// create one 10h interval and test value in and out
list.add(new ProfileSwitch().date(startDate).duration((int) T.hours(10).mins()).profileName("1").profile(AAPSMocker.getValidProfile()));
// for older date first record should be returned only if has zero duration
Assert.assertEquals(null, list.getValueToTime(startDate - T.secs(1).msecs()));
Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate)).profileName);
Assert.assertEquals(null, list.getValueToTime(startDate + T.hours(10).msecs() + 1));
list.reset();
list.add(new ProfileSwitch().date(startDate).profileName("1").profile(AAPSMocker.getValidProfile()));
Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate - T.secs(1).msecs())).profileName);
Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate)).profileName);
Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(10).msecs() + 1)).profileName);
// switch to different profile after 5h
list.add(new ProfileSwitch().date(startDate + T.hours(5).msecs()).duration(0).profileName("2").profile(AAPSMocker.getValidProfile()));
Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate - T.secs(1).msecs())).profileName);
Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(5).msecs() - 1)).profileName);
Assert.assertEquals("2", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(5).msecs() + 1)).profileName);
// insert 1h interval inside
list.add(new ProfileSwitch().date(startDate + T.hours(6).msecs()).duration((int) T.hours(1).mins()).profileName("3").profile(AAPSMocker.getValidProfile()));
Assert.assertEquals("2", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(6).msecs() - 1)).profileName);
Assert.assertEquals("3", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(6).msecs() + 1)).profileName);
Assert.assertEquals("2", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(7).msecs() + 1)).profileName);
}
@Test
public void testCopyConstructor() {
list.reset();
list.add(new ProfileSwitch().date(startDate).duration((int) T.hours(10).mins()).profileName("4").profile(AAPSMocker.getValidProfile()));
ProfileIntervals<ProfileSwitch> list2 = new ProfileIntervals<>(list);
Assert.assertEquals(1, list2.getList().size());
}
@Test
public void invalidProfilesShouldNotBeReturned() {
list.reset();
list.add(new ProfileSwitch().date(startDate + T.hours(1).msecs()).profileName("6"));
Assert.assertEquals(null, list.get(0));
}
@Test
public void testReversingArrays() {
List<ProfileSwitch> someList = new ArrayList<>();
someList.add(new ProfileSwitch().date(startDate).duration((int) T.hours(3).mins()).profileName("5").profile(AAPSMocker.getValidProfile()));
someList.add(new ProfileSwitch().date(startDate + T.hours(1).msecs()).duration((int) T.hours(1).mins()).profileName("6").profile(AAPSMocker.getValidProfile()));
list.reset();
list.add(someList);
Assert.assertEquals(startDate, list.get(0).date);
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date);
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversedList().get(0).date);
}
@Before
public void prepareMock() {
AAPSMocker.mockMainApp();
AAPSMocker.mockStrings();
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockTreatmentPlugin();
}
}

View file

@ -0,0 +1,90 @@
package info.nightscout.androidaps.data
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.interfaces.PumpDescription
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper
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.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class)
@PrepareForTest(VirtualPumpPlugin::class)
class ProfileIntervalsTest : TestBaseWithProfile() {
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
private val startDate = DateUtil.now()
var list = ProfileIntervals<ProfileSwitch>()
@Before
fun mock() {
`when`(activePluginProvider.activePump).thenReturn(virtualPumpPlugin)
`when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription())
}
@Test
fun doTests() {
// create one 10h interval and test value in and out
list.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(10).mins().toInt()).profileName("1").profile(validProfile))
// for older date first record should be returned only if has zero duration
Assert.assertEquals(null, list.getValueToTime(startDate - T.secs(1).msecs()))
Assert.assertEquals("1", (list.getValueToTime(startDate) as ProfileSwitch?)!!.profileName)
Assert.assertEquals(null, list.getValueToTime(startDate + T.hours(10).msecs() + 1))
list.reset()
list.add(ProfileSwitch(profileInjector).date(startDate).profileName("1").profile(validProfile))
Assert.assertEquals("1", (list.getValueToTime(startDate - T.secs(1).msecs()) as ProfileSwitch?)!!.profileName)
Assert.assertEquals("1", (list.getValueToTime(startDate) as ProfileSwitch?)!!.profileName)
Assert.assertEquals("1", (list.getValueToTime(startDate + T.hours(10).msecs() + 1) as ProfileSwitch?)!!.profileName)
// switch to different profile after 5h
list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(5).msecs()).duration(0).profileName("2").profile(validProfile))
Assert.assertEquals("1", (list.getValueToTime(startDate - T.secs(1).msecs()) as ProfileSwitch?)!!.profileName)
Assert.assertEquals("1", (list.getValueToTime(startDate + T.hours(5).msecs() - 1) as ProfileSwitch?)!!.profileName)
Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(5).msecs() + 1) as ProfileSwitch?)!!.profileName)
// insert 1h interval inside
list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(6).msecs()).duration(T.hours(1).mins().toInt()).profileName("3").profile(validProfile))
Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(6).msecs() - 1) as ProfileSwitch?)!!.profileName)
Assert.assertEquals("3", (list.getValueToTime(startDate + T.hours(6).msecs() + 1) as ProfileSwitch?)!!.profileName)
Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(7).msecs() + 1) as ProfileSwitch?)!!.profileName)
}
@Test
fun testCopyConstructor() {
list.reset()
list.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(10).mins().toInt()).profileName("4").profile(validProfile))
val list2 = ProfileIntervals(list)
Assert.assertEquals(1, list2.list.size.toLong())
}
@Test fun invalidProfilesShouldNotBeReturned() {
list.reset()
list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(1).msecs()).profileName("6"))
Assert.assertEquals(null, list[0])
}
@Test fun testReversingArrays() {
val someList: MutableList<ProfileSwitch> = ArrayList()
someList.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(3).mins().toInt()).profileName("5").profile(validProfile))
someList.add(ProfileSwitch(profileInjector).date(startDate + T.hours(1).msecs()).duration(T.hours(1).mins().toInt()).profileName("6").profile(validProfile))
list.reset()
list.add(someList)
Assert.assertEquals(startDate, list[0].date)
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date)
Assert.assertEquals(startDate + T.hours(1).msecs(), list.reversedList[0].date)
}
}

View file

@ -3,9 +3,9 @@ package info.nightscout.androidaps.interfaces
import android.content.Context import android.content.Context
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin
@ -48,15 +48,12 @@ import java.util.*
*/ */
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class, OpenAPSMAPlugin::class, OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class, VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class) @PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class, OpenAPSMAPlugin::class, OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class, VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class)
class ConstraintsCheckerTest : TestBase() { class ConstraintsCheckerTest : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
@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 commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
@Mock lateinit var context: Context @Mock lateinit var context: Context
@ -64,7 +61,6 @@ class ConstraintsCheckerTest : TestBase() {
@Mock lateinit var glimpPlugin: GlimpPlugin @Mock lateinit var glimpPlugin: GlimpPlugin
@Mock lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin @Mock lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin
val rxBus = RxBusWrapper()
private var buildHelper = BuildHelper() private var buildHelper = BuildHelper()
lateinit var danaRPump: DanaRPump lateinit var danaRPump: DanaRPump
@ -89,7 +85,7 @@ class ConstraintsCheckerTest : TestBase() {
} }
@Before @Before
fun prepareMock() { fun prepare() {
`when`(resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch)).thenReturn("Running dev version. Closed loop is disabled.") `when`(resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch)).thenReturn("Running dev version. Closed loop is disabled.")
`when`(resourceHelper.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences") `when`(resourceHelper.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences")
`when`(resourceHelper.gs(R.string.objectivenotstarted)).thenReturn("Objective %d not started") `when`(resourceHelper.gs(R.string.objectivenotstarted)).thenReturn("Objective %d not started")

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.aps.loop
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.db.TemporaryBasal
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
@ -28,16 +29,13 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class) @PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class)
class APSResultTest : TestBase() { class APSResultTest : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var activePluginProvider: ActivePluginProvider
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
private var closedLoopEnabled = Constraint(false) private var closedLoopEnabled = Constraint(false)
private val pumpDescription = PumpDescription() private val pumpDescription = PumpDescription()
@ -199,7 +197,7 @@ class APSResultTest : TestBase() {
} }
@Before @Before
fun prepareMock() { fun prepare() {
`when`(constraintChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled) `when`(constraintChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled)
`when`(activePluginProvider.activePump).thenReturn(virtualPumpPlugin) `when`(activePluginProvider.activePump).thenReturn(virtualPumpPlugin)
`when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0) `when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0)

View file

@ -1,14 +1,22 @@
package info.nightscout.androidaps.plugins.general.automation.actions package info.nightscout.androidaps.plugins.general.automation.actions
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.automation.elements.InputString import info.nightscout.androidaps.plugins.general.automation.elements.InputString
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import org.powermock.api.mockito.PowerMockito import org.powermock.api.mockito.PowerMockito
@ -16,14 +24,31 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(NSUpload::class) @PrepareForTest(NSUpload::class, RxBusWrapper::class)
class ActionNotificationTest : ActionsTestBase() { class ActionNotificationTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var rxBus: RxBusWrapper
private lateinit var sut: ActionNotification private lateinit var sut: ActionNotification
var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector {
if (it is ActionNotification) {
it.resourceHelper = resourceHelper
it.rxBus = rxBus
}
if (it is PumpEnactResult) {
it.aapsLogger = aapsLogger
it.resourceHelper = resourceHelper
}
}
}
@Before @Before
fun setup() { fun setup() {
PowerMockito.mockStatic(NSUpload::class.java) PowerMockito.mockStatic(NSUpload::class.java)
`when`(resourceHelper.gs(R.string.ok)).thenReturn("OK")
`when`(resourceHelper.gs(R.string.notification)).thenReturn("Notification") `when`(resourceHelper.gs(R.string.notification)).thenReturn("Notification")
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.notification_message), ArgumentMatchers.anyString())).thenReturn("Notification: %s") `when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.notification_message), ArgumentMatchers.anyString())).thenReturn("Notification: %s")

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.actions
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
@ -21,16 +22,12 @@ import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
@PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class, LocalProfilePlugin::class, SmsCommunicatorPlugin::class) @PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class, LocalProfilePlugin::class, SmsCommunicatorPlugin::class)
open class ActionsTestBase : TestBase() { open class ActionsTestBase : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin @Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var loopPlugin: LoopPlugin @Mock lateinit var loopPlugin: LoopPlugin
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.triggers
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.TestBaseWithProfile
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.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
@ -19,14 +20,11 @@ import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
@PrepareForTest(LastLocationDataContainer::class) @PrepareForTest(LastLocationDataContainer::class)
open class TriggerTestBase : TestBase() { open class TriggerTestBase : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var locationDataContainer: LastLocationDataContainer @Mock lateinit var locationDataContainer: LastLocationDataContainer
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin @Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin

View file

@ -1,86 +0,0 @@
package info.nightscout.androidaps.plugins.general.careportal.Dialogs;
import android.content.Context;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Date;
import info.AAPSMocker;
import info.SPMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
import static info.nightscout.androidaps.plugins.general.careportal.CareportalFragment.PROFILESWITCH;
import static org.powermock.api.mockito.PowerMockito.doAnswer;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest({SP.class, MainApp.class, ConfigBuilderPlugin.class, Context.class, NSUpload.class, TreatmentsPlugin.class, TreatmentService.class, DatabaseHelper.class})
public class NewNSTreatmentDialogTest {
NewNSTreatmentDialog dialog;
ProfileSwitch profileSwitchUpload = null;
@Test
public void createNSTreatmentTest() throws Exception {
// Test profile creation
doAnswer(invocation -> {
ProfileSwitch ps = invocation.getArgument(0);
profileSwitchUpload = ps;
return null;
}).when(NSUpload.class, "uploadProfileSwitch", ArgumentMatchers.any());
dialog.setOptions(PROFILESWITCH, R.string.careportal_profileswitch);
dialog.profileStore = AAPSMocker.getValidProfileStore();
dialog.eventTime = new Date();
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.PROFILESWITCH);
data.put("profile", AAPSMocker.TESTPROFILENAME);
data.put("duration", 0);
data.put("percentage", 110);
data.put("timeshift", 0);
dialog.createNSTreatment(data);
// Profile should be sent to NS
Assert.assertEquals(AAPSMocker.TESTPROFILENAME, profileSwitchUpload.profileName);
}
@Before
public void prepareMock() throws Exception {
AAPSMocker.mockMainApp();
SPMocker.prepareMock();
SP.putString("profile", AAPSMocker.getValidProfileStore().getData().toString());
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockStrings();
PowerMockito.mockStatic(NSUpload.class);
AAPSMocker.mockTreatmentService();
AAPSMocker.mockDatabaseHelper();
NSProfilePlugin profilePlugin = NSProfilePlugin.getPlugin();
when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface())
.thenReturn(profilePlugin);
dialog = new NewNSTreatmentDialog();
PowerMockito.spy(System.class);
when(System.currentTimeMillis()).thenReturn(1000L);
}
}

View file

@ -3,10 +3,10 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator
import android.telephony.SmsManager import android.telephony.SmsManager
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.data.IobTotal
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.db.BgReading
@ -14,7 +14,6 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
@ -33,7 +32,6 @@ import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.XdripCalibrations import info.nightscout.androidaps.utils.XdripCalibrations
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
@ -52,13 +50,10 @@ import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, FabricPrivacy::class, VirtualPumpPlugin::class, XdripCalibrations::class, SmsManager::class, RxBusWrapper::class, CommandQueue::class, LocalProfilePlugin::class, DateUtil::class, IobCobCalculatorPlugin::class, MainApp::class) @PrepareForTest(ConstraintChecker::class, FabricPrivacy::class, VirtualPumpPlugin::class, XdripCalibrations::class, SmsManager::class, RxBusWrapper::class, CommandQueue::class, LocalProfilePlugin::class, DateUtil::class, IobCobCalculatorPlugin::class, MainApp::class)
class SmsCommunicatorPluginTest : TestBase() { class SmsCommunicatorPluginTest : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
lateinit var rxBus: RxBusWrapper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@ -68,7 +63,6 @@ class SmsCommunicatorPluginTest : TestBase() {
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var localProfilePlugin: LocalProfilePlugin @Mock lateinit var localProfilePlugin: LocalProfilePlugin
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var treatmentService: TreatmentService @Mock lateinit var treatmentService: TreatmentService
var injector: HasAndroidInjector = HasAndroidInjector { var injector: HasAndroidInjector = HasAndroidInjector {
@ -99,7 +93,6 @@ class SmsCommunicatorPluginTest : TestBase() {
private var hasBeenRun = false private var hasBeenRun = false
@Before fun prepareTests() { @Before fun prepareTests() {
rxBus = RxBusWrapper()
val reading = BgReading(injector) val reading = BgReading(injector)
reading.value = 100.0 reading.value = 100.0
val bgList: MutableList<BgReading> = ArrayList() val bgList: MutableList<BgReading> = ArrayList()

View file

@ -3,17 +3,14 @@ package info.nightscout.androidaps.plugins.pump.danaR
import android.content.Context import android.content.Context
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
@ -26,17 +23,13 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(SP::class, ConstraintChecker::class) @PrepareForTest(SP::class, ConstraintChecker::class)
class DanaRPluginTest : TestBase() { class DanaRPluginTest : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
val rxBus = RxBusWrapper()
lateinit var danaRPump: DanaRPump lateinit var danaRPump: DanaRPump
private lateinit var danaRPlugin: DanaRPlugin private lateinit var danaRPlugin: DanaRPlugin

View file

@ -9,7 +9,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
@ -22,7 +21,7 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class MessageHashTableRTest : DanaRSTestBase() { class MessageHashTableRTest : DanaRTestBase() {
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper

View file

@ -3,18 +3,15 @@ package info.nightscout.androidaps.plugins.pump.danaRKorean
import android.content.Context import android.content.Context
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
@ -27,17 +24,13 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(SP::class, ConstraintChecker::class) @PrepareForTest(SP::class, ConstraintChecker::class)
class DanaRKoreanPluginTest : TestBase() { class DanaRKoreanPluginTest : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
val rxBus = RxBusWrapper()
lateinit var danaRPump: DanaRPump lateinit var danaRPump: DanaRPump
private lateinit var danaRPlugin: DanaRKoreanPlugin private lateinit var danaRPlugin: DanaRKoreanPlugin

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
@ -11,7 +10,6 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -24,8 +22,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class MessageHashTableRKoreanTest : DanaRSTestBase() { class MessageHashTableRKoreanTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var danaRPlugin: DanaRPlugin @Mock lateinit var danaRPlugin: DanaRPlugin
@Mock lateinit var danaRKoreanPlugin: DanaRKoreanPlugin @Mock lateinit var danaRKoreanPlugin: DanaRKoreanPlugin
@ -33,7 +29,6 @@ class MessageHashTableRKoreanTest : DanaRSTestBase() {
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Test fun runTest() { @Test fun runTest() {
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))

View file

@ -14,7 +14,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -30,15 +29,12 @@ import org.powermock.modules.junit4.PowerMockRunner
class DanaRSPluginTest : DanaRSTestBase() { class DanaRSPluginTest : DanaRSTestBase() {
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
private lateinit var danaRSPlugin: DanaRSPlugin private lateinit var danaRSPlugin: DanaRSPlugin
lateinit var rxBus: RxBusWrapper
@Test @Test
fun basalRateShouldBeLimited() { fun basalRateShouldBeLimited() {
@ -70,7 +66,6 @@ class DanaRSPluginTest : DanaRSTestBase() {
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio")
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate")
rxBus = RxBusWrapper()
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage)
} }
} }

View file

@ -3,13 +3,10 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
import com.cozmo.danar.util.BleCommandUtil import com.cozmo.danar.util.BleCommandUtil
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -22,8 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class DanaRSMessageHashTableTest : DanaRSTestBase() { class DanaRSMessageHashTableTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var danaRSPlugin: DanaRSPlugin
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker

View file

@ -1,16 +1,14 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Before import org.junit.Before
import org.mockito.Mock import org.mockito.Mock
open class DanaRSTestBase : TestBase() { open class DanaRSTestBase : TestBaseWithProfile() {
@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

@ -5,7 +5,6 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -18,8 +17,6 @@ import java.util.*
@PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class) @PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class)
class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var danaRSPlugin: DanaRSPlugin
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage

View file

@ -1,11 +1,9 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -13,8 +11,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(RxBusWrapper::class) @PrepareForTest(RxBusWrapper::class)
class DanaRS_Packet_Basal_Get_Basal_RateTest : DanaRSTestBase() { class DanaRS_Packet_Basal_Get_Basal_RateTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump) val packet = DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)

View file

@ -1,11 +1,9 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -13,9 +11,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(RxBusWrapper::class) @PrepareForTest(RxBusWrapper::class)
class DanaRS_Packet_Bolus_Get_Bolus_OptionTest : DanaRSTestBase() { class DanaRS_Packet_Bolus_Get_Bolus_OptionTest : DanaRSTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump) val packet = DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)
// test message decoding // test message decoding

View file

@ -5,13 +5,11 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -25,12 +23,9 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage

View file

@ -8,7 +8,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.plugins.treatments.Treatment
import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -23,8 +22,6 @@ import org.powermock.modules.junit4.PowerMockRunner
class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() { class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() {
@Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var danaRSPlugin: DanaRSPlugin

View file

@ -1,11 +1,9 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -13,9 +11,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(RxBusWrapper::class) @PrepareForTest(RxBusWrapper::class)
class DanaRS_Packet_General_Get_Pump_CheckTest : DanaRSTestBase() { class DanaRS_Packet_General_Get_Pump_CheckTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper
@Test fun runTest() { @Test fun runTest() {
var packet = DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper) var packet = DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)
Assert.assertEquals(null, packet.requestParams) Assert.assertEquals(null, packet.requestParams)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__ALARM", packet.friendlyName) Assert.assertEquals("REVIEW__ALARM", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_All_HistoryTest : DanaRSTestBase() { class DanaRS_Packet_History_All_HistoryTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_All_History(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_All_History(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__ALL_HISTORY", packet.friendlyName) Assert.assertEquals("REVIEW__ALL_HISTORY", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_BasalTest : DanaRSTestBase() { class DanaRS_Packet_History_BasalTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__BASAL", packet.friendlyName) Assert.assertEquals("REVIEW__BASAL", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() { class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__BLOOD_GLUCOSE", packet.friendlyName) Assert.assertEquals("REVIEW__BLOOD_GLUCOSE", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_BolusTest : DanaRSTestBase() { class DanaRS_Packet_History_BolusTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__BOLUS", packet.friendlyName) Assert.assertEquals("REVIEW__BOLUS", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() { class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__CARBOHYDRATE", packet.friendlyName) Assert.assertEquals("REVIEW__CARBOHYDRATE", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_DailyTest : DanaRSTestBase() { class DanaRS_Packet_History_DailyTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__DAILY", packet.friendlyName) Assert.assertEquals("REVIEW__DAILY", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() { class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__PRIME", packet.friendlyName) Assert.assertEquals("REVIEW__PRIME", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_RefillTest : DanaRSTestBase() { class DanaRS_Packet_History_RefillTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__REFILL", packet.friendlyName) Assert.assertEquals("REVIEW__REFILL", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() { class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__SUSPEND", packet.friendlyName) Assert.assertEquals("REVIEW__SUSPEND", packet.friendlyName)

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest() @PrepareForTest()
class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() { class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, System.currentTimeMillis()) val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, System.currentTimeMillis())
Assert.assertEquals("REVIEW__TEMPORARY", packet.friendlyName) Assert.assertEquals("REVIEW__TEMPORARY", packet.friendlyName)

View file

@ -1,12 +1,10 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.api.mockito.PowerMockito import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@ -15,8 +13,6 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(NSUpload::class) @PrepareForTest(NSUpload::class)
class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() { class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper) val packet = DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper)
// test params // test params

View file

@ -4,12 +4,10 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.plugins.treatments.Treatment
import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -25,8 +23,6 @@ import org.powermock.modules.junit4.PowerMockRunner
class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() { class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() {
@Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var danaRSPlugin: DanaRSPlugin
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider

View file

@ -13,7 +13,6 @@ import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.plugins.treatments.Treatment
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -29,13 +28,10 @@ import org.powermock.modules.junit4.PowerMockRunner
class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
@Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage

View file

@ -3,19 +3,16 @@ package info.nightscout.androidaps.plugins.pump.danaRv2
import android.content.Context import android.content.Context
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -26,18 +23,14 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class DanaRv2PluginTest : TestBase() { class DanaRv2PluginTest : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var sp: info.nightscout.androidaps.utils.sharedPreferences.SP @Mock lateinit var sp: info.nightscout.androidaps.utils.sharedPreferences.SP
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
val rxBus = RxBusWrapper()
lateinit var danaRPump: DanaRPump lateinit var danaRPump: DanaRPump
private lateinit var danaRv2Plugin: DanaRv2Plugin private lateinit var danaRv2Plugin: DanaRv2Plugin

View file

@ -8,9 +8,9 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -24,7 +24,7 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class MessageHashTable_rv2Test : DanaRSTestBase() { class MessageHashTable_rv2Test : DanaRTestBase() {
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper

View file

@ -5,8 +5,8 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert import org.junit.Assert
@ -18,7 +18,7 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(DanaRKoreanPlugin::class, DanaRPlugin::class, DanaRv2Plugin::class) @PrepareForTest(DanaRKoreanPlugin::class, DanaRPlugin::class, DanaRv2Plugin::class)
class MsgCheckValue_v2Test : DanaRSTestBase() { class MsgCheckValue_v2Test : DanaRTestBase() {
val rxBus = RxBusWrapper() val rxBus = RxBusWrapper()
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper

View file

@ -6,7 +6,6 @@ import org.junit.Before;
import java.util.List; import java.util.List;
import info.AAPSMocker;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage;
@ -48,7 +47,6 @@ public class MedtronicHistoryDataUTest {
// } // }
AAPSMocker.mockMainApp();
} }
@ -56,12 +54,6 @@ public class MedtronicHistoryDataUTest {
public void prepareMocks() throws Exception { public void prepareMocks() throws Exception {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace"); System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace");
AAPSMocker.mockMainApp();
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockStrings();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockCommandQueue();
when(SP.getString(R.string.key_danars_address, "")).thenReturn(""); when(SP.getString(R.string.key_danars_address, "")).thenReturn("");

View file

@ -4,7 +4,7 @@ import android.content.Context
import dagger.Lazy import dagger.Lazy
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
@ -33,24 +33,19 @@ import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class, ToastUtils::class, Context::class, TreatmentsPlugin::class, FabricPrivacy::class) @PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class, ToastUtils::class, Context::class, TreatmentsPlugin::class, FabricPrivacy::class)
class CommandQueueTest : TestBase() { class CommandQueueTest : TestBaseWithProfile() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var lazyActivePlugin: Lazy<ActivePluginProvider> @Mock lateinit var lazyActivePlugin: Lazy<ActivePluginProvider>
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var fabricPrivacy: FabricPrivacy
private val buildHelper = BuildHelper() private val buildHelper = BuildHelper()
val rxBus = RxBusWrapper()
val injector = HasAndroidInjector { val injector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
if (it is Command) { if (it is Command) {
@ -63,7 +58,7 @@ class CommandQueueTest : TestBase() {
lateinit var commandQueue: CommandQueue lateinit var commandQueue: CommandQueue
@Before @Before
fun prepareMock() { fun prepare() {
commandQueue = CommandQueue(injector, aapsLogger, rxBus, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, buildHelper, fabricPrivacy) commandQueue = CommandQueue(injector, aapsLogger, rxBus, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, buildHelper, fabricPrivacy)
val pumpDescription = PumpDescription() val pumpDescription = PumpDescription()