< prev index next >

test/jdk/java/text/Normalizer/NormalizerAPITest.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2018, 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,26 +24,29 @@
  /*
   * @test
   * @bug 4221795 8174270
   * @summary Confirm Normalizer's fundamental behavior
   * @modules java.base/sun.text java.base/jdk.internal.icu.text
-  * @library /java/text/testlib
   * @compile -XDignore.symbol.file NormalizerAPITest.java
-  * @run main/timeout=30 NormalizerAPITest
+  * @run junit/timeout=30 NormalizerAPITest
   */
  
  import java.text.Normalizer;
  import java.nio.CharBuffer;
  
+ import org.junit.jupiter.api.Test;
+ 
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
  
  /*
   * Tests around null/"" arguments for public methods.
   *
   * You may think that so elaborate testing for such a part is not necessary.
   * But I actually detected a bug by this program during my porting work.
   */
- public class NormalizerAPITest extends IntlTest {
+ public class NormalizerAPITest {
  
      //
      // Shortcuts
      //
  

@@ -69,17 +72,14 @@
      };
  
      static final String nonNullStr = "testdata";
  
  
-     public static void main(String[] args) throws Exception {
-         new NormalizerAPITest().run(args);
-     }
- 
      /*
       * Check if normalize(null) throws NullPointerException as expected.
       */
+     @Test
      public void Test_NullPointerException_java_normalize() {
          boolean error = false;
  
          /* Check null as String to be normalized */
          for (int i = 0; i < forms.length; i++) {

@@ -98,17 +98,18 @@
          }
          catch (NullPointerException e) {
          }
  
          if (error) {
-              errln("normalize(null) should throw NullPointerException.");
+              fail("normalize(null) should throw NullPointerException.");
          }
      }
  
      /*
       * Check if normalize(null) throws NullPointerException as expected.
       */
+     @Test
      public void Test_NullPointerException_sun_normalize() {
          boolean error = false;
  
          for (int j = 0; j < options.length; j++) {
              for (int i = 0; i < forms.length; i++) {

@@ -129,17 +130,18 @@
              catch (NullPointerException e) {
              }
          }
  
          if (error) {
-              errln("normalize(null) should throw NullPointerException.");
+              fail("normalize(null) should throw NullPointerException.");
          }
      }
  
      /*
       * Check if isNormalized(null) throws NullPointerException as expected.
       */
+     @Test
      public void Test_NullPointerException_java_isNormalized() {
          boolean error = false;
  
          for (int i = 0; i < forms.length; i++) {
              try {

@@ -158,17 +160,18 @@
          }
  
          catch (NullPointerException e) {
          }
          if (error) {
-              errln("isNormalized(null) should throw NullPointerException.");
+              fail("isNormalized(null) should throw NullPointerException.");
          }
      }
  
      /*
       * Check if isNormalized(null) throws NullPointerException as expected.
       */
+     @Test
      public void Test_NullPointerException_sun_isNormalized() {
          boolean error = false;
  
          for (int j = 0; j < options.length; j++) {
              for (int i = 0; i < forms.length; i++) {

@@ -189,18 +192,19 @@
              catch (NullPointerException e) {
              }
          }
  
          if (error) {
-              errln("isNormalized(null) should throw NullPointerException.");
+              fail("isNormalized(null) should throw NullPointerException.");
          }
      }
  
      /*
       * Check if isNormalized("") doesn't throw NullPointerException and returns
       * "" as expected.
       */
+     @Test
      public void Test_No_NullPointerException_java_normalize() {
          boolean error = false;
  
          for (int i = 0; i < forms.length; i++) {
              try {

@@ -213,18 +217,19 @@
                  error = true;
              }
          }
  
          if (error) {
-              errln("normalize() for String(\"\") should return \"\".");
+              fail("normalize() for String(\"\") should return \"\".");
          }
      }
  
      /*
       * Check if isNormalized("") doesn't throw NullPointerException and returns
       * "" as expected.
       */
+     @Test
      public void Test_No_NullPointerException_sun_normalize() {
          boolean error = false;
  
          for (int j = 0; j < options.length; j++) {
              for (int i = 0; i < forms.length; i++) {

@@ -238,18 +243,19 @@
                      error = true;
                  }
              }
          }
          if (error) {
-              errln("normalize() for String(\"\") should return \"\".");
+              fail("normalize() for String(\"\") should return \"\".");
          }
      }
  
      /*
       * Check if isNormalized("") doesn't throw NullPointerException and returns
       * "" as expected.
       */
+     @Test
      public void Test_No_NullPointerException_java_isNormalized() {
          boolean error = false;
  
          for (int i = 0; i < forms.length; i++) {
              try {

@@ -261,18 +267,19 @@
              catch (NullPointerException e) {
                  error = true;
              }
          }
          if (error) {
-              errln("isNormalized() for String(\"\") should not return true.");
+              fail("isNormalized() for String(\"\") should not return true.");
          }
      }
  
      /*
       * Check if isNormalized("") doesn't throw NullPointerException and returns
       * "" as expected.
       */
+     @Test
      public void Test_No_NullPointerException_sun_isNormalized() {
          boolean error = false;
  
          for (int j = 0; j < options.length; j++) {
              for (int i = 0; i < forms.length; i++) {

@@ -286,18 +293,19 @@
                      error = true;
                  }
              }
          }
          if (error) {
-              errln("isNormalized() for String(\"\") should not return true.");
+              fail("isNormalized() for String(\"\") should not return true.");
          }
      }
  
      /*
       * Check if normalize() and isNormalized() work as expected for every
       * known class which implement CharSequence Interface.
       */
+     @Test
      public void Test_CharSequence() {
  
          check_CharSequence(String.valueOf(inputData),
                             String.valueOf(outputData));
  

@@ -313,27 +321,27 @@
  
  
      void check_CharSequence(CharSequence in, CharSequence expected) {
          String out = Normalizer.normalize(in, NFD);
          if (!out.equals(expected.toString())) {
-             errln("java.text.Normalizer.normalize(" +
+             fail("java.text.Normalizer.normalize(" +
                    in.getClass().getSimpleName() + ") failed.");
          }
          out = sun.text.Normalizer.normalize(in, NFD,
                               jdk.internal.icu.text.NormalizerBase.UNICODE_LATEST);
          if (!out.equals(expected.toString())) {
-             errln("sun.text.Normalizer.normalize(" +
+             fail("sun.text.Normalizer.normalize(" +
                    in.getClass().getSimpleName() + ") failed.");
          }
  
          if (!Normalizer.isNormalized(expected, NFD)) {
-             errln("java.text.Normalizer.isNormalize(" +
+             fail("java.text.Normalizer.isNormalize(" +
                    in.getClass().getSimpleName() + ") failed.");
          }
          if (!sun.text.Normalizer.isNormalized(expected, NFD,
                             jdk.internal.icu.text.NormalizerBase.UNICODE_LATEST)) {
-             errln("sun.text.Normalizer.isNormalize(" +
+             fail("sun.text.Normalizer.isNormalize(" +
                    in.getClass().getSimpleName() + ") failed.");
          }
      }
  
      static final char[] inputData  = {'T', 's', 'c', 'h', 'u', '\u1e9b'};
< prev index next >