### Question:
MapboxUncaughtExceptionHanlder implements Thread.UncaughtExceptionHandler,
  SharedPreferences.OnSharedPreferenceChangeListener { @Override public void uncaughtException(Thread thread, Throwable throwable) { List<Throwable> causalChain; if (isEnabled.get() && isMapboxCrash(causalChain = getCausalChain(throwable))) { try { CrashReport report = CrashReportBuilder.setup(applicationContext, mapboxPackage, version) .addExceptionThread(thread) .addCausalChain(causalChain) .build(); ensureDirectoryWritable(applicationContext, mapboxPackage); File file = FileUtils.getFile(applicationContext, getReportFileName(mapboxPackage, report.getDateString())); FileUtils.writeToFile(file, report.toJson()); } catch (Exception ex) { Log.e(TAG, ex.toString()); } } if (defaultExceptionHandler != null) { defaultExceptionHandler.uncaughtException(thread, throwable); } else { Log.i(TAG, "Default exception handler is null"); } } @VisibleForTesting  MapboxUncaughtExceptionHanlder(@NonNull Context applicationContext,
                                 @NonNull SharedPreferences sharedPreferences,
                                 @NonNull String mapboxPackage,
                                 @NonNull String version,
                                 Thread.UncaughtExceptionHandler defaultExceptionHandler); static void install(@NonNull Context context, @NonNull String mapboxPackage, @NonNull String version); @Override void uncaughtException(Thread thread, Throwable throwable); @Override void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key); static final String MAPBOX_PREF_ENABLE_CRASH_REPORTER; static final String MAPBOX_CRASH_REPORTER_PREFERENCES; }### Answer:
@Test public void testDefaultExceptionHanlder() { exceptionHanlder.uncaughtException(Thread.currentThread(), new Throwable()); verify(defaultExceptionHanlder, times(1)) .uncaughtException(any(Thread.class), any(Throwable.class)); }
@Test public void testNullDefaultExceptionHanlder() { exceptionHanlder = new MapboxUncaughtExceptionHanlder(context, sharedPreferences, TELEM_MAPBOX_PACKAGE, TELEM_MAPBOX_VERSION, null); try { exceptionHanlder.uncaughtException(Thread.currentThread(), new Throwable()); } catch (Throwable throwable) { fail("Unexpected assertion due to null default handler: " + throwable.toString()); } }
@Test public void exceptionHandlerEnabledNotMapboxCrash() { exceptionHanlder.uncaughtException(Thread.currentThread(), createThrowable("HighLevelThrowable", "A", "B")); verify(context, never()).getFilesDir(); }