KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > junit > internal > requests > ErrorReportingRequest


1 package org.junit.internal.requests;
2
3 import java.lang.reflect.InvocationTargetException JavaDoc;
4 import java.util.Arrays JavaDoc;
5 import java.util.List JavaDoc;
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 JavaDoc<?> fClass;
17     private final Throwable JavaDoc fCause;
18
19     public ErrorReportingRequest(Class JavaDoc<?> klass, Throwable JavaDoc cause) {
20         fClass= klass;
21         fCause= cause;
22     }
23
24     @Override JavaDoc
25     public Runner getRunner() {
26         List JavaDoc<Throwable JavaDoc> 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 JavaDoc throwable= goofs.get(i);
31             runner.add(new ErrorReportingRunner(description, throwable));
32         }
33         return runner;
34     }
35     
36     private List JavaDoc<Throwable JavaDoc> getCauses(Throwable JavaDoc cause) {
37         if (cause instanceof InvocationTargetException JavaDoc)
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