< prev index next >

test/jdk/java/text/BreakIterator/Bug4533872.java

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

@@ -19,25 +19,25 @@
   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
- /**
+ /*
   * @test
   * @bug 4533872 4640853
-  * @library /java/text/testlib
   * @summary Unit tests for supplementary character support (JSR-204) and Unicode 4.0 support
+  * @run junit Bug4533872
   */
  
  import java.text.BreakIterator;
  import java.util.Locale;
  
- public class Bug4533872 extends IntlTest {
+ import org.junit.jupiter.api.Test;
  
-     public static void main(String[] args) throws Exception {
-         new Bug4533872().run(args);
-     }
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class Bug4533872 {
  
      static final String[] given = {
        /* Lu Nd    Lu     Ll    */
          "XYZ12345 ABCDE  abcde",
        /* Nd Lo          Nd  Lu Po    Lu   Ll    */

@@ -60,10 +60,11 @@
      int start, end, current;
  
      /*
       * Test for next(int n)
       */
+     @Test
      void TestNext() {
          iter = BreakIterator.getWordInstance(Locale.US);
  
          for (int i = 0; i < given.length; i++) {
              iter.setText(given[i]);

@@ -71,21 +72,22 @@
              int j = expected[i].length - 1;
              start = iter.next(j);
              end = iter.next();
  
              if (!expected[i][j].equals(given[i].substring(start, end))) {
-                 errln("Word break failure: printEachForward() expected:<" +
+                 fail("Word break failure: printEachForward() expected:<" +
                        expected[i][j] + ">, got:<" +
                        given[i].substring(start, end) +
                        "> start=" + start + "  end=" + end);
              }
          }
      }
  
      /*
       * Test for isBoundary(int n)
       */
+     @Test
      void TestIsBoundary() {
          iter = BreakIterator.getWordInstance(Locale.US);
  
          for (int i = 0; i < given.length; i++) {
              iter.setText(given[i]);

@@ -93,11 +95,11 @@
              start = iter.first();
              end = iter.next();
  
              while (end < given[i].length()) {
                  if (!iter.isBoundary(end)) {
-                     errln("Word break failure: isBoundary() This should be a boundary. Index=" +
+                     fail("Word break failure: isBoundary() This should be a boundary. Index=" +
                            end + " for " + given[i]);
                  }
                  end = iter.next();
              }
          }

@@ -110,21 +112,22 @@
       */
  
      /*
       * Test mainly for next() and current()
       */
+     @Test
      void TestPrintEachForward() {
          iter = BreakIterator.getWordInstance(Locale.US);
  
          for (int i = 0; i < given.length; i++) {
              iter.setText(given[i]);
              start = iter.first();
  
              // Check current()'s return value - should be same as first()'s.
              current = iter.current();
              if (start != current) {
-                 errln("Word break failure: printEachForward() Unexpected current value: current()=" +
+                 fail("Word break failure: printEachForward() Unexpected current value: current()=" +
                        current + ", expected(=first())=" + start);
              }
  
              int j = 0;
              for (end = iter.next();

@@ -132,16 +135,16 @@
                   start = end, end = iter.next(), j++) {
  
                  // Check current()'s return value - should be same as next()'s.
                  current = iter.current();
                  if (end != current) {
-                     errln("Word break failure: printEachForward() Unexpected current value: current()=" +
+                     fail("Word break failure: printEachForward() Unexpected current value: current()=" +
                            current + ", expected(=next())=" + end);
                  }
  
                  if (!expected[i][j].equals(given[i].substring(start, end))) {
-                     errln("Word break failure: printEachForward() expected:<" +
+                     fail("Word break failure: printEachForward() expected:<" +
                            expected[i][j] + ">, got:<" +
                            given[i].substring(start, end) +
                            "> start=" + start + "  end=" + end);
                  }
              }

@@ -149,21 +152,22 @@
      }
  
      /*
       * Test mainly for previous() and current()
       */
+     @Test
      void TestPrintEachBackward() {
          iter = BreakIterator.getWordInstance(Locale.US);
  
          for (int i = 0; i < given.length; i++) {
              iter.setText(given[i]);
              end = iter.last();
  
              // Check current()'s return value - should be same as last()'s.
              current = iter.current();
              if (end != current) {
-                 errln("Word break failure: printEachBackward() Unexpected current value: current()=" +
+                 fail("Word break failure: printEachBackward() Unexpected current value: current()=" +
                        current + ", expected(=last())=" + end);
              }
  
              int j;
              for (start = iter.previous(), j = expected[i].length-1;

@@ -171,16 +175,16 @@
                   end = start, start = iter.previous(), j--) {
  
                  // Check current()'s return value - should be same as previous()'s.
                  current = iter.current();
                  if (start != current) {
-                     errln("Word break failure: printEachBackward() Unexpected current value: current()=" +
+                     fail("Word break failure: printEachBackward() Unexpected current value: current()=" +
                            current + ", expected(=previous())=" + start);
                  }
  
                  if (!expected[i][j].equals(given[i].substring(start, end))) {
-                     errln("Word break failure: printEachBackward() expected:<" +
+                     fail("Word break failure: printEachBackward() expected:<" +
                            expected[i][j] + ">, got:<" +
                            given[i].substring(start, end) +
                            "> start=" + start + "  end=" + end);
                  }
              }

@@ -188,10 +192,11 @@
      }
  
      /*
       * Test mainly for following() and previous()
       */
+     @Test
      void TestPrintAt_1() {
          iter = BreakIterator.getWordInstance(Locale.US);
  
          int[][] index = {
              {2, 8, 10, 15, 17},

@@ -205,11 +210,11 @@
              for (int j = index[i].length-1; j >= 0; j--) {
                  end = iter.following(index[i][j]);
                  start = iter.previous();
  
                  if (!expected[i][j].equals(given[i].substring(start, end))) {
-                     errln("Word break failure: printAt_1() expected:<" +
+                     fail("Word break failure: printAt_1() expected:<" +
                            expected[i][j] + ">, got:<" +
                            given[i].substring(start, end) +
                            "> start=" + start + "  end=" + end);
                  }
              }

@@ -217,10 +222,11 @@
      }
  
      /*
       * Test mainly for preceding() and next()
       */
+     @Test
      void TestPrintAt_2() {
          iter = BreakIterator.getWordInstance(Locale.US);
  
          int[][] index = {
              {2, 9, 10, 15, 17},

@@ -232,30 +238,30 @@
          for (int i = 0; i < given.length; i++) {
              iter.setText(given[i]);
  
              // Check preceding(0)'s return value - should equals BreakIterator.DONE.
              if (iter.preceding(0) != BreakIterator.DONE) {
-                  errln("Word break failure: printAt_2() expected:-1(BreakIterator.DONE), got:" +
+                  fail("Word break failure: printAt_2() expected:-1(BreakIterator.DONE), got:" +
                         iter.preceding(0));
              }
  
              for (int j = 0; j < index[i].length; j++) {
                  start = iter.preceding(index[i][j]);
                  end = iter.next();
  
                  if (!expected[i][j].equals(given[i].substring(start, end))) {
-                     errln("Word break failure: printAt_2() expected:<" +
+                     fail("Word break failure: printAt_2() expected:<" +
                            expected[i][j] + ">, got:<" +
                            given[i].substring(start, end) +
                            "> start=" + start + "  end=" + end);
                  }
              }
  
              // Check next()'s return value - should equals BreakIterator.DONE.
              end = iter.last();
              start = iter.next();
              if (start != BreakIterator.DONE) {
-                  errln("Word break failure: printAt_2() expected:-1(BreakIterator.DONE), got:" + start);
+                  fail("Word break failure: printAt_2() expected:-1(BreakIterator.DONE), got:" + start);
              }
          }
      }
  }
< prev index next >