Push extends AbstractAppCenterService { public static AppCenterFuture<Void> setEnabled(boolean enabled) { return getInstance().setInstanceEnabledAsync(enabled); } private  Push(); static synchronized Push getInstance(); static AppCenterFuture<Boolean> isEnabled(); static AppCenterFuture<Void> setEnabled(boolean enabled); static void setListener(PushListener pushListener); @SuppressWarnings("JavadocReference") static void checkLaunchedFromNotification(Activity activity, Intent intent); @Deprecated static void setSenderId(@SuppressWarnings("SameParameterValue") String senderId); static void enableFirebaseAnalytics(@NonNull Context context); @Override String getServiceName(); @Override Map<String, LogFactory> getLogFactories(); @Override synchronized void onStarted(@NonNull Context context, @NonNull Channel channel, String appSecret, String transmissionTargetToken, boolean startedFromApp); @Override void onActivityCreated(Activity activity, Bundle savedInstanceState); @Override void onActivityStarted(Activity activity); @Override synchronized void onActivityResumed(Activity activity); @Override void onActivityPaused(Activity activity);  }
@Test public void setEnabled() throws InterruptedException { assertFalse(Push.isEnabled().get()); verifyStatic(); AppCenterLog.error(anyString(), anyString()); String testToken = "TEST"; Push push = Push.getInstance(); Channel channel = mock(Channel.class); start(push, channel); verify(channel).removeGroup(eq(push.getGroupName())); assertTrue(Push.isEnabled().get()); verify(mPackageManager).setComponentEnabledSetting(any(ComponentName.class), eq(PackageManager.COMPONENT_ENABLED_STATE_DEFAULT), eq(PackageManager.DONT_KILL_APP)); verify(mFirebaseInstanceIdResult).addOnSuccessListener(mFirebaseInstanceIdSuccessListener.capture()); assertNotNull(mFirebaseInstanceIdSuccessListener.getValue()); InstanceIdResult result = mock(InstanceIdResult.class); when(result.getToken()).thenReturn(testToken); mFirebaseInstanceIdSuccessListener.getValue().onSuccess(result); ArgumentCaptor<PushInstallationLog> log = ArgumentCaptor.forClass(PushInstallationLog.class); verify(channel).enqueue(log.capture(), eq(push.getGroupName()), eq(DEFAULTS)); assertEquals(testToken, log.getValue().getPushToken()); Push.setEnabled(true); assertTrue(Push.isEnabled().get()); verify(mFirebaseInstanceIdResult).addOnSuccessListener(mFirebaseInstanceIdSuccessListener.capture()); verify(channel).enqueue(any(PushInstallationLog.class), eq(push.getGroupName()), eq(DEFAULTS)); Push.setEnabled(false).get(); assertFalse(Push.isEnabled().get()); verify(channel).clear(push.getGroupName()); verify(channel, times(2)).removeGroup(eq(push.getGroupName())); final CountDownLatch latch = new CountDownLatch(1); Push.setEnabled(false).thenAccept(new AppCenterConsumer<Void>() { @Override public void accept(Void aVoid) { latch.countDown(); } }); assertTrue(latch.await(0, TimeUnit.MILLISECONDS)); push.onTokenRefresh(testToken); verify(mFirebaseInstanceIdResult).addOnSuccessListener(mFirebaseInstanceIdSuccessListener.capture()); verify(channel).enqueue(any(PushInstallationLog.class), eq(push.getGroupName()), eq(DEFAULTS)); Activity activity = mock(Activity.class); when(activity.getIntent()).thenReturn(mock(Intent.class)); push.onActivityResumed(activity); verifyStatic(); AppCenterLog.error(anyString(), anyString()); verify(mFirebaseAnalyticsInstance).setAnalyticsCollectionEnabled(false); verify(mFirebaseAnalyticsInstance, never()).setAnalyticsCollectionEnabled(true); Push.unsetInstance(); push = Push.getInstance(); start(push, channel); verify(mFirebaseAnalyticsInstance, times(2)).setAnalyticsCollectionEnabled(false); verify(mFirebaseAnalyticsInstance, never()).setAnalyticsCollectionEnabled(true); }