1 package org.junit.internal.requests; 2 3 import java.lang.reflect.InvocationTargetException ; 4 import java.util.Arrays ; 5 import java.util.List ; 6 7 import org.junit.internal.runners.CompositeRunner; 8 import org.junit.internal.runners.ErrorReportingRunner; 9 import org.junit.internal.runners.InitializationError; 10 import org.junit.runner.Description; 11 import org.junit.runner.Request; 12 import org.junit.runner.Runner; 13 14 public class ErrorReportingRequest extends Request { 15 16 private final Class <?> fClass; 17 private final Throwable fCause; 18 19 public ErrorReportingRequest(Class <?> klass, Throwable cause) { 20 fClass= klass; 21 fCause= cause; 22 } 23 24 @Override 25 public Runner getRunner() { 26 List <Throwable > goofs= getCauses(fCause); 27 CompositeRunner runner= new CompositeRunner(fClass.getName()); 28 for (int i= 0; i < goofs.size(); i++) { 29 final Description description= Description.createTestDescription(fClass, "initializationError" + i); 30 final Throwable throwable= goofs.get(i); 31 runner.add(new ErrorReportingRunner(description, throwable)); 32 } 33 return runner; 34 } 35 36 private List <Throwable > getCauses(Throwable cause) { 37 if (cause instanceof InvocationTargetException ) 38 return getCauses(cause.getCause()); 39 if (cause instanceof InitializationError) 40 return ((InitializationError) cause).getCauses(); 41 return Arrays.asList(cause); 42 } 43 } 44 | Popular Tags |