11/*
2- * Copyright (c) 1999, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1999, 2026 , 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
2424package javax .xml .datatype .ptests ;
2525
26- import static java .util .Calendar .HOUR ;
27- import static java .util .Calendar .MINUTE ;
28- import static java .util .Calendar .YEAR ;
29- import static org .testng .Assert .assertEquals ;
30- import static org .testng .Assert .assertTrue ;
31-
32- import java .util .GregorianCalendar ;
33- import java .util .Locale ;
34- import java .util .TimeZone ;
26+ import org .junit .jupiter .api .BeforeEach ;
27+ import org .junit .jupiter .api .Test ;
28+ import org .junit .jupiter .params .ParameterizedTest ;
29+ import org .junit .jupiter .params .provider .MethodSource ;
30+ import org .junit .jupiter .params .provider .ValueSource ;
3531
3632import javax .xml .datatype .DatatypeConfigurationException ;
3733import javax .xml .datatype .DatatypeConstants ;
3834import javax .xml .datatype .DatatypeFactory ;
3935import javax .xml .datatype .Duration ;
4036import javax .xml .datatype .XMLGregorianCalendar ;
37+ import java .util .GregorianCalendar ;
38+ import java .util .Locale ;
39+ import java .util .TimeZone ;
4140
42- import org .testng .Assert ;
43- import org .testng .annotations .BeforeClass ;
44- import org .testng .annotations .DataProvider ;
45- import org .testng .annotations .Test ;
41+ import static java .util .Calendar .HOUR ;
42+ import static java .util .Calendar .MINUTE ;
43+ import static java .util .Calendar .YEAR ;
44+ import static org .junit .jupiter .api .Assertions .assertEquals ;
45+ import static org .junit .jupiter .api .Assertions .assertFalse ;
46+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
47+ import static org .junit .jupiter .api .Assertions .assertThrows ;
48+ import static org .junit .jupiter .api .Assertions .assertTrue ;
4649
4750/*
4851 * @test
4952 * @bug 5049592 5041845 5048932 5064587 5040542 5049531 5049528
5053 * @library /javax/xml/jaxp/libs
51- * @run testng /othervm javax.xml.datatype.ptests.XMLGregorianCalendarTest
54+ * @run junit /othervm javax.xml.datatype.ptests.XMLGregorianCalendarTest
5255 * @summary Class containing the test cases for XMLGregorianCalendar
5356 */
5457public class XMLGregorianCalendarTest {
5558
5659 private DatatypeFactory datatypeFactory ;
5760
58- @ BeforeClass
61+ @ BeforeEach
5962 public void setup () throws DatatypeConfigurationException {
6063 datatypeFactory = DatatypeFactory .newInstance ();
6164 }
6265
63- @ DataProvider (name = "valid-milliseconds" )
64- public Object [][] getValidMilliSeconds () {
65- return new Object [][] { { 0 }, { 1 }, { 2 }, { 16 }, { 1000 } };
66- }
67-
6866 /*
6967 * Test DatatypeFactory.newXMLGregorianCalendar(..) with milliseconds > 1.
7068 *
7169 * Bug # 5049592
72- *
7370 */
74- @ Test (dataProvider = "valid-milliseconds" )
71+ @ ParameterizedTest
72+ @ ValueSource (ints ={ 0 , 1 , 2 , 16 , 1000 })
7573 public void checkNewCalendar (int ms ) {
7674 // valid milliseconds
7775 XMLGregorianCalendar calendar = datatypeFactory .newXMLGregorianCalendar (2004 , // year
@@ -93,7 +91,8 @@ public void checkNewCalendar(int ms) {
9391 *
9492 * Bug # 5049592
9593 */
96- @ Test (dataProvider = "valid-milliseconds" )
94+ @ ParameterizedTest
95+ @ ValueSource (ints ={ 0 , 1 , 2 , 16 , 1000 })
9796 public void checkNewTime (int ms ) {
9897 // valid milliseconds
9998 XMLGregorianCalendar calendar2 = datatypeFactory .newXMLGregorianCalendarTime (19 , // hour
@@ -107,30 +106,28 @@ public void checkNewTime(int ms) {
107106 assertEquals (calendar2 .getMillisecond (), ms );
108107 }
109108
110- @ DataProvider (name = "invalid-milliseconds" )
111- public Object [][] getInvalidMilliSeconds () {
112- return new Object [][] { { -1 }, { 1001 } };
113- }
114-
115109 /*
116110 * Test DatatypeFactory.newXMLGregorianCalendar(..).
117111 *
118112 * Bug # 5049592 IllegalArgumentException is thrown if milliseconds < 0 or >
119113 * 1001.
120114 *
121115 */
122- @ Test (expectedExceptions = IllegalArgumentException .class , dataProvider = "invalid-milliseconds" )
123- public void checkNewCalendarNeg (int milliseconds ) {
116+ @ ParameterizedTest
117+ @ ValueSource (ints ={ -1 , 1001 })
118+ public void checkNewCalendarNeg (int invalidMilliseconds ) {
124119 // invalid milliseconds
125- datatypeFactory .newXMLGregorianCalendar (2004 , // year
126- 6 , // month
127- 2 , // day
128- 19 , // hour
129- 20 , // minute
130- 59 , // second
131- milliseconds , // milliseconds
132- 840 // timezone
133- );
120+ assertThrows (
121+ IllegalArgumentException .class ,
122+ () -> datatypeFactory .newXMLGregorianCalendar (2004 , // year
123+ 6 , // month
124+ 2 , // day
125+ 19 , // hour
126+ 20 , // minute
127+ 59 , // second
128+ invalidMilliseconds , // milliseconds
129+ 840 // timezone
130+ ));
134131 }
135132
136133 /*
@@ -140,19 +137,21 @@ public void checkNewCalendarNeg(int milliseconds) {
140137 * 1001.
141138 *
142139 */
143- @ Test (expectedExceptions = IllegalArgumentException .class , dataProvider = "invalid-milliseconds" )
144- public void checkNewTimeNeg (int milliseconds ) {
140+ @ ParameterizedTest
141+ @ ValueSource (ints ={ -1 , 1001 })
142+ public void checkNewTimeNeg (int invalidMilliseconds ) {
145143 // invalid milliseconds
146- datatypeFactory .newXMLGregorianCalendarTime (19 , // hour
147- 20 , // minute
148- 59 , // second
149- milliseconds , // milliseconds
150- 840 // timezone
151- );
144+ assertThrows (
145+ IllegalArgumentException .class ,
146+ () -> datatypeFactory .newXMLGregorianCalendarTime (19 , // hour
147+ 20 , // minute
148+ 59 , // second
149+ invalidMilliseconds , // milliseconds
150+ 840 // timezone
151+ ));
152152 }
153153
154- @ DataProvider (name = "data-for-add" )
155- public Object [][] getDataForAdd () {
154+ public static Object [][] getDataForAdd () {
156155 return new Object [][] {
157156 //calendar1, calendar2, duration
158157 { "1999-12-31T00:00:00Z" , "2000-01-01T00:00:00Z" , "P1D" },
@@ -173,7 +172,8 @@ public Object[][] getDataForAdd() {
173172 * Test XMLGregorianCalendar.add(Duration).
174173 *
175174 */
176- @ Test (dataProvider = "data-for-add" )
175+ @ ParameterizedTest
176+ @ MethodSource ("getDataForAdd" )
177177 public void checkAddDays (String cal1 , String cal2 , String dur ) {
178178
179179 XMLGregorianCalendar calendar1 = datatypeFactory .newXMLGregorianCalendar (cal1 );
@@ -191,57 +191,38 @@ public void checkAddDays(String cal1, String cal2, String dur) {
191191
192192 }
193193
194- @ DataProvider (name = "gMonth" )
195- public Object [][] getGMonth () {
196- return new Object [][] {
197- { "2000-02" },
198- { "2000-03" },
199- { "2018-02" }};
200- }
201194 /*
202195 * Test XMLGregorianCalendar#isValid(). for gMonth
203196 *
204197 * Bug # 5041845
205- *
206198 */
207- @ Test (dataProvider = "gMonth" )
199+ @ ParameterizedTest
200+ @ ValueSource (strings ={ "2000-02" , "2000-03" , "2018-02" })
208201 public void checkIsValid (String month ) {
209-
210202 XMLGregorianCalendar gMonth = datatypeFactory .newXMLGregorianCalendar (month );
211203 gMonth .setYear (null );
212- Assert .assertTrue (gMonth .isValid (), gMonth .toString () + " should isValid" );
213-
214- }
215-
216- @ DataProvider (name = "lexical01" )
217- public Object [][] getLexicalRepresentForNormalize01 () {
218- return new Object [][] { { "2000-01-16T12:00:00Z" }, { "2000-01-16T12:00:00" } };
204+ assertTrue (gMonth .isValid (), gMonth + " should isValid" );
219205 }
220206
221207 /*
222208 * Test XMLGregorianCalendar#normalize(...).
223209 *
224210 * Bug # 5048932 XMLGregorianCalendar.normalize works
225- *
226211 */
227- @ Test (dataProvider = "lexical01" )
212+ @ ParameterizedTest
213+ @ ValueSource (strings ={ "2000-01-16T12:00:00Z" , "2000-01-16T12:00:00" })
228214 public void checkNormalize01 (String lexical ) {
229215 XMLGregorianCalendar lhs = datatypeFactory .newXMLGregorianCalendar (lexical );
230216 lhs .normalize ();
231217 }
232218
233- @ DataProvider (name = "lexical02" )
234- public Object [][] getLexicalRepresentForNormalize02 () {
235- return new Object [][] { { "2000-01-16T00:00:00.01Z" }, { "2000-01-16T00:00:00.01" }, { "13:20:00" } };
236- }
237-
238219 /*
239220 * Test XMLGregorianCalendar#normalize(...).
240221 *
241222 * Bug # 5064587 XMLGregorianCalendar.normalize shall not change timezone
242- *
243223 */
244- @ Test (dataProvider = "lexical02" )
224+ @ ParameterizedTest
225+ @ ValueSource (strings ={ "2000-01-16T00:00:00.01Z" , "2000-01-16T00:00:00.01" , "13:20:00" })
245226 public void checkNormalize02 (String lexical ) {
246227 XMLGregorianCalendar orig = datatypeFactory .newXMLGregorianCalendar (lexical );
247228 XMLGregorianCalendar normalized = datatypeFactory .newXMLGregorianCalendar (lexical ).normalize ();
@@ -291,8 +272,6 @@ public void checkToGregorianCalendar01() {
291272 int hour = calendar .get (HOUR );
292273
293274 assertTrue ((year == 2003 && hour == 2 && minute == 3 ), " expecting year == 2003, hour == 2, minute == 3" + ", result is year == " + year + ", hour == " + hour + ", minute == " + minute );
294-
295-
296275 }
297276
298277 /*
@@ -311,8 +290,7 @@ public void checkToGregorianCalendar02() {
311290 calendar .toGregorianCalendar (TimeZone .getDefault (), Locale .getDefault (), null );
312291 }
313292
314- @ DataProvider (name = "calendar" )
315- public Object [][] getXMLGregorianCalendarData () {
293+ public static Object [][] getXMLGregorianCalendarData () {
316294 return new Object [][] {
317295 // year, month, day, hour, minute, second
318296 { 1970 , 1 , 1 , 0 , 0 , 0 }, // DATETIME
@@ -332,10 +310,12 @@ public Object[][] getXMLGregorianCalendarData() {
332310 * Bug # 5049528
333311 *
334312 */
335- @ Test (dataProvider = "calendar" )
313+ @ ParameterizedTest
314+ @ MethodSource ("getXMLGregorianCalendarData" )
336315 public void checkToStringPos (final int year , final int month , final int day , final int hour , final int minute , final int second ) {
337316 XMLGregorianCalendar calendar = datatypeFactory .newXMLGregorianCalendar (year , month , day , hour , minute , second , undef , undef );
338- calendar .toString ();
317+ assertNotNull (calendar .toString ());
318+ assertFalse (calendar .toString ().isEmpty ());
339319 }
340320
341321 /*
@@ -345,13 +325,13 @@ public void checkToStringPos(final int year, final int month, final int day, fin
345325 * if all parameters are undef
346326 *
347327 */
348- @ Test ( expectedExceptions = IllegalStateException . class )
328+ @ Test
349329 public void checkToStringNeg () {
350330 XMLGregorianCalendar calendar = datatypeFactory .newXMLGregorianCalendar (undef , undef , undef , undef , undef , undef , undef , undef );
351331 // expected to fail
352- calendar . toString ( );
332+ assertThrows ( IllegalStateException . class , calendar :: toString );
353333 }
354334
355- private final int undef = DatatypeConstants .FIELD_UNDEFINED ;
335+ private static final int undef = DatatypeConstants .FIELD_UNDEFINED ;
356336
357337}
0 commit comments