< prev index next >

modules/graphics/src/test/java/com/sun/glass/ui/monocle/TestLogShim.java

Print this page
rev 9504 : need to fix test log and others

@@ -23,18 +23,16 @@
  * questions.
  */
 
 package com.sun.glass.ui.monocle;
 
-import junit.framework.AssertionFailedError;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Formatter;
 import java.util.List;
 
-public class TestLog {
+public class TestLogShim {
 
     private static final boolean verbose = Boolean.getBoolean("verbose");
     private static final double timeScale = Double.parseDouble(
             System.getProperty("timeScale", "1"));
 

@@ -43,10 +41,16 @@
     private static final List<String> log = new ArrayList<>();
     private static final Object lock = new Object();
 
     private static long startTime = System.currentTimeMillis();
 
+    public static class TestLogAssertion extends Exception {
+        public TestLogAssertion(String message) {
+            super(message);
+        }
+    }
+
     public static void log(String s) {
         synchronized (lock) {
             if (verbose) {
                 System.out.println(timestamp() + " TestLog: " + s);
             }

@@ -153,35 +157,35 @@
 
     public static boolean checkLogContaining(String s) {
         return checkLog(new String[] {s}, 0, false) != null;
     }
 
-    public static void assertLog(String s) {
+    public static void assertLog(String s) throws TestLogAssertion {
         synchronized (lock) {
             if (!checkLog(s)) {
                 String err = "No line '" + s + "' in log";
                 if (verbose) {
                     System.out.println(err);
                 }
-                throw new AssertionFailedError(err);
+                throw new TestLogAssertion(err);
             }
         }
     }
 
-    public static void assertLogContaining(String s) {
+    public static void assertLogContaining(String s) throws TestLogAssertion {
         synchronized (lock) {
             if (!checkLogContaining(s)) {
                 String err = "No line containing '" + s + "' in log";
                 if (verbose) {
                     System.out.println(err);
                 }
-                throw new AssertionFailedError(err);
+                throw new TestLogAssertion(err);
             }
         }
     }
 
-    private static String waitForLog(String[] s, long timeout, boolean exact) throws InterruptedException {
+    private static String waitForLog(String[] s, long timeout, boolean exact) throws InterruptedException, TestLogAssertion {
         long startTime = System.currentTimeMillis();
         long timeNow = startTime;
         long endTime = timeNow + (long) (timeout * timeScale);
         String line;
         String logString = Arrays.toString(s).substring(1, Arrays.toString(s).length() - 1);

@@ -202,11 +206,11 @@
                         for (String logLine: log) {
                             System.out.println(logLine);
                         }
                     }
                     System.out.println(message);
-                    throw new AssertionFailedError(message);
+                    throw new TestLogAssertion(message);
                 }
             }
         }
         long matchTime = System.currentTimeMillis() - startTime;
         if (verbose) {

@@ -223,27 +227,27 @@
             }
         }
         return line;
     }
 
-    public static String waitForLog(String s, long timeout) throws InterruptedException {
+    public static String waitForLog(String s, long timeout) throws InterruptedException, TestLogAssertion {
         return waitForLog(new String [] {s}, timeout, true);
     }
 
-    public static String waitForLogContaining(String s, long timeout) throws InterruptedException {
+    public static String waitForLogContaining(String s, long timeout) throws InterruptedException, TestLogAssertion {
         return waitForLog(new String [] {s}, timeout, false);
     }
 
-    public static String waitForLog(String format, Object... args) throws InterruptedException {
+    public static String waitForLog(String format, Object... args) throws InterruptedException, TestLogAssertion {
         return waitForLog(new Formatter().format(format, args).toString(),
                           DEFAULT_TIMEOUT);
     }
 
-    public static String waitForLogContaining(String format, Object... args) throws InterruptedException {
+    public static String waitForLogContaining(String format, Object... args) throws InterruptedException, TestLogAssertion {
         return waitForLogContaining(new Formatter().format(format, args).toString(),
                           DEFAULT_TIMEOUT);
     }
 
-    public static String waitForLogContainingSubstrings(String... s) throws InterruptedException {
+    public static String waitForLogContainingSubstrings(String... s) throws InterruptedException, TestLogAssertion {
         return waitForLog(s, DEFAULT_TIMEOUT, false);
     }
 }
< prev index next >