< prev index next >

test/testlibrary/com/oracle/java/testlibrary/Asserts.java

Print this page
rev 8910 : full patch for jfr
   1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 419 
 420         if (minLength < longestStringLines.length) {
 421             String stringName = ((longestStringLines == str1Lines) ?
 422                                  "first" : "second");
 423             messageBuilder.append(String.format("Only %s string contains " +
 424                                                 "following lines:\n",
 425                                                 stringName));
 426             stringsAreDifferent = true;
 427             for(int line = minLength; line < longestStringLines.length; line++) {
 428                 messageBuilder.append(String.
 429                                       format("[line %d] '%s'", line,
 430                                              longestStringLines[line]));
 431             }
 432         }
 433 
 434         if (stringsAreDifferent) {
 435             error(messageBuilder.toString());
 436         }
 437     }
 438 


















 439     private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) {
 440         assertNotNull(lhs, msg);
 441         assertNotNull(rhs, msg);
 442         return lhs.compareTo(rhs);
 443     }
 444 
 445     private static String format(Object o) {
 446         return o == null? "null" : o.toString();
 447     }
 448 
 449     private static void error(String msg) {
 450         throw new RuntimeException(msg);
 451     }
 452 
 453 }
   1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 419 
 420         if (minLength < longestStringLines.length) {
 421             String stringName = ((longestStringLines == str1Lines) ?
 422                                  "first" : "second");
 423             messageBuilder.append(String.format("Only %s string contains " +
 424                                                 "following lines:\n",
 425                                                 stringName));
 426             stringsAreDifferent = true;
 427             for(int line = minLength; line < longestStringLines.length; line++) {
 428                 messageBuilder.append(String.
 429                                       format("[line %d] '%s'", line,
 430                                              longestStringLines[line]));
 431             }
 432         }
 433 
 434         if (stringsAreDifferent) {
 435             error(messageBuilder.toString());
 436         }
 437     }
 438 
 439     /**
 440      * Fail the test directly
 441      * @throws RuntimeException anyway.
 442      */
 443     public static void fail() {
 444         error("Failed");
 445     }
 446 
 447     /**
 448      * Fails a test with the given message.
 449      *
 450      * @param msg A description of the failure.
 451      *
 452      */
 453     public static void fail(String msg) {
 454         error(msg);
 455     }
 456 
 457     private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) {
 458         assertNotNull(lhs, msg);
 459         assertNotNull(rhs, msg);
 460         return lhs.compareTo(rhs);
 461     }
 462 
 463     private static String format(Object o) {
 464         return o == null? "null" : o.toString();
 465     }
 466 
 467     private static void error(String msg) {
 468         throw new RuntimeException(msg);
 469     }
 470 
 471 }
< prev index next >