ActionProfileSwitch extends Action { @Override public void doAction(Callback callback) { String activeProfileName = ProfileFunctions.getInstance().getProfileName(); if ( profileName.equals("")){ log.error("Selected profile not initialized"); if (callback != null) callback.result(new PumpEnactResult().success(false).comment(R.string.error_field_must_not_be_empty)).run(); return; } if ( ProfileFunctions.getInstance().getProfile() == null){ log.error("ProfileFunctions not initialized"); if (callback != null) callback.result(new PumpEnactResult().success(false).comment(R.string.noprofile)).run(); return; } if (profileName.equals(activeProfileName)) { if (L.isEnabled(L.AUTOMATION)) log.debug("Profile is already switched"); if (callback != null) callback.result(new PumpEnactResult().success(true).comment(R.string.alreadyset)).run(); return; } ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface(); if (activeProfile == null) { log.error("ProfileInterface not initialized"); if (callback != null) callback.result(new PumpEnactResult().success(false).comment(R.string.noprofile)).run(); return; } ProfileStore profileStore = activeProfile.getProfile(); if (profileStore == null) return; if(profileStore.getSpecificProfile(profileName) == null) { if (L.isEnabled(L.AUTOMATION)) log.error("Selected profile does not exist! - "+ profileName); if (callback != null) callback.result(new PumpEnactResult().success(false).comment(R.string.notexists)).run(); return; } ProfileFunctions.doProfileSwitch(profileStore, profileName, 0, 100, 0, DateUtil.now()); if (callback != null) callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run(); } ActionProfileSwitch(); @Override int friendlyName(); @Override String shortDescription(); @Override void doAction(Callback callback); @Override void generateDialog(LinearLayout root); @Override boolean hasDialog(); @Override String toJSON(); @Override Action fromJSON(String data); @Override Optional<Integer> icon();  }
@Test public void doAction() { PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn("Test"); actionProfileSwitch = new ActionProfileSwitch(); actionProfileSwitch.inputProfileName.setValue("someOtherProfile"); actionProfileSwitch.profileName = "someProfile"; actionProfileSwitch.doAction(new Callback() { @Override public void run() { Assert.assertTrue(result.success); } }); }