JUnitResultBuilder { public JUnitResult build(Result result) { boolean wasSuccessful = result.wasSuccessful(); int failureCount = result.getFailureCount(); int runCount = result.getRunCount(); JUnitResult junitResult = new JUnitResult(wasSuccessful, failureCount, runCount); List<Failure> failures = result.getFailures(); for (Failure failure : failures) { String descriptionMethodName = failure.getDescription() .getMethodName(); String exceptionClassName = failure.getException().getClass() .toString(); String message = failure.getMessage(); String trace = failure.getTrace(); boolean isAssertionError = (failure.getException() instanceof java.lang.AssertionError); JUnitFailure junitFailure = new JUnitFailure(message, exceptionClassName, descriptionMethodName, isAssertionError, trace); for (StackTraceElement elem : failure.getException() .getStackTrace()) { String elemToString = elem.toString(); junitFailure.addToExceptionStackTrace(elemToString); } junitResult.addFailure(junitFailure); } return junitResult; }  JUnitResult build(Result result);  }
@Test public void testTranslationFromJUnitRunner() { JUnitCore core = new JUnitCore(); Class<?> fooTestClass = new FooTestClassLoader().loadFooTestClass(); Result result = core.run(fooTestClass); JUnitResultBuilder builder = new JUnitResultBuilder(); JUnitResult junitResult = builder.build(result); assertFalse(junitResult.wasSuccessful()); assertEquals(1, junitResult.getFailureCount()); assertEquals(1, junitResult.getFailures().size()); JUnitFailure junitFailure = junitResult.getFailures().get(0); assertTrue(junitFailure.isAssertionError()); }