ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.240 by jsr166, Tue Jan 23 22:56:37 2018 UTC vs.
Revision 1.244 by jsr166, Tue Apr 10 18:09:58 2018 UTC

# Line 66 | Line 66 | import java.util.Arrays;
66   import java.util.Collection;
67   import java.util.Collections;
68   import java.util.Date;
69 + import java.util.Deque;
70   import java.util.Enumeration;
71 + import java.util.HashSet;
72   import java.util.Iterator;
73   import java.util.List;
74   import java.util.NoSuchElementException;
75   import java.util.PropertyPermission;
76 + import java.util.Set;
77   import java.util.concurrent.BlockingQueue;
78   import java.util.concurrent.Callable;
79   import java.util.concurrent.CountDownLatch;
# Line 418 | Line 421 | public class JSR166TestCase extends Test
421          for (String testClassName : testClassNames) {
422              try {
423                  Class<?> testClass = Class.forName(testClassName);
424 <                Method m = testClass.getDeclaredMethod("suite",
422 <                                                       new Class<?>[0]);
424 >                Method m = testClass.getDeclaredMethod("suite");
425                  suite.addTest(newTestSuite((Test)m.invoke(null)));
426 <            } catch (Exception e) {
427 <                throw new Error("Missing test class", e);
426 >            } catch (ReflectiveOperationException e) {
427 >                throw new AssertionError("Missing test class", e);
428              }
429          }
430      }
# Line 449 | Line 451 | public class JSR166TestCase extends Test
451      public static boolean atLeastJava8()  { return JAVA_CLASS_VERSION >= 52.0; }
452      public static boolean atLeastJava9()  { return JAVA_CLASS_VERSION >= 53.0; }
453      public static boolean atLeastJava10() { return JAVA_CLASS_VERSION >= 54.0; }
454 +    public static boolean atLeastJava11() { return JAVA_CLASS_VERSION >= 55.0; }
455  
456      /**
457       * Collects all JSR166 unit tests as one suite.
# Line 599 | Line 602 | public class JSR166TestCase extends Test
602              for (String methodName : testMethodNames(testClass))
603                  suite.addTest((Test) c.newInstance(data, methodName));
604              return suite;
605 <        } catch (Exception e) {
606 <            throw new Error(e);
605 >        } catch (ReflectiveOperationException e) {
606 >            throw new AssertionError(e);
607          }
608      }
609  
# Line 616 | Line 619 | public class JSR166TestCase extends Test
619          if (atLeastJava8()) {
620              String name = testClass.getName();
621              String name8 = name.replaceAll("Test$", "8Test");
622 <            if (name.equals(name8)) throw new Error(name);
622 >            if (name.equals(name8)) throw new AssertionError(name);
623              try {
624                  return (Test)
625                      Class.forName(name8)
626 <                    .getMethod("testSuite", new Class[] { dataClass })
626 >                    .getMethod("testSuite", dataClass)
627                      .invoke(null, data);
628 <            } catch (Exception e) {
629 <                throw new Error(e);
628 >            } catch (ReflectiveOperationException e) {
629 >                throw new AssertionError(e);
630              }
631          } else {
632              return new TestSuite();
# Line 1447 | Line 1450 | public class JSR166TestCase extends Test
1450          }
1451      }
1452  
1450    public abstract class RunnableShouldThrow implements Runnable {
1451        protected abstract void realRun() throws Throwable;
1452
1453        final Class<?> exceptionClass;
1454
1455        <T extends Throwable> RunnableShouldThrow(Class<T> exceptionClass) {
1456            this.exceptionClass = exceptionClass;
1457        }
1458
1459        public final void run() {
1460            try {
1461                realRun();
1462                threadShouldThrow(exceptionClass.getSimpleName());
1463            } catch (Throwable t) {
1464                if (! exceptionClass.isInstance(t))
1465                    threadUnexpectedException(t);
1466            }
1467        }
1468    }
1469
1453      public abstract class ThreadShouldThrow extends Thread {
1454          protected abstract void realRun() throws Throwable;
1455  
# Line 2072 | Line 2055 | public class JSR166TestCase extends Test
2055          assertEquals(savedCompletedTaskCount, p.getCompletedTaskCount());
2056          assertEquals(savedQueueSize, p.getQueue().size());
2057      }
2058 +
2059 +    void assertCollectionsEquals(Collection<?> x, Collection<?> y) {
2060 +        assertEquals(x, y);
2061 +        assertEquals(y, x);
2062 +        assertEquals(x.isEmpty(), y.isEmpty());
2063 +        assertEquals(x.size(), y.size());
2064 +        if (x instanceof List) {
2065 +            assertEquals(x.toString(), y.toString());
2066 +        }
2067 +        if (x instanceof List || x instanceof Set) {
2068 +            assertEquals(x.hashCode(), y.hashCode());
2069 +        }
2070 +        if (x instanceof List || x instanceof Deque) {
2071 +            assertTrue(Arrays.equals(x.toArray(), y.toArray()));
2072 +            assertTrue(Arrays.equals(x.toArray(new Object[0]),
2073 +                                     y.toArray(new Object[0])));
2074 +        }
2075 +    }
2076 +
2077 +    /**
2078 +     * A weaker form of assertCollectionsEquals which does not insist
2079 +     * that the two collections satisfy Object#equals(Object), since
2080 +     * they may use identity semantics as Deques do.
2081 +     */
2082 +    void assertCollectionsEquivalent(Collection<?> x, Collection<?> y) {
2083 +        if (x instanceof List || x instanceof Set)
2084 +            assertCollectionsEquals(x, y);
2085 +        else {
2086 +            assertEquals(x.isEmpty(), y.isEmpty());
2087 +            assertEquals(x.size(), y.size());
2088 +            assertEquals(new HashSet(x), new HashSet(y));
2089 +            if (x instanceof Deque) {
2090 +                assertTrue(Arrays.equals(x.toArray(), y.toArray()));
2091 +                assertTrue(Arrays.equals(x.toArray(new Object[0]),
2092 +                                         y.toArray(new Object[0])));
2093 +            }
2094 +        }
2095 +    }
2096   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines