@Test public void testExceptionHandler() throws Exception { assertFalse(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); track().uncaughtExceptions().with(mTracker); assertTrue(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); try { //noinspection NumericOverflow int i = 1 / 0; assertNotEquals(i, 0); } catch (Exception e) { (Thread.getDefaultUncaughtExceptionHandler()).uncaughtException(Thread.currentThread(), e); } verify(mTracker).track(mCaptor.capture()); TrackMe tracked = mCaptor.getValue(); assertEquals(tracked.get(QueryParams.EVENT_CATEGORY), "Exception"); assertTrue(tracked.get(QueryParams.EVENT_ACTION).startsWith("org.matomo.sdk.extra.TrackHelperTest/testExceptionHandler:")); assertEquals(tracked.get(QueryParams.EVENT_NAME), "/ by zero"); assertEquals(tracked.get(QueryParams.EVENT_VALUE), "1"); boolean exception = false; try { track().uncaughtExceptions().with(mTracker); } catch (RuntimeException e) { exception = true; } assertTrue(exception); } }
@Test public void testExceptionHandler() throws Exception { assertFalse(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); track().uncaughtExceptions().with(mTracker); assertTrue(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler); try { //noinspection NumericOverflow int i = 1 / 0; assertNotEquals(i, 0); } catch (Exception e) { (Thread.getDefaultUncaughtExceptionHandler()).uncaughtException(Thread.currentThread(), e); } verify(mTracker).track(mCaptor.capture()); TrackMe tracked = mCaptor.getValue(); assertEquals(tracked.get(QueryParams.EVENT_CATEGORY), "Exception"); assertTrue(tracked.get(QueryParams.EVENT_ACTION).startsWith("org.matomo.sdk.extra.TrackHelperTest/testExceptionHandler:")); assertEquals(tracked.get(QueryParams.EVENT_NAME), "/ by zero"); assertEquals(tracked.get(QueryParams.EVENT_VALUE), "1"); boolean exception = false; try { track().uncaughtExceptions().with(mTracker); } catch (RuntimeException e) { exception = true; } assertTrue(exception); } }