Update of /cvsroot/cweb/junit-ext/src/java/junit/framework
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv5364/src/java/junit/framework
Modified Files:
TestCase2.java
Log Message:
Added getInnerCause and isInnerCause.
Index: TestCase2.java
===================================================================
RCS file: /cvsroot/cweb/junit-ext/src/java/junit/framework/TestCase2.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** TestCase2.java 10 Sep 2007 11:09:13 -0000 1.24
--- TestCase2.java 18 Oct 2007 16:53:59 -0000 1.25
***************
*** 2254,2258 ****
// * Place. This specifies how big an error we are willing to accept
// * in terms of the value of the least significant digit of the
! // * floating point number's representation. <i>maxUlps</i> can
// * also be interpreted in terms of how many representable floats
// * we are willing to accept between A and B. This function will
--- 2254,2258 ----
// * Place. This specifies how big an error we are willing to accept
// * in terms of the value of the least significant digit of the
! // * floating point numbers representation. <i>maxUlps</i> can
// * also be interpreted in terms of how many representable floats
// * we are willing to accept between A and B. This function will
***************
*** 2329,2333 ****
// * Place. This specifies how big an error we are willing to accept
// * in terms of the value of the least significant digit of the
! // * floating point number's representation. <i>maxUlps</i> can
// * also be interpreted in terms of how many representable doubles
// * we are willing to accept between A and B. This function will
--- 2329,2333 ----
// * Place. This specifies how big an error we are willing to accept
// * in terms of the value of the least significant digit of the
! // * floating point numbers representation. <i>maxUlps</i> can
// * also be interpreted in terms of how many representable doubles
// * we are willing to accept between A and B. This function will
***************
*** 2590,2592 ****
--- 2590,2657 ----
}
+ /**
+ * Examines a stack trace for an instance of the specified cause nested to
+ * any level within that stack trace.
+ *
+ * @param t
+ * The stack trace.
+ * @param cls
+ * The class of exception that you are looking for in the stack
+ * trace.
+ *
+ * @return An exception that is an instance of that class iff one exists in
+ * the stack trace and <code>null</code> otherwise.
+ *
+ * @throws IllegalArgumentException
+ * if any parameter is null.
+ */
+ static public Throwable getInnerCause(Throwable t, Class<? extends Throwable> cls) {
+
+ if (t == null)
+ throw new IllegalArgumentException();
+
+ if (cls == null)
+ throw new IllegalArgumentException();
+
+ {
+ Class x = t.getClass();
+ while(x != null){
+ if( x == cls)
+ return t;
+ x = x.getSuperclass();
+ }
+
+ }
+
+ t = t.getCause();
+
+ if (t == null)
+ return null;
+
+ return getInnerCause(t, cls);
+
+ }
+
+ /**
+ * Examines a stack trace for an instance of the specified cause nested to
+ * any level within that stack trace.
+ *
+ * @param t
+ * The stack trace.
+ * @param cls
+ * The class of exception that you are looking for in the stack
+ * trace.
+ *
+ * @return <code>true</code> iff an exception that is an instance of that
+ * class iff one exists in the stack trace.
+ *
+ * @throws IllegalArgumentException
+ * if any parameter is null.
+ */
+ static public boolean isInnerCause(Throwable t, Class<? extends Throwable>cls) {
+
+ return getInnerCause(t, cls) != null;
+
+ }
+
}
|