< prev index next >

test/jdk/java/text/Collator/IteratorTest.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 1998, 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.

@@ -24,10 +24,11 @@
  /*
   * @test
   * @bug 4062985 4108758 4108762 4157299
   * @library /java/text/testlib
   * @summary Test CollationElementIterator, particularly the new methods in 1.2
+  * @run junit IteratorTest
   */
  /*
   * (C) Copyright IBM Corp. 1998 - All Rights Reserved
   *
   * The original version of this source code and documentation is copyrighted

@@ -38,26 +39,27 @@
   */
  
  import java.util.Locale;
  import java.text.*;
  
- public class IteratorTest extends CollatorTest {
+ import org.junit.jupiter.api.Test;
+ 
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class IteratorTest {
      // TODO:
      //  - Test previous() with contracting character sequences, which don't work
      //      at the moment.
      //  - Test edge cases on setOffset(), e.g. offset > length, etc.
      //
-     public static void main(String[] args) throws Exception {
-         new IteratorTest().run(args);
-     }
- 
      /**
       * Test for CollationElementIterator.previous()
       *
       * @bug 4108758 - Make sure it works with contracting characters
       *
       */
+     @Test
      public void TestPrevious() throws ParseException {
          // A basic test to see if it's working at all
          backAndForth(en_us.getCollationElementIterator(test1));
  
          // Test with a contracting character sequence

@@ -80,10 +82,11 @@
      }
  
      /**
       * Test for getOffset() and setOffset()
       */
+     @Test
      public void TestOffset() {
          CollationElementIterator iter = en_us.getCollationElementIterator(test1);
  
          // Run all the way through the iterator, then get the offset
          int orders[] = getOrders(iter);

@@ -94,18 +97,19 @@
                                  + offset + " vs " + test1.length());
          }
  
          // Now set the offset back to the beginning and see if it works
          iter.setOffset(0);
-         assertEqual(iter, en_us.getCollationElementIterator(test1));
+         TestUtils.compareCollationElementIters(iter, en_us.getCollationElementIterator(test1));
  
          // TODO: try iterating halfway through a messy string.
      }
  
      /**
       * Test for setText()
       */
+     @Test
      public void TestSetText() {
          CollationElementIterator iter1 = en_us.getCollationElementIterator(test1);
          CollationElementIterator iter2 = en_us.getCollationElementIterator(test2);
  
          // Run through the second iterator just to exercise it

@@ -115,16 +119,17 @@
              c = iter2.next();
          }
  
          // Now set it to point to the same string as the first iterator
          iter2.setText(test1);
-         assertEqual(iter1, iter2);
+         TestUtils.compareCollationElementIters(iter1, iter2);
      }
  
      /** @bug 4108762
       * Test for getMaxExpansion()
       */
+     @Test
      public void TestMaxExpansion() throws ParseException {
          // Try a simple one first:
          // The only expansion ends with 'e' and has length 2
          String[][] test1 = {
              { "< a & ae = \u00e4 < b < e", "" },

@@ -149,20 +154,21 @@
      }
  
      /*
       * @bug 4157299
       */
+     @Test
      public void TestClearBuffers() throws ParseException {
          RuleBasedCollator c = new RuleBasedCollator("< a < b < c & ab = d");
          CollationElementIterator i = c.getCollationElementIterator("abcd");
          int e0 = i.next();   // save the first collation element
          i.setOffset(3);      // go to the expanding character
          i.next();            // but only use up half of it
          i.setOffset(0);      // go back to the beginning
          int e = i.next();    // and get this one again
          if (e != e0) {
-            errln("got " + Integer.toString(e, 16) + ", expected " +
+            fail("got " + Integer.toString(e, 16) + ", expected " +
                         Integer.toString(e0, 16));
          }
      }
  
      //------------------------------------------------------------------------

@@ -177,30 +183,30 @@
          int index = orders.length;
          int o;
  
          while ((o = iter.previous()) != CollationElementIterator.NULLORDER) {
              if (o != orders[--index]) {
-                 errln("Mismatch at index " + index + ": "
+                 fail("Mismatch at index " + index + ": "
                          + orders[index] + " vs " + o);
                  break;
              }
          }
          if (index != 0) {
-             errln("Didn't get back to beginning - index is " + index);
+             fail("Didn't get back to beginning - index is " + index);
  
              iter.reset();
-             err("next: ");
+             fail("next: ");
              while ((o = iter.next()) != NULLORDER) {
-                 err( Integer.toHexString(o) + " ");
+                 fail( Integer.toHexString(o) + " ");
              }
-             errln("");
+             fail("");
  
-             err("prev: ");
+             fail("prev: ");
              while ((o = iter.previous()) != NULLORDER) {
-                  err( Integer.toHexString(o) + " ");
+                  fail( Integer.toHexString(o) + " ");
              }
-             errln("");
+             fail("");
          }
      }
  
      /**
       * Verify that getMaxExpansion works on a given set of collation rules

@@ -224,19 +230,19 @@
  
              int order = iter.next();
  
              if (order == NULLORDER || iter.next() != NULLORDER) {
                  iter.reset();
-                 errln("verifyExpansion: '" + tests[i][0] +
+                 fail("verifyExpansion: '" + tests[i][0] +
                      "' has multiple orders:" + orderString(iter));
              }
  
              int expansion = iter.getMaxExpansion(order);
              int expect = new Integer(tests[i][1]).intValue();
  
              if (expansion != expect) {
-                 errln("expansion for '" + tests[i][0] + "' is wrong: " +
+                 fail("expansion for '" + tests[i][0] + "' is wrong: " +
                      "expected " + expect + ", got " + expansion);
              }
          }
      }
  
< prev index next >