Crashes extends AbstractAppCenterService { public static AppCenterFuture<Void> setEnabled(boolean enabled) { return getInstance().setInstanceEnabledAsync(enabled); } private  Crashes(); @NonNull static synchronized Crashes getInstance(); static AppCenterFuture<Boolean> isEnabled(); static AppCenterFuture<Void> setEnabled(boolean enabled); @SuppressWarnings({"SameParameterValue", "WeakerAccess"}) static void trackError(Throwable throwable); static void trackError(Throwable throwable, Map<String, String> properties, Iterable<ErrorAttachmentLog> attachments); static void generateTestCrash(); static void setListener(CrashesListener listener); static AppCenterFuture<String> getMinidumpDirectory(); static void notifyUserConfirmation(@UserConfirmationDef int userConfirmation); static AppCenterFuture<Boolean> hasCrashedInLastSession(); static AppCenterFuture<ErrorReport> getLastSessionCrashReport(); static AppCenterFuture<Boolean> hasReceivedMemoryWarningInLastSession(); @Override synchronized void onStarted(@NonNull Context context, @NonNull Channel channel, String appSecret, String transmissionTargetToken, boolean startedFromApp); @Override Map<String, LogFactory> getLogFactories(); @Override String getServiceName(); static final int SEND; static final int DONT_SEND; static final int ALWAYS_SEND; @VisibleForTesting
    static final String PREF_KEY_ALWAYS_SEND; static final String LOG_TAG; }
@Test public void setEnabled() { Crashes crashes = Crashes.getInstance(); mockStatic(ErrorLogHelper.class); Channel mockChannel = mock(Channel.class); File dir = mock(File.class); File file1 = mock(File.class); File file2 = mock(File.class); when(ErrorLogHelper.getErrorStorageDirectory()).thenReturn(dir); when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[0]); when(ErrorLogHelper.getNewMinidumpFiles()).thenReturn(new File[0]); when(dir.listFiles()).thenReturn(new File[]{file1, file2}); assertFalse(Crashes.isEnabled().get()); assertEquals(0, crashes.getInitializeTimestamp()); crashes.onStarting(mAppCenterHandler); crashes.onStarted(mock(Context.class), mockChannel, "", null, true); verify(mockChannel).removeGroup(eq(crashes.getGroupName())); verify(mockChannel).addGroup(eq(crashes.getGroupName()), anyInt(), anyInt(), anyInt(), isNull(Ingestion.class), any(Channel.GroupListener.class)); assertTrue(Crashes.isEnabled().get()); Crashes.setEnabled(true); assertTrue(Crashes.isEnabled().get()); assertTrue(crashes.getInitializeTimestamp() > 0); Crashes.setEnabled(false); assertFalse(Crashes.isEnabled().get()); verify(mockChannel).clear(crashes.getGroupName()); verify(mockChannel, times(2)).removeGroup(eq(crashes.getGroupName())); assertEquals(crashes.getInitializeTimestamp(), -1); assertFalse(Thread.getDefaultUncaughtExceptionHandler() instanceof UncaughtExceptionHandler); assertFalse(verify(file1).delete()); assertFalse(verify(file2).delete()); Crashes.trackError(EXCEPTION); verifyNoMoreInteractions(mockChannel); Crashes.setEnabled(true); assertTrue(Crashes.isEnabled().get()); assertTrue(crashes.getInitializeTimestamp() > 0); assertTrue(Thread.getDefaultUncaughtExceptionHandler() instanceof UncaughtExceptionHandler); Crashes.setEnabled(true); assertTrue(Crashes.isEnabled().get()); verify(mockChannel, times(2)).addGroup(eq(crashes.getGroupName()), anyInt(), anyInt(), anyInt(), isNull(Ingestion.class), any(Channel.GroupListener.class)); Crashes.trackError(EXCEPTION); verify(mockChannel, times(1)).enqueue(isA(HandledErrorLog.class), eq(crashes.getGroupName()), eq(DEFAULTS)); }