1 package junitour;
2
3 import junit.framework.AssertionFailedError;
4 import java.util.WeakHashMap;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public class UnitTestIncompleteError extends AssertionFailedError implements UnitTestIncomplete {
39 private static WeakHashMap<Class,Boolean> clazzCache = new WeakHashMap<Class,Boolean>(200);
40
41
42 public UnitTestIncompleteError() {
43 super();
44 }
45
46 public UnitTestIncompleteError(final String message) {
47 super(message);
48 }
49
50 public UnitTestIncompleteError(final String message, final Throwable cause) {
51 super(message);
52 super.initCause(cause);
53 }
54
55 public UnitTestIncompleteError(final Throwable cause) {
56 super();
57 super.initCause(cause);
58 }
59
60 public static boolean isTestIncompleteError(final Throwable t) {
61 if (t == null) return false;
62
63 debug ("testing ["+t+"] of class ["+t.getClass()+"] which implements these interfaces ["+t.getClass().getInterfaces()+"]");
64
65 final Class aClass = t.getClass();
66 final Boolean cachedClazzCheck = clazzCache.get(aClass);
67 if( cachedClazzCheck!=null )
68 return cachedClazzCheck;
69
70 if (UnitTestIncompleteError.class.getName().equals(aClass.getName())) {
71 return true;
72 }
73 if (UnitTestIncompleteError.class.isInstance(t)) {
74 return true;
75 }
76 if (UnitTestIncomplete.class.isInstance(t)) {
77 return true;
78 }
79
80 if (UnitTestIncomplete.class.isAssignableFrom(aClass)) {
81 return true;
82 }
83
84
85 final Class[] interfaces = aClass.getInterfaces();
86 if( checkIncomplete(interfaces) ) {
87 clazzCache.put(aClass, Boolean.TRUE);
88 return true;
89 }
90 clazzCache.put(aClass, Boolean.FALSE);
91 return false;
92 }
93
94 private static void debug(String s) {
95 System.err.println("UnitTestIncomplete:"+s);
96 }
97
98
99
100
101
102
103
104 private static boolean checkIncomplete(Class[] interfaces) {
105 if( interfaces==null ) return false;
106
107 for (int i = 0; i < interfaces.length; i++) {
108 Class anInterface = interfaces[i];
109 if (anInterface.getName().equals(UnitTestIncomplete.class.getName())) {
110
111 return true;
112 }
113 }
114 return false;
115 }
116
117 }