ExceptionERDC implements ErrorReportDataCollector { @Override public Map<String, String> collect(ErrorReportCollectingContext context) { HashMap<String, String> r = new HashMap<>(); Throwable throwable = context.getThrowable(); r.put(EXCEPTION, throwable.getClass().getName()); r.put(MESSAGE, throwable.getMessage()); r.put(THREAD, context.getThread().getName()); r.put(MESSAGE_LOCALIZED, throwable.getLocalizedMessage()); r.put(STACKTRACE, Throwables.getStackTraceAsString(throwable)); return r; }  @Override Map<String, String> collect(ErrorReportCollectingContext context); static final String EXCEPTION; static final String MESSAGE; static final String THREAD; static final String MESSAGE_LOCALIZED; static final String STACKTRACE; }
@Test public void testCollect() throws Exception { Exception exception = new Exception("msg"); ErrorReportCollectingContext context = new ErrorReportCollectingContext(); context.setThrowable(exception); context.setThread(Thread.currentThread()); Map<String, String> collect = new ExceptionERDC().collect(context); assertEquals("msg",collect.get(ExceptionERDC.MESSAGE)); assertEquals("java.lang.Exception",collect.get(ExceptionERDC.EXCEPTION)); assertTrue(collect.containsKey(ExceptionERDC.THREAD)); assertEquals("msg",collect.get(ExceptionERDC.MESSAGE_LOCALIZED)); assertTrue(collect.containsKey(ExceptionERDC.STACKTRACE)); }