< prev index next >

test/lib/testlibrary/jdk/testlibrary/Asserts.java

Print this page
rev 13428 : jfr backport


 391      *
 392      * @see #assertTrue(boolean, String)
 393      */
 394     public static void assertTrue(boolean value) {
 395         assertTrue(value, "Expected value to be true");
 396     }
 397 
 398     /**
 399      * Asserts that {@code value} is {@code true}.
 400      *
 401      * @param value The value assumed to be true.
 402      * @param msg A description of the assumption.
 403      * @throws RuntimeException if the assertion isn't valid.
 404      */
 405     public static void assertTrue(boolean value, String msg) {
 406         if (!value) {
 407             error(msg);
 408         }
 409     }
 410 
















 411     private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) {
 412         assertNotNull(lhs, msg);
 413         assertNotNull(rhs, msg);
 414         return lhs.compareTo(rhs);
 415     }
 416 
 417     private static String format(Object o) {
 418         return o == null? "null" : o.toString();
 419     }
 420 
 421     private static void error(String msg) {
 422         throw new RuntimeException(msg);
 423     }
 424 
 425 }


 391      *
 392      * @see #assertTrue(boolean, String)
 393      */
 394     public static void assertTrue(boolean value) {
 395         assertTrue(value, "Expected value to be true");
 396     }
 397 
 398     /**
 399      * Asserts that {@code value} is {@code true}.
 400      *
 401      * @param value The value assumed to be true.
 402      * @param msg A description of the assumption.
 403      * @throws RuntimeException if the assertion isn't valid.
 404      */
 405     public static void assertTrue(boolean value, String msg) {
 406         if (!value) {
 407             error(msg);
 408         }
 409     }
 410 
 411     /**
 412      * Fails a test with the default message.
 413      */
 414     public static void fail() {
 415         error("Test failed");
 416     }
 417 
 418     /**
 419      * Fails a test with the given message.
 420      *
 421      * @param msg A description of the failure.
 422      */
 423     public static void fail(String msg) {
 424         error(msg);
 425     }
 426 
 427     private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) {
 428         assertNotNull(lhs, msg);
 429         assertNotNull(rhs, msg);
 430         return lhs.compareTo(rhs);
 431     }
 432 
 433     private static String format(Object o) {
 434         return o == null? "null" : o.toString();
 435     }
 436 
 437     private static void error(String msg) {
 438         throw new RuntimeException(msg);
 439     }
 440 
 441 }
< prev index next >