better test coverage & some cleanup
This commit is contained in:
parent
157028c4fd
commit
7406577546
2 changed files with 22 additions and 30 deletions
|
@ -20,16 +20,13 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|||
import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
|
||||
public class ActionProfileSwitch extends Action {
|
||||
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
|
||||
public InputProfileName inputProfileName = new InputProfileName("-");
|
||||
public InputProfileName inputProfileName = new InputProfileName(ProfileFunctions.getInstance().getProfileName());
|
||||
String profileName = "";
|
||||
String profileStoreName;
|
||||
String profileInterfaceString;
|
||||
|
||||
public ActionProfileSwitch() {
|
||||
// Prevent action if active profile is already active
|
||||
|
@ -50,25 +47,19 @@ public class ActionProfileSwitch extends Action {
|
|||
|
||||
@Override
|
||||
public void doAction(Callback callback) {
|
||||
String activeProfileName = ProfileFunctions.getInstance().getProfileName();
|
||||
|
||||
/*log.debug("Current profile is: " + activeProfileName);
|
||||
log.debug("Wanted profile is: " + profileName);
|
||||
log.debug("Do they match: " + (profileName.equals(activeProfileName)));
|
||||
*/
|
||||
String activeProfileName = ProfileFunctions.getInstance().getProfileName();
|
||||
//Check for uninitialized profileName
|
||||
if ( profileName.equals("")){ profileName = activeProfileName; }
|
||||
|
||||
if (profileName.equals(activeProfileName)) {
|
||||
// Profile is already switched
|
||||
return;
|
||||
}
|
||||
ProfileInterface profileInterface = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
|
||||
profileInterfaceString = profileInterface.toString();
|
||||
ProfileStore profileStore = NSProfilePlugin.getPlugin().getProfile();
|
||||
log.debug("NS profileStore is: " +profileStore.toString());
|
||||
if (profileStore == null) {
|
||||
log.error("ProfileStore is null");
|
||||
return;
|
||||
}
|
||||
profileStoreName = profileStore.toString();
|
||||
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
|
||||
if (activeProfile == null) return;
|
||||
ProfileStore profileStore = activeProfile.getProfile();
|
||||
if (profileStore == null) return;
|
||||
if(profileStore.getSpecificProfile(profileName) == null) {
|
||||
log.error("Selected profile does not exist! - "+ profileName);
|
||||
return;
|
||||
|
|
|
@ -18,7 +18,6 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
@ -30,11 +29,11 @@ import static org.mockito.ArgumentMatchers.anyString;
|
|||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, TreatmentsPlugin.class, ProfileFunctions.class, ConfigBuilderPlugin.class})
|
||||
@PrepareForTest({MainApp.class, SP.class, TreatmentsPlugin.class, ProfileFunctions.class, ConfigBuilderPlugin.class, NSProfilePlugin.class})
|
||||
public class ActionProfileSwitchTest {
|
||||
TreatmentsPlugin treatmentsPlugin;
|
||||
ProfileSwitch profileAdded;
|
||||
private ActionProfileSwitch actionProfileSwitch = new ActionProfileSwitch();
|
||||
private ActionProfileSwitch actionProfileSwitch;
|
||||
private String stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitch\"}";
|
||||
|
||||
@Before
|
||||
|
@ -48,6 +47,7 @@ public class ActionProfileSwitchTest {
|
|||
AAPSMocker.mockTreatmentService();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockDatabaseHelper();
|
||||
AAPSMocker.mockProfileFunctions();
|
||||
|
||||
treatmentsPlugin = AAPSMocker.mockTreatmentPlugin();
|
||||
NSProfilePlugin profilePlugin = NSProfilePlugin.getPlugin();
|
||||
|
@ -62,6 +62,7 @@ public class ActionProfileSwitchTest {
|
|||
|
||||
@Test
|
||||
public void friendlyName() {
|
||||
actionProfileSwitch = new ActionProfileSwitch();
|
||||
Assert.assertEquals(R.string.profilename, actionProfileSwitch.friendlyName());
|
||||
}
|
||||
|
||||
|
@ -75,25 +76,24 @@ public class ActionProfileSwitchTest {
|
|||
|
||||
@Test
|
||||
public void doAction() {
|
||||
/* actionProfileSwitch = new ActionProfileSwitch();
|
||||
actionProfileSwitch.inputProfileName.setValue("Test");
|
||||
actionProfileSwitch.profileName = "Test";
|
||||
SP.putString("profile", AAPSMocker.getValidProfileStore().getData().toString());
|
||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn("Test");
|
||||
|
||||
actionProfileSwitch = new ActionProfileSwitch();
|
||||
actionProfileSwitch.inputProfileName.setValue("someOtherProfile");
|
||||
actionProfileSwitch.profileName = "someProfile";
|
||||
|
||||
when(NSProfilePlugin.getPlugin().getProfile()).thenReturn(AAPSMocker.getValidProfileStore());
|
||||
// Assert.assertEquals("", actionProfileSwitch.profileStoreName);
|
||||
Assert.assertEquals("", actionProfileSwitch.profileInterfaceString);
|
||||
// when(NSProfilePlugin.getPlugin().getProfile()).thenReturn(AAPSMocker.getValidProfileStore());
|
||||
actionProfileSwitch.doAction(new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
Assert.assertTrue(result.success);
|
||||
}
|
||||
});
|
||||
Assert.assertNotEquals(null, profileAdded);*/
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasDialogTest() {
|
||||
actionProfileSwitch = new ActionProfileSwitch();
|
||||
Assert.assertTrue(actionProfileSwitch.hasDialog());
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,7 @@ public class ActionProfileSwitchTest {
|
|||
|
||||
@Test
|
||||
public void iconTest() {
|
||||
actionProfileSwitch = new ActionProfileSwitch();
|
||||
Assert.assertEquals(Optional.of(R.drawable.icon_actions_profileswitch), actionProfileSwitch.icon());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue