01: package com.reeltwo.jumble.util;
02:
03: import java.util.HashSet;
04: import java.util.Set;
05:
06: import junit.framework.Test;
07:
08: /**
09: * Class containing several utility methods useful to Jumble.
10: *
11: * @author Tin Pavlinic
12: * @version $Revision: 495 $
13: */
14: public class JumbleUtils {
15: private JumbleUtils() {
16: }
17:
18: /**
19: * Determines whether a given class is a test class.
20: *
21: * @param clazz
22: * the class to check.
23: * @return true if the class is a test class, false otherwise.
24: */
25: public static boolean isTestClass(Class clazz) {
26: Set interfaceSet = new HashSet();
27: Class tmp = clazz;
28:
29: while (tmp != Object.class) {
30: Class[] intfc = tmp.getInterfaces();
31: for (int i = 0; i < intfc.length; i++) {
32: interfaceSet.add(intfc[i]);
33: }
34: tmp = tmp.getSuperclass();
35: }
36:
37: Class[] interfaces = (Class[]) interfaceSet
38: .toArray(new Class[interfaceSet.size()]);
39:
40: for (int i = 0; i < interfaces.length; i++) {
41: if (interfaces[i] == Test.class) {
42: return true;
43: }
44: }
45: return false;
46: }
47:
48: /**
49: * Gets whether assertions are currently enabled.
50: *
51: * @return whether assertions are currently enabled
52: *
53: */
54: public static boolean isAssertionsEnabled() {
55: boolean assertionsEnabled = false;
56: assert assertionsEnabled = true;
57: return assertionsEnabled;
58: }
59: }
|