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.238 by jsr166, Mon Dec 11 00:27:08 2017 UTC vs.
Revision 1.239 by jsr166, Tue Jan 23 20:44:11 2018 UTC

# Line 99 | Line 99 | import java.util.concurrent.atomic.Atomi
99   import java.util.concurrent.atomic.AtomicReference;
100   import java.util.regex.Pattern;
101  
102 import junit.framework.AssertionFailedError;
102   import junit.framework.Test;
103   import junit.framework.TestCase;
104   import junit.framework.TestResult;
# Line 733 | Line 732 | public class JSR166TestCase extends Test
732          String msg = toString() + ": " + String.format(format, args);
733          System.err.println(msg);
734          dumpTestThreads();
735 <        throw new AssertionFailedError(msg);
735 >        throw new AssertionError(msg);
736      }
737  
738      /**
# Line 754 | Line 753 | public class JSR166TestCase extends Test
753                  throw (RuntimeException) t;
754              else if (t instanceof Exception)
755                  throw (Exception) t;
756 <            else {
757 <                AssertionFailedError afe =
759 <                    new AssertionFailedError(t.toString());
760 <                afe.initCause(t);
761 <                throw afe;
762 <            }
756 >            else
757 >                throw new AssertionError(t.toString(), t);
758          }
759  
760          if (Thread.interrupted())
# Line 793 | Line 788 | public class JSR166TestCase extends Test
788  
789      /**
790       * Just like fail(reason), but additionally recording (using
791 <     * threadRecordFailure) any AssertionFailedError thrown, so that
792 <     * the current testcase will fail.
791 >     * threadRecordFailure) any AssertionError thrown, so that the
792 >     * current testcase will fail.
793       */
794      public void threadFail(String reason) {
795          try {
796              fail(reason);
797 <        } catch (AssertionFailedError t) {
798 <            threadRecordFailure(t);
799 <            throw t;
797 >        } catch (AssertionError fail) {
798 >            threadRecordFailure(fail);
799 >            throw fail;
800          }
801      }
802  
803      /**
804       * Just like assertTrue(b), but additionally recording (using
805 <     * threadRecordFailure) any AssertionFailedError thrown, so that
806 <     * the current testcase will fail.
805 >     * threadRecordFailure) any AssertionError thrown, so that the
806 >     * current testcase will fail.
807       */
808      public void threadAssertTrue(boolean b) {
809          try {
810              assertTrue(b);
811 <        } catch (AssertionFailedError t) {
812 <            threadRecordFailure(t);
813 <            throw t;
811 >        } catch (AssertionError fail) {
812 >            threadRecordFailure(fail);
813 >            throw fail;
814          }
815      }
816  
817      /**
818       * Just like assertFalse(b), but additionally recording (using
819 <     * threadRecordFailure) any AssertionFailedError thrown, so that
820 <     * the current testcase will fail.
819 >     * threadRecordFailure) any AssertionError thrown, so that the
820 >     * current testcase will fail.
821       */
822      public void threadAssertFalse(boolean b) {
823          try {
824              assertFalse(b);
825 <        } catch (AssertionFailedError t) {
826 <            threadRecordFailure(t);
827 <            throw t;
825 >        } catch (AssertionError fail) {
826 >            threadRecordFailure(fail);
827 >            throw fail;
828          }
829      }
830  
831      /**
832       * Just like assertNull(x), but additionally recording (using
833 <     * threadRecordFailure) any AssertionFailedError thrown, so that
834 <     * the current testcase will fail.
833 >     * threadRecordFailure) any AssertionError thrown, so that the
834 >     * current testcase will fail.
835       */
836      public void threadAssertNull(Object x) {
837          try {
838              assertNull(x);
839 <        } catch (AssertionFailedError t) {
840 <            threadRecordFailure(t);
841 <            throw t;
839 >        } catch (AssertionError fail) {
840 >            threadRecordFailure(fail);
841 >            throw fail;
842          }
843      }
844  
845      /**
846       * Just like assertEquals(x, y), but additionally recording (using
847 <     * threadRecordFailure) any AssertionFailedError thrown, so that
848 <     * the current testcase will fail.
847 >     * threadRecordFailure) any AssertionError thrown, so that the
848 >     * current testcase will fail.
849       */
850      public void threadAssertEquals(long x, long y) {
851          try {
852              assertEquals(x, y);
853 <        } catch (AssertionFailedError t) {
854 <            threadRecordFailure(t);
855 <            throw t;
853 >        } catch (AssertionError fail) {
854 >            threadRecordFailure(fail);
855 >            throw fail;
856          }
857      }
858  
859      /**
860       * Just like assertEquals(x, y), but additionally recording (using
861 <     * threadRecordFailure) any AssertionFailedError thrown, so that
862 <     * the current testcase will fail.
861 >     * threadRecordFailure) any AssertionError thrown, so that the
862 >     * current testcase will fail.
863       */
864      public void threadAssertEquals(Object x, Object y) {
865          try {
866              assertEquals(x, y);
867 <        } catch (AssertionFailedError fail) {
867 >        } catch (AssertionError fail) {
868              threadRecordFailure(fail);
869              throw fail;
870          } catch (Throwable fail) {
# Line 879 | Line 874 | public class JSR166TestCase extends Test
874  
875      /**
876       * Just like assertSame(x, y), but additionally recording (using
877 <     * threadRecordFailure) any AssertionFailedError thrown, so that
878 <     * the current testcase will fail.
877 >     * threadRecordFailure) any AssertionError thrown, so that the
878 >     * current testcase will fail.
879       */
880      public void threadAssertSame(Object x, Object y) {
881          try {
882              assertSame(x, y);
883 <        } catch (AssertionFailedError fail) {
883 >        } catch (AssertionError fail) {
884              threadRecordFailure(fail);
885              throw fail;
886          }
# Line 907 | Line 902 | public class JSR166TestCase extends Test
902  
903      /**
904       * Records the given exception using {@link #threadRecordFailure},
905 <     * then rethrows the exception, wrapping it in an
906 <     * AssertionFailedError if necessary.
905 >     * then rethrows the exception, wrapping it in an AssertionError
906 >     * if necessary.
907       */
908      public void threadUnexpectedException(Throwable t) {
909          threadRecordFailure(t);
# Line 917 | Line 912 | public class JSR166TestCase extends Test
912              throw (RuntimeException) t;
913          else if (t instanceof Error)
914              throw (Error) t;
915 <        else {
916 <            AssertionFailedError afe =
922 <                new AssertionFailedError("unexpected exception: " + t);
923 <            afe.initCause(t);
924 <            throw afe;
925 <        }
915 >        else
916 >            throw new AssertionError("unexpected exception: " + t, t);
917      }
918  
919      /**
# Line 1284 | Line 1275 | public class JSR166TestCase extends Test
1275  
1276      /**
1277       * Sleeps until the given time has elapsed.
1278 <     * Throws AssertionFailedError if interrupted.
1278 >     * Throws AssertionError if interrupted.
1279       */
1280      static void sleep(long millis) {
1281          try {
1282              delay(millis);
1283          } catch (InterruptedException fail) {
1284 <            AssertionFailedError afe =
1294 <                new AssertionFailedError("Unexpected InterruptedException");
1295 <            afe.initCause(fail);
1296 <            throw afe;
1284 >            throw new AssertionError("Unexpected InterruptedException", fail);
1285          }
1286      }
1287  
# Line 1384 | Line 1372 | public class JSR166TestCase extends Test
1372   //             r.run();
1373   //         } catch (Throwable fail) { threadUnexpectedException(fail); }
1374   //         if (millisElapsedSince(startTime) > timeoutMillis/2)
1375 < //             throw new AssertionFailedError("did not return promptly");
1375 > //             throw new AssertionError("did not return promptly");
1376   //     }
1377  
1378   //     void assertTerminatesPromptly(Runnable r) {
# Line 1401 | Line 1389 | public class JSR166TestCase extends Test
1389              assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS));
1390          } catch (Throwable fail) { threadUnexpectedException(fail); }
1391          if (millisElapsedSince(startTime) > timeoutMillis/2)
1392 <            throw new AssertionFailedError("timed get did not return promptly");
1392 >            throw new AssertionError("timed get did not return promptly");
1393      }
1394  
1395      <T> void checkTimedGet(Future<T> f, T expectedValue) {
# Line 1643 | Line 1631 | public class JSR166TestCase extends Test
1631   //         long startTime = System.nanoTime();
1632   //         while (!flag.get()) {
1633   //             if (millisElapsedSince(startTime) > timeoutMillis)
1634 < //                 throw new AssertionFailedError("timed out");
1634 > //                 throw new AssertionError("timed out");
1635   //             Thread.yield();
1636   //         }
1637   //     }
# Line 1730 | Line 1718 | public class JSR166TestCase extends Test
1718  
1719      /**
1720       * A CyclicBarrier that uses timed await and fails with
1721 <     * AssertionFailedErrors instead of throwing checked exceptions.
1721 >     * AssertionErrors instead of throwing checked exceptions.
1722       */
1723      public static class CheckedBarrier extends CyclicBarrier {
1724          public CheckedBarrier(int parties) { super(parties); }
# Line 1739 | Line 1727 | public class JSR166TestCase extends Test
1727              try {
1728                  return super.await(2 * LONG_DELAY_MS, MILLISECONDS);
1729              } catch (TimeoutException timedOut) {
1730 <                throw new AssertionFailedError("timed out");
1730 >                throw new AssertionError("timed out");
1731              } catch (Exception fail) {
1732 <                AssertionFailedError afe =
1745 <                    new AssertionFailedError("Unexpected exception: " + fail);
1746 <                afe.initCause(fail);
1747 <                throw afe;
1732 >                throw new AssertionError("Unexpected exception: " + fail, fail);
1733              }
1734          }
1735      }
# Line 1867 | Line 1852 | public class JSR166TestCase extends Test
1852              try { throwingAction.run(); }
1853              catch (Throwable t) {
1854                  threw = true;
1855 <                if (!expectedExceptionClass.isInstance(t)) {
1856 <                    AssertionFailedError afe =
1857 <                        new AssertionFailedError
1858 <                        ("Expected " + expectedExceptionClass.getName() +
1859 <                         ", got " + t.getClass().getName());
1875 <                    afe.initCause(t);
1876 <                    threadUnexpectedException(afe);
1877 <                }
1855 >                if (!expectedExceptionClass.isInstance(t))
1856 >                    throw new AssertionError(
1857 >                            "Expected " + expectedExceptionClass.getName() +
1858 >                            ", got " + t.getClass().getName(),
1859 >                            t);
1860              }
1861              if (!threw)
1862                  shouldThrow(expectedExceptionClass.getName());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines