NewNSTreatmentDialog extends AppCompatDialogFragment implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { void createNSTreatment(JSONObject data) { if (JsonHelper.safeGetString(data, "eventType", "").equals(CareportalEvent.PROFILESWITCH)) { ProfileSwitch profileSwitch = ProfileFunctions.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); } } NewNSTreatmentDialog(); NewNSTreatmentDialog setOptions(OptionsToShow options, int event); @Override View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState); @Override void onResume(); @Override void onClick(View view); @Override void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth); @Override void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second); @Override void onSaveInstanceState(Bundle savedInstanceState); public ProfileStore profileStore; }
@Test public void createNSTreatmentTest() throws Exception { 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); Assert.assertEquals(AAPSMocker.TESTPROFILENAME, profileSwitchUpload.profileName); }