use of org.mockito.Mock in project android_packages_apps_Settings by LineageOS.
the class AdvancedPowerUsageDetailTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFragment = spy(new AdvancedPowerUsageDetail());
doReturn(mContext).when(mFragment).getContext();
doReturn(mActivity).when(mFragment).getActivity();
doReturn(SUMMARY).when(mFragment).getString(anyInt());
doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
doReturn(mBundle).when(mFragment).getArguments();
doReturn(mLoaderManager).when(mFragment).getLoaderManager();
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
doReturn(mEntityHeaderController).when(mEntityHeaderController).setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setButtonActions(anyInt(), anyInt());
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(Drawable.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(ApplicationsState.AppEntry.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(ApplicationsState.AppEntry.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(nullable(String.class));
doReturn(UID).when(mBatterySipper).getUid();
doReturn(APP_LABEL).when(mBatteryEntry).getLabel();
doReturn(BACKGROUND_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_BACKGROUND), anyLong(), anyInt());
doReturn(PROCSTATE_TOP_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_TOP), anyLong(), anyInt());
doReturn(mForegroundActivityTimer).when(mUid).getForegroundActivityTimer();
doReturn(FOREGROUND_ACTIVITY_TIME_US).when(mForegroundActivityTimer).getTotalTimeLocked(anyLong(), anyInt());
ReflectionHelpers.setField(mBatteryEntry, "sipper", mBatterySipper);
mBatteryEntry.iconId = ICON_ID;
mBatterySipper.uidObj = mUid;
mBatterySipper.drainType = BatterySipper.DrainType.APP;
mFragment.mHeaderPreference = mHeaderPreference;
mFragment.mState = mState;
mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
mAppEntry.info = mock(ApplicationInfo.class);
mTestActivity = spy(new SettingsActivity());
doReturn(mPackageManager).when(mTestActivity).getPackageManager();
doReturn(mAppOpsManager).when(mTestActivity).getSystemService(Context.APP_OPS_SERVICE);
mBatteryUtils = spy(BatteryUtils.getInstance(mTestActivity));
doReturn(FOREGROUND_SERVICE_TIME_US).when(mBatteryUtils).getForegroundServiceTotalTimeUs(any(BatteryStats.Uid.class), anyLong());
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
Answer<Void> callable = invocation -> {
mBundle = captor.getValue();
return null;
};
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(), nullable(CharSequence.class), nullable(UserHandle.class));
mForegroundPreference = new Preference(mContext);
mBackgroundPreference = new Preference(mContext);
mPowerUsagePreference = new Preference(mContext);
mFragment.mForegroundPreference = mForegroundPreference;
mFragment.mBackgroundPreference = mBackgroundPreference;
mFragment.mPowerUsagePreference = mPowerUsagePreference;
mFragment.mAnomalySummaryPreferenceController = mAnomalySummaryPreferenceController;
mAnomalies = new ArrayList<>();
mAnomalies.add(new Anomaly.Builder().setUid(UID).setType(Anomaly.AnomalyType.WAKE_LOCK).build());
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class GeneralSettingsPresenterTest method testExecuteValidationFailing.
@Test
public void testExecuteValidationFailing() {
final POM pom = mock(POM.class);
doReturn(false).when(validationService).validate(eq(pom));
generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
Assert.fail("Promise should've been resolved!");
return promises.resolve();
}).catch_(e -> {
verify(validationService).validate(eq(pom));
Assert.assertEquals(e, "Test message");
return promises.resolve();
});
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class GeneralSettingsPresenterTest method testExecuteValidation.
@Test
public void testExecuteValidation() {
final POM pom = mock(POM.class);
doReturn(true).when(validationService).validate(eq(pom));
generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
verify(validationService).validate(eq(pom));
Assert.assertEquals(valid, true);
return promises.resolve();
}).catch_(e -> {
Assert.fail("Promise should've been resolved!");
return promises.resolve();
});
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class DeploymentPopupBuilderTest method testBuildDeployWithMultipleServerTemplates.
@Test
public void testBuildDeployWithMultipleServerTemplates() throws Exception {
final List<ServerTemplate> serverTemplates = new ArrayList<>();
final ValidateExistingContainerCallback callback = mock(ValidateExistingContainerCallback.class);
final ParameterizedCommand<DeploymentScreenPopupViewImpl> onSuccess = (v) -> {
};
doReturn(callback).when(builder).multipleServerTemplatesValidation(serverTemplates);
builder.buildDeployWithMultipleServerTemplates(serverTemplates, onSuccess);
verify(builder).setViewFields(onSuccess, callback);
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class DeploymentPopupBuilderTest method testBuildDeployWithOneServerTemplate.
@Test
public void testBuildDeployWithOneServerTemplate() throws Exception {
final ServerTemplate serverTemplate = mock(ServerTemplate.class);
final ValidateExistingContainerCallback callback = mock(ValidateExistingContainerCallback.class);
final ParameterizedCommand<DeploymentScreenPopupViewImpl> onSuccess = (v) -> {
};
doReturn(callback).when(builder).singleServerTemplatesValidation(serverTemplate);
builder.buildDeployWithOneServerTemplate(serverTemplate, onSuccess);
verify(builder).setViewFields(onSuccess, callback);
}
Aggregations