< prev index next >

test/jdk/java/text/Collator/MonkeyTest.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -23,10 +23,11 @@
  
  /*
   * @test
   * @library /java/text/testlib
   * @summary test Collation, Monkey style
+  * @run junit MonkeyTest
   */
  /*
  (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  (C) Copyright IBM Corp. 1996 - All Rights Reserved
  

@@ -45,35 +46,36 @@
  import java.util.Locale;
  import java.text.Collator;
  import java.text.RuleBasedCollator;
  import java.text.CollationKey;
  
- public class MonkeyTest extends CollatorTest
- {
-     public static void main(String[] args) throws Exception {
-         new MonkeyTest().run(args);
-     }
+ import org.junit.jupiter.api.Test;
  
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class MonkeyTest
+ {
      public void report(String s, String t, int result, int revResult)
      {
          if (result == -1)
          {
              if (revResult != 1)
-                 errln(" --> Test Failed");
+                 fail(" --> Test Failed");
          }
          else if (result == 1)
          {
              if (revResult != -1)
-                 errln(" --> Test Failed");
+                 fail(" --> Test Failed");
          }
          else if (result == 0)
          {
              if (revResult != 0)
-                 errln(" --> Test Failed");
+                 fail(" --> Test Failed");
          }
      }
  
+     @Test
      public void TestCollationKey()
      {
          String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
          Random r = new Random(3);
          int s = checkValue(r.nextInt() % source.length());

@@ -103,20 +105,21 @@
          String addOne = subs + "\uE000";
          CollationKey1 = myCollator.getCollationKey(subs);
          CollationKey2 = myCollator.getCollationKey(addOne);
          result = CollationKey1.compareTo(CollationKey2);
          if (result != -1)
-             errln("CollationKey(" + subs + ")" + ".LT." + "CollationKey(" + addOne + ") Failed.");
+             fail("CollationKey(" + subs + ")" + ".LT." + "CollationKey(" + addOne + ") Failed.");
          result = CollationKey2.compareTo(CollationKey1);
          if (result != 1)
-             errln("CollationKey(" + addOne + ")" + ".GT." + "CollationKey(" + subs + ") Failed.");
+             fail("CollationKey(" + addOne + ")" + ".GT." + "CollationKey(" + subs + ") Failed.");
      }
      private static int checkValue(int value)
      {
          value *= (value > 0) ? 1 : -1;
          return value;
      }
+     @Test
      public void TestCompare()
      {
          String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
          Random r = new Random(3);
          int s = checkValue(r.nextInt() % source.length());

@@ -138,12 +141,12 @@
          revResult = myCollator.compare(subt, subs);  // Primary
          report(subs, subt, result, revResult);
          String addOne = subs + "\uE000";
          result = myCollator.compare(subs, addOne);
          if (result != -1)
-             errln("Test : " + subs + " .LT. " + addOne + " Failed.");
+             fail("Test : " + subs + " .LT. " + addOne + " Failed.");
          result = myCollator.compare(addOne, subs);
          if (result != 1)
-             errln("Test : " + addOne + " .GE. " + subs + " Failed.");
+             fail("Test : " + addOne + " .GE. " + subs + " Failed.");
      }
      private static Collator myCollator = Collator.getInstance();
  }
< prev index next >