< prev index next >

test/java/lang/StackWalker/StackRecorderUtil.java

Print this page




  83         }
  84 
  85         if (compareClassNames && !tf.className().equals(sf.getClassName())) {
  86             throw new RuntimeException("Expected class name: " + tf.className() +
  87                     ", but got: " + sf.getClassName());
  88         }
  89         if (compareMethodNames && !tf.methodName.equals(sf.getMethodName())) {
  90             throw new RuntimeException("Expected method name: " + tf.methodName +
  91                     ", but got: " + sf.getMethodName());
  92         }
  93         if (compareSTEs) {
  94             StackTraceElement ste = sf.toStackTraceElement();
  95             if (!(ste.getClassName().equals(tf.className()) &&
  96                   ste.getMethodName().equals(tf.methodName)) &&
  97                   ste.getFileName().equals(tf.fileName)) {
  98                 throw new RuntimeException("Expected StackTraceElement info: " +
  99                         tf + ", but got: " + ste);
 100             }
 101             if (!Objects.equals(ste.getClassName(), sf.getClassName())
 102                 || !Objects.equals(ste.getMethodName(), sf.getMethodName())
 103                 || !Objects.equals(ste.getFileName(), sf.getFileName().orElse(null))
 104                 || !Objects.equals(ste.getLineNumber(), sf.getLineNumber().orElse(-1))
 105                 || !Objects.equals(ste.isNativeMethod(), sf.isNativeMethod())) {
 106                 throw new RuntimeException("StackFrame and StackTraceElement differ: " +
 107                         "sf=" + sf + ", ste=" + ste);
 108             }
 109         }
 110     }
 111 
 112     public Iterator<TestFrame> iterator() {
 113         return testFrames.iterator();
 114     }
 115 
 116     /**
 117      * Class used to record stack frame information.
 118      */
 119     public static class TestFrame {
 120         public Class declaringClass;
 121         public String methodName;
 122         public String fileName = null;
 123 
 124         public TestFrame (Class declaringClass, String methodName, String fileName) {


  83         }
  84 
  85         if (compareClassNames && !tf.className().equals(sf.getClassName())) {
  86             throw new RuntimeException("Expected class name: " + tf.className() +
  87                     ", but got: " + sf.getClassName());
  88         }
  89         if (compareMethodNames && !tf.methodName.equals(sf.getMethodName())) {
  90             throw new RuntimeException("Expected method name: " + tf.methodName +
  91                     ", but got: " + sf.getMethodName());
  92         }
  93         if (compareSTEs) {
  94             StackTraceElement ste = sf.toStackTraceElement();
  95             if (!(ste.getClassName().equals(tf.className()) &&
  96                   ste.getMethodName().equals(tf.methodName)) &&
  97                   ste.getFileName().equals(tf.fileName)) {
  98                 throw new RuntimeException("Expected StackTraceElement info: " +
  99                         tf + ", but got: " + ste);
 100             }
 101             if (!Objects.equals(ste.getClassName(), sf.getClassName())
 102                 || !Objects.equals(ste.getMethodName(), sf.getMethodName())
 103                 || !Objects.equals(ste.getFileName(), sf.getFileName())
 104                 || !Objects.equals(ste.getLineNumber(), sf.getLineNumber())
 105                 || !Objects.equals(ste.isNativeMethod(), sf.isNativeMethod())) {
 106                 throw new RuntimeException("StackFrame and StackTraceElement differ: " +
 107                         "sf=" + sf + ", ste=" + ste);
 108             }
 109         }
 110     }
 111 
 112     public Iterator<TestFrame> iterator() {
 113         return testFrames.iterator();
 114     }
 115 
 116     /**
 117      * Class used to record stack frame information.
 118      */
 119     public static class TestFrame {
 120         public Class declaringClass;
 121         public String methodName;
 122         public String fileName = null;
 123 
 124         public TestFrame (Class declaringClass, String methodName, String fileName) {
< prev index next >