SafetyNet { public void executeSafely(Runnable runnable) { try { runnable.run(); } catch (Throwable t) { Logger.e("Exception catch", t); reportException(t); } } SafetyNet(CrashReporterApiClient crashReporterApiClient);   SafetyNet(CrashReporterApiClient crashReporterApiClient, boolean forceMainThreadReport); void executeSafelyOnNewThread(final Runnable runnable); void executeSafely(Runnable runnable);  }
@Test public void sendsTheExceptionCatchToTheCrashReporterApiClient() { NullPointerException nullPointerException = new NullPointerException(); BrokenRunnable brokenRunnable = new BrokenRunnable(nullPointerException); safetyNet.executeSafely(brokenRunnable); verify(apiClient).reportError(nullPointerException); }
@Test public void doesNotSendAnyExceptionIfThereIsNoCrash() { safetyNet.executeSafely(new Runnable() { @Override public void run() { } }); verify(apiClient, never()).reportError(any(Throwable.class)); }