DeviceAdminActivity extends FragmentActivity { protected void displayLoginScreen() { finish(); LoginActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); }  @Override void onActivityResult(int requestCode, int resultCode, Intent data);  }
@Test public void shouldDisplayLoginActivityIfDeviceAdminPermissionIsEnabled() { when(devicePolicyManager.isAdminActive((ComponentName) anyObject())).thenReturn(true); activityController.create(); verify(devicePolicyManager).isAdminActive((ComponentName) anyObject()); verify(deviceAdminActivity).displayLoginScreen(); }
@Test public void shouldStartLoginActivityWhenRequested(){ when(devicePolicyManager.isAdminActive((ComponentName) anyObject())).thenReturn(true); ShadowActivity shadowActivity = shadowOf_(deviceAdminActivity); deviceAdminActivity.displayLoginScreen(); ShadowIntent shadowIntent = shadowOf_(shadowActivity.getNextStartedActivity()); assertEquals(shadowIntent.getFlags(), Intent.FLAG_ACTIVITY_CLEAR_TOP); assertThat(shadowIntent.getComponent().getClassName(), equalTo(LoginActivity_.class.getName())); }