Skip to content

8381882: Convert test/jaxp/javax/xml/jaxp/unittest/stream tests to JUnit#30643

Open
david-beaumont wants to merge 3 commits intoopenjdk:masterfrom
david-beaumont:jdk_8381882_jaxp_stream
Open

8381882: Convert test/jaxp/javax/xml/jaxp/unittest/stream tests to JUnit#30643
david-beaumont wants to merge 3 commits intoopenjdk:masterfrom
david-beaumont:jdk_8381882_jaxp_stream

Conversation

@david-beaumont
Copy link
Copy Markdown
Contributor

@david-beaumont david-beaumont commented Apr 9, 2026

Convert and tidy-up unit tests in test/jaxp/javax/xml/jaxp/unittest/stream.

It is recommended to set the diff settings in github to hide whitespace (cog-wheel menu).

There are a lot of cases where manual catch blocks with explicit fail are removed to just allow the test to fail idiomatically by throwing the exception normally. This causes thousands of lines to be un-indented (with no other change).

About 200 explicit uses of fail() were either removed or converted to appropriate JUnit asserts.

There are also several non-trivial changes in this PR related to bad tests where, for example, catching and ignoring exceptions allowed the test to pass under all situations.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8381882: Convert test/jaxp/javax/xml/jaxp/unittest/stream tests to JUnit (Sub-task - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30643/head:pull/30643
$ git checkout pull/30643

Update a local copy of the PR:
$ git checkout pull/30643
$ git pull https://git.openjdk.org/jdk.git pull/30643/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30643

View PR using the GUI difftool:
$ git pr show -t 30643

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30643.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 9, 2026

👋 Welcome back dbeaumont! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 9, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Apr 9, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 9, 2026

@david-beaumont The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

Copy link
Copy Markdown
Contributor Author

@david-beaumont david-beaumont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some "preloaded" comments explaining non-trivial changes.

Assert.assertEquals(s1.getEventType(), XMLStreamConstants.START_DOCUMENT);
s1.next();
s1.next(); // advance to <TITLE>
Assert.assertTrue(s1.getLocalName().equals("TITLE"));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of assertions have been rewritten to be idiomatic. Mostly this is handled via IntelliJ analysis, but not always.

public class Bug6509774 {

@Test
public void test0() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was obviously cut & pasted with alternating blank lines (making it much less readable), so I reformatted it to remove unwanted empty lines.

}
}

public static/* synchronized */XMLStreamReader getReader(InputStream is) throws Exception {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for synchronization on factories.

*/
public class CoalesceTest {

String countryElementContent = "START India CS}}}}}} India END";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well as making these constants, I could switch to UPPER_SNAKE_CASE. Your (reviewer) call.

eventType = streamReader.next();
if (eventType == XMLStreamConstants.CHARACTERS) {
String text = streamReader.getText();
if (!text.equals(descriptionElementContent)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the debug output is needed if assertEquals() is used.

public void testDuplicateNamespaceURI() throws Exception {

xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement(new String(""), "localName", new String("nsUri"));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear why the new String() was being used here. I could revert it if it's felt likely to be important.

public class NamespaceTest {

/** debug output? */
private static final boolean DEBUG = true;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug output is extensive and unnecessary for unit tests. I've checked that no output was also affecting the test itself.

}

Assert.assertTrue(actualOutput.equals(EXPECTED_OUTPUT) || actualOutput.equals(EXPECTED_OUTPUT_2), "Expected: " + EXPECTED_OUTPUT + "\n" + "Actual: "
assertTrue(actualOutput.equals(EXPECTED_OUTPUT) || actualOutput.equals(EXPECTED_OUTPUT_2), "Expected: " + EXPECTED_OUTPUT + "\n" + "Actual: "
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left this in, but realistically only one or these sub-clauses will ever be true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of removal of redundant catch clauses in this test... sorry!

XMLStreamWriter w = xof.createXMLStreamWriter(sw);
w.writeStartDocument();
w.writeStartElement("foo", "bar", "zot");
w.writeDefaultNamespace(null);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not actually asserting anything.

@david-beaumont david-beaumont marked this pull request as ready for review April 9, 2026 09:51
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 9, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 9, 2026

Webrevs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant