11/*
2- * Copyright (c) 1997, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1997, 2023 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2323
2424/*
2525 * @test
26- * @library /java/text/testlib
2726 * @summary test for Character Iterator
27+ * @run junit CharacterIteratorTest
2828 */
2929
3030/*
6565
6666import java .text .*;
6767
68- public class CharacterIteratorTest extends IntlTest {
69- public static void main (String [] args ) throws Exception {
70- new CharacterIteratorTest ().run (args );
71- }
68+ import org .junit .jupiter .api .Test ;
69+
70+ import static org .junit .jupiter .api .Assertions .fail ;
7271
72+ public class CharacterIteratorTest {
7373 public CharacterIteratorTest () {
7474 }
7575
76+ @ Test
7677 public void TestConstructionAndEquality () {
7778 String testText = "Now is the time for all good men to come to the aid of their country." ;
7879 String testText2 = "Don't bother using this string." ;
@@ -84,49 +85,50 @@ public void TestConstructionAndEquality() {
8485 CharacterIterator test5 = (CharacterIterator )test1 .clone ();
8586
8687 if (test1 .equals (test2 ) || test1 .equals (test3 ) || test1 .equals (test4 ))
87- errln ("Construation or equals() failed: Two unequal iterators tested equal" );
88+ fail ("Construation or equals() failed: Two unequal iterators tested equal" );
8889
8990 if (!test1 .equals (test5 ))
90- errln ("clone() or equals() failed: Two clones tested unequal" );
91+ fail ("clone() or equals() failed: Two clones tested unequal" );
9192
9293 if (test1 .hashCode () == test2 .hashCode () || test1 .hashCode () == test3 .hashCode ()
9394 || test1 .hashCode () == test4 .hashCode ())
94- errln ("hash() failed: different objects have same hash code" );
95+ fail ("hash() failed: different objects have same hash code" );
9596
9697 if (test1 .hashCode () != test5 .hashCode ())
97- errln ("hash() failed: identical objects have different hash codes" );
98+ fail ("hash() failed: identical objects have different hash codes" );
9899
99100 test1 .setIndex (5 );
100101 if (!test1 .equals (test2 ) || test1 .equals (test5 ))
101- errln ("setIndex() failed" );
102+ fail ("setIndex() failed" );
102103 }
103104
105+ @ Test
104106 public void TestIteration () {
105107 String text = "Now is the time for all good men to come to the aid of their country." ;
106108
107109 CharacterIterator iter = new StringCharacterIterator (text , 5 );
108110
109111 if (iter .current () != text .charAt (5 ))
110- errln ("Iterator didn't start out in the right place." );
112+ fail ("Iterator didn't start out in the right place." );
111113
112114 char c = iter .first ();
113115 int i = 0 ;
114116
115117 if (iter .getBeginIndex () != 0 || iter .getEndIndex () != text .length ())
116- errln ("getBeginIndex() or getEndIndex() failed" );
118+ fail ("getBeginIndex() or getEndIndex() failed" );
117119
118- logln ("Testing forward iteration..." );
120+ System . out . println ("Testing forward iteration..." );
119121 do {
120122 if (c == CharacterIterator .DONE && i != text .length ())
121- errln ("Iterator reached end prematurely" );
123+ fail ("Iterator reached end prematurely" );
122124 else if (c != text .charAt (i ))
123- errln ("Character mismatch at position " + i + ", iterator has " + c +
125+ fail ("Character mismatch at position " + i + ", iterator has " + c +
124126 ", string has " + text .charAt (c ));
125127
126128 if (iter .current () != c )
127- errln ("current() isn't working right" );
129+ fail ("current() isn't working right" );
128130 if (iter .getIndex () != i )
129- errln ("getIndex() isn't working right" );
131+ fail ("getIndex() isn't working right" );
130132
131133 if (c != CharacterIterator .DONE ) {
132134 c = iter .next ();
@@ -137,18 +139,18 @@ else if (c != text.charAt(i))
137139 c = iter .last ();
138140 i = text .length () - 1 ;
139141
140- logln ("Testing backward iteration..." );
142+ System . out . println ("Testing backward iteration..." );
141143 do {
142144 if (c == CharacterIterator .DONE && i >= 0 )
143- errln ("Iterator reached end prematurely" );
145+ fail ("Iterator reached end prematurely" );
144146 else if (c != text .charAt (i ))
145- errln ("Character mismatch at position " + i + ", iterator has " + c +
147+ fail ("Character mismatch at position " + i + ", iterator has " + c +
146148 ", string has " + text .charAt (c ));
147149
148150 if (iter .current () != c )
149- errln ("current() isn't working right" );
151+ fail ("current() isn't working right" );
150152 if (iter .getIndex () != i )
151- errln ("getIndex() isn't working right" );
153+ fail ("getIndex() isn't working right" );
152154
153155 if (c != CharacterIterator .DONE ) {
154156 c = iter .previous ();
@@ -158,26 +160,26 @@ else if (c != text.charAt(i))
158160
159161 iter = new StringCharacterIterator (text , 5 , 15 , 10 );
160162 if (iter .getBeginIndex () != 5 || iter .getEndIndex () != 15 )
161- errln ("creation of a restricted-range iterator failed" );
163+ fail ("creation of a restricted-range iterator failed" );
162164
163165 if (iter .getIndex () != 10 || iter .current () != text .charAt (10 ))
164- errln ("starting the iterator in the middle didn't work" );
166+ fail ("starting the iterator in the middle didn't work" );
165167
166168 c = iter .first ();
167169 i = 5 ;
168170
169- logln ("Testing forward iteration over a range..." );
171+ System . out . println ("Testing forward iteration over a range..." );
170172 do {
171173 if (c == CharacterIterator .DONE && i != 15 )
172- errln ("Iterator reached end prematurely" );
174+ fail ("Iterator reached end prematurely" );
173175 else if (c != text .charAt (i ))
174- errln ("Character mismatch at position " + i + ", iterator has " + c +
176+ fail ("Character mismatch at position " + i + ", iterator has " + c +
175177 ", string has " + text .charAt (c ));
176178
177179 if (iter .current () != c )
178- errln ("current() isn't working right" );
180+ fail ("current() isn't working right" );
179181 if (iter .getIndex () != i )
180- errln ("getIndex() isn't working right" );
182+ fail ("getIndex() isn't working right" );
181183
182184 if (c != CharacterIterator .DONE ) {
183185 c = iter .next ();
@@ -188,18 +190,18 @@ else if (c != text.charAt(i))
188190 c = iter .last ();
189191 i = 14 ;
190192
191- logln ("Testing backward iteration over a range..." );
193+ System . out . println ("Testing backward iteration over a range..." );
192194 do {
193195 if (c == CharacterIterator .DONE && i >= 5 )
194- errln ("Iterator reached end prematurely" );
196+ fail ("Iterator reached end prematurely" );
195197 else if (c != text .charAt (i ))
196- errln ("Character mismatch at position " + i + ", iterator has " + c +
198+ fail ("Character mismatch at position " + i + ", iterator has " + c +
197199 ", string has " + text .charAt (c ));
198200
199201 if (iter .current () != c )
200- errln ("current() isn't working right" );
202+ fail ("current() isn't working right" );
201203 if (iter .getIndex () != i )
202- errln ("getIndex() isn't working right" );
204+ fail ("getIndex() isn't working right" );
203205
204206 if (c != CharacterIterator .DONE ) {
205207 c = iter .previous ();
@@ -211,6 +213,7 @@ else if (c != text.charAt(i))
211213 /**
212214 * @bug 4082050 4078261 4078255
213215 */
216+ @ Test
214217 public void TestPathologicalCases () {
215218 String text = "This is only a test." ;
216219
@@ -227,7 +230,7 @@ public void TestPathologicalCases() {
227230 || iter.previous() != CharacterIterator.DONE
228231 || iter.current() != CharacterIterator.DONE
229232 || iter.getIndex() != 5)
230- errln ("Got something other than DONE when performing operations on an empty StringCharacterIterator");
233+ fail ("Got something other than DONE when performing operations on an empty StringCharacterIterator");
231234*/
232235CharacterIterator iter = null ;
233236
@@ -242,7 +245,7 @@ public void TestPathologicalCases() {
242245 gotException = true ;
243246 }
244247 if (!gotException )
245- errln ("StringCharacterIterator didn't throw an exception when given an invalid substring range." );
248+ fail ("StringCharacterIterator didn't throw an exception when given an invalid substring range." );
246249
247250 // test for bug #4078255 (getting wrong value from next() when we're at the end
248251 // of the string)
@@ -253,24 +256,25 @@ public void TestPathologicalCases() {
253256 iter .last ();
254257 actualIndex = iter .getIndex ();
255258 if (actualIndex != expectedIndex - 1 )
256- errln ("last() failed: expected " + (expectedIndex - 1 ) + ", got " + actualIndex );
259+ fail ("last() failed: expected " + (expectedIndex - 1 ) + ", got " + actualIndex );
257260
258261 iter .next ();
259262 actualIndex = iter .getIndex ();
260263 if (actualIndex != expectedIndex )
261- errln ("next() after last() failed: expected " + expectedIndex + ", got " + actualIndex );
264+ fail ("next() after last() failed: expected " + expectedIndex + ", got " + actualIndex );
262265
263266 iter .next ();
264267 actualIndex = iter .getIndex ();
265268 if (actualIndex != expectedIndex )
266- errln ("second next() after last() failed: expected " + expectedIndex + ", got " + actualIndex );
269+ fail ("second next() after last() failed: expected " + expectedIndex + ", got " + actualIndex );
267270 }
268271
269272 /*
270273 * @bug 4123771 4051073
271274 * #4123771 is actually a duplicate of bug #4051073, which was fixed some time ago, but
272275 * no one ever added a regression test for it.
273276 */
277+ @ Test
274278 public void TestBug4123771 () {
275279 String text = "Some string for testing" ;
276280 StringCharacterIterator iter = new StringCharacterIterator (text );
@@ -283,7 +287,7 @@ public void TestBug4123771() {
283287 System .out .println (" position: " + index );
284288 System .out .println (" getEndIndex(): " + iter .getEndIndex ());
285289 System .out .println (" text.length(): " + text .length ());
286- errln ("" ); // re-throw the exception through our test framework
290+ fail ("" ); // re-throw the exception through our test framework
287291 }
288292 }
289293}
0 commit comments