@Override protected void failed(Throwable e, Description description) { System.out.println("Failure detected. Printing found telemetry:"); List<Telemetry> telemetries = LogChannelMockVerifier.INSTANCE.getTelemetryCollection(); for (Telemetry t : telemetries) { String tname = t.getClass().getSimpleName(); String tinfo = tname; if (t instanceof TraceTelemetry) { TraceTelemetry trct = (TraceTelemetry)t; tinfo = String.format("%s{message='%s'}", tname, trct.getMessage()); } else if (t instanceof ExceptionTelemetry) { ExceptionTelemetry ext = (ExceptionTelemetry)t; tinfo = String.format("%s{%s[message='%s']}", tname, ext.getException().getClass().getSimpleName(), ext.getException().getMessage()); } System.out.println(" - "+tinfo); } System.out.printf("%d total telemetries collected.%n", telemetries.size()); } };
@Test public void testCtor() { NullPointerException exception = new NullPointerException("mock"); ExceptionTelemetry exceptionTelemetry = new ExceptionTelemetry(exception); assertSame(exception, exceptionTelemetry.getException()); assertTrue(exceptionTelemetry.getProperties().isEmpty()); assertTrue(exceptionTelemetry.getMetrics().isEmpty()); assertThat(exceptionTelemetry.getExceptions(), hasSize(1)); }
@Test public void testSetException() { NullPointerException exception = new NullPointerException("mock"); ExceptionTelemetry exceptionTelemetry = new ExceptionTelemetry(exception); NullPointerException exception1 = new NullPointerException("mock"); exceptionTelemetry.setException(exception1); assertSame(exception1, exceptionTelemetry.getException()); }
@Test public void testGetThrowableOnException() { IOException exception = new IOException("mock"); ExceptionTelemetry telemetry = new ExceptionTelemetry(exception); assertSame(exception, telemetry.getThrowable()); assertSame(exception, telemetry.getException()); }
@Test public void testError() { Error error = new NoSuchMethodError("Method"); ExceptionTelemetry telemetry = new ExceptionTelemetry(error); assertNull(telemetry.getException()); assertSame(error, telemetry.getThrowable()); }