Skip to content

Commit 637d7aa

Browse files
Migrate jaxp/functional/javax/xml tests to JUnit
1 parent ce7a890 commit 637d7aa

47 files changed

Lines changed: 1660 additions & 2006 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/jaxp/javax/xml/jaxp/functional/javax/xml/datatype/ptests/DurationTest.java

Lines changed: 128 additions & 138 deletions
Large diffs are not rendered by default.

test/jaxp/javax/xml/jaxp/functional/javax/xml/datatype/ptests/FactoryNewInstanceTest.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -23,25 +23,26 @@
2323

2424
package javax.xml.datatype.ptests;
2525

26-
import static org.testng.Assert.assertNotNull;
27-
import static org.testng.Assert.assertNotSame;
28-
import static org.testng.Assert.assertSame;
29-
import static org.testng.Assert.assertEquals;
26+
import jaxp.library.JAXPDataProvider;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.MethodSource;
3030

3131
import javax.xml.datatype.DatatypeConfigurationException;
3232
import javax.xml.datatype.DatatypeFactory;
3333
import javax.xml.datatype.Duration;
3434

35-
import jaxp.library.JAXPDataProvider;
36-
37-
import org.testng.annotations.DataProvider;
38-
import org.testng.annotations.Test;
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertNotNull;
37+
import static org.junit.jupiter.api.Assertions.assertNotSame;
38+
import static org.junit.jupiter.api.Assertions.assertSame;
39+
import static org.junit.jupiter.api.Assertions.assertThrows;
3940

4041
/*
4142
* @test
4243
* @bug 8169778
4344
* @library /javax/xml/jaxp/libs
44-
* @run testng/othervm javax.xml.datatype.ptests.FactoryNewInstanceTest
45+
* @run junit/othervm javax.xml.datatype.ptests.FactoryNewInstanceTest
4546
* @summary Tests for DatatypeFactory.newInstance(factoryClassName , classLoader)
4647
*/
4748
public class FactoryNewInstanceTest {
@@ -50,9 +51,11 @@ public class FactoryNewInstanceTest {
5051
"com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl";
5152
private static final String DATATYPE_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
5253

53-
@DataProvider(name = "parameters")
54-
public Object[][] getValidateParameters() {
55-
return new Object[][] { { DATATYPE_FACTORY_CLASSNAME, null }, { DATATYPE_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
54+
public static Object[][] getValidateParameters() {
55+
return new Object[][] {
56+
{ DATATYPE_FACTORY_CLASSNAME, null },
57+
{ DATATYPE_FACTORY_CLASSNAME, FactoryNewInstanceTest.class.getClassLoader() },
58+
};
5659
}
5760

5861
/**
@@ -66,8 +69,8 @@ public void testDefaultInstance() throws Exception {
6669
DatatypeFactory dtf2 = DatatypeFactory.newInstance();
6770
assertNotSame(dtf1, dtf2, "same instance returned:");
6871
assertSame(dtf1.getClass(), dtf2.getClass(),
69-
"unexpected class mismatch for newDefaultInstance():");
70-
assertEquals(dtf1.getClass().getName(), DEFAULT_IMPL_CLASS);
72+
"unexpected class mismatch for newDefaultInstance():");
73+
assertEquals(DEFAULT_IMPL_CLASS, dtf1.getClass().getName());
7174
}
7275

7376
/*
@@ -76,7 +79,8 @@ public void testDefaultInstance() throws Exception {
7679
* implementation of javax.xml.datatype.DatatypeFactory , should return
7780
* newInstance of DatatypeFactory
7881
*/
79-
@Test(dataProvider = "parameters")
82+
@ParameterizedTest
83+
@MethodSource("getValidateParameters")
8084
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
8185
DatatypeFactory dtf = DatatypeFactory.newInstance(DATATYPE_FACTORY_CLASSNAME, null);
8286
Duration duration = dtf.newDuration(true, 1, 1, 1, 1, 1, 1);
@@ -89,9 +93,11 @@ public void testNewInstance(String factoryClassName, ClassLoader classLoader) th
8993
* java.lang.ClassLoader classLoader) factoryClassName is null , should
9094
* throw DatatypeConfigurationException
9195
*/
92-
@Test(expectedExceptions = DatatypeConfigurationException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
96+
@ParameterizedTest
97+
@JAXPDataProvider.NewInstanceNeg
9398
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
94-
DatatypeFactory.newInstance(factoryClassName, classLoader);
99+
assertThrows(
100+
DatatypeConfigurationException.class,
101+
() -> DatatypeFactory.newInstance(factoryClassName, classLoader));
95102
}
96-
97103
}

test/jaxp/javax/xml/jaxp/functional/javax/xml/datatype/ptests/XMLGregorianCalendarTest.java

Lines changed: 66 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -23,55 +23,53 @@
2323

2424
package 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

3632
import javax.xml.datatype.DatatypeConfigurationException;
3733
import javax.xml.datatype.DatatypeConstants;
3834
import javax.xml.datatype.DatatypeFactory;
3935
import javax.xml.datatype.Duration;
4036
import 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
*/
5457
public 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

Comments
 (0)