MainActivityPresenter implements DialogInterface.OnClickListener { public void onAppLockActivateClick() { boolean appLockActivate = Utils.isAppLockActivated(sharedPreferences); if (!appLockActivate) { sharedPreferences.edit().putBoolean(Constants.APP_LOCK_ACTIVATED, true).apply(); checkAndActivateAppLock(); } else { showWarning(); } } @Inject  MainActivityPresenter(Set<String> activatedPackages, SharedPreferences sharedPreferences,
      Context context, AccessibilityChecker accessibilityChecker); void setView(MainActivityView mainActivityView); void checkAccessibilityEnabled(); void onAppLockActivateClick(); void onTimingClick(String timing); void onWarningTextClick(); void onCreditTextClick(); void onGithubClick(); @Override void onClick(DialogInterface dialog, int which);  }
@SuppressLint("CommitPrefEdits") @Test public void testOnAppLockActivate_NO_INCLUDEDPACKAGES() throws Exception { sharedPreferences.edit().putBoolean(Constants.APP_LOCK_ACTIVATED, false).commit(); given(activatedPackages.size()).willReturn(0); mainActivityPresenter.onAppLockActivateClick(); verify(mainActivityView).showToast(Constants.ADD_APPS_MESSAGE); verify(mainActivityView).launchActivity(Utils.getSettingsActivityIntent(context)); verify(mainActivityView).setActivateDrawable(pauseDrawable); assertTrue(sharedPreferences.getBoolean(Constants.APP_LOCK_ACTIVATED, false)); }
@SuppressLint("CommitPrefEdits") @Test public void testOnAppLockActivate_INCLUDEDPACKAGES() { sharedPreferences.edit().putBoolean(Constants.APP_LOCK_ACTIVATED, false).commit(); given(activatedPackages.size()).willReturn(5); mainActivityPresenter.onAppLockActivateClick(); verify(mainActivityView).showToast(Constants.OVERLAY_ACTIVATED_MESSAGE); verify(mainActivityView).launchActivity(Utils.getHomeScreenIntent()); verify(mainActivityView).setActivateDrawable(pauseDrawable); assertTrue(sharedPreferences.getBoolean(Constants.APP_LOCK_ACTIVATED, false)); }
@SuppressLint("CommitPrefEdits") @Test public void testOnAppLockActivate_APPLOCK_DEACTIVATED() { sharedPreferences.edit().putBoolean(Constants.APP_LOCK_ACTIVATED, true).commit(); mainActivityPresenter.onAppLockActivateClick(); verify(mainActivityView).hideActivateButton(); verify(mainActivityView).hideActivateHeader(); verify(mainActivityView).showWarningText(); verify(mainActivityView).setWarningText(Constants.PAUSE_WARNING_MESSAGE_FIRST); }