Skip to content

8381842: Refactor remaining TestNG tests under java/net/ to use JUnit#30681

Open
dfuch wants to merge 1 commit intoopenjdk:masterfrom
dfuch:junit-rem-net-8381842
Open

8381842: Refactor remaining TestNG tests under java/net/ to use JUnit#30681
dfuch wants to merge 1 commit intoopenjdk:masterfrom
dfuch:junit-rem-net-8381842

Conversation

@dfuch
Copy link
Copy Markdown
Member

@dfuch dfuch commented Apr 10, 2026

Hi, may I get a review for this change that converts the remaining TestNG tests under test/jdk/java/net to JUnit.

An exception is java/net/NetworkInterface/NetworkInterfaceStreamTest.java which depends on library classes depending on TestNG. Converting that test is not done here but is tracked by JDK-8381848



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-8381842: Refactor remaining TestNG tests under java/net/ to use JUnit (Sub-task - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30681

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 10, 2026

👋 Welcome back dfuchs! 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 10, 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 net net-dev@openjdk.org label Apr 10, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 10, 2026

@dfuch The following label will be automatically applied to this pull request:

  • net

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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 10, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 10, 2026

Webrevs

@@ -53,8 +54,7 @@ public void testSetAddress() throws Exception {
assertTrue(pkt.getAddress() == null);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

assertNull?

.map(InetAddress::getHostAddress).toArray(String[]::new);
String [] expectedAddresses = getExpectedAddressesArray();

if (Arrays.deepEquals(resolvedAddresses, expectedAddresses)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could use assertArrayEquals? (unless you want to keep the custom error messages)

}

@Test
// InetSocketAddress.toString() throws NPE with unresolved address
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This comment is wrong / misleading; it was the behavior before https://bugs.openjdk.org/browse/JDK-4464064 was fixed

Maybe would also be good to rename the method then from NPETest to unresolvedTest or similar?

// InetSocketAddress.toString() throws NPE with unresolved address
public static void NPETest() {
public void NPETest() {
System.out.println(new InetSocketAddress("unresolved", 12345));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace with assertDoesNotThrow / assertNotNull?


@DataProvider(name = "hostPortArgs")
public Object[][] createArgs1() {
public static Object[][] createArgs1() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it make sense to apply the provider name as method name (i.e. hostPortArgs) to make it more expressive?

(same also for the other argument methods here)

Comment on lines +62 to +63
static private HttpServer server;
static private SocksServer socks;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should be private static instead of static private to be conventional?

private String response = "Hello.";
static private HttpServer server;
static private SocksServer socks;
private static String response = "Hello.";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can be final?

Comment on lines 76 to 83
try (ServerSocket ss = new ServerSocket(port, backlog, InetAddress.getLoopbackAddress());
Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
Socket s2 = ss.accept()) {
Assert.fail("IOException was expected to be thrown, but wasn't");
fail("IOException was expected to be thrown, but wasn't");
} catch (IOException ioe) {
// expected
// now verify the IOE was thrown for the correct expected reason
if (!(ioe.getCause() instanceof IllegalArgumentException)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use assertThrows? E.g.:

var e = assertThrows(IOException.class, ...);
assertInstanceOf(IllegalArgumentException.class, e.getCause());

That would also make it clearer which of the calls is expected to throw the IOException.

Comment on lines 49 to +50
if (namelen == -1)
return new Object[][] {new String[]{""}};
return List.of("");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove this namelen == -1 check because it is always false?

Comment on lines +54 to +56
new String(new char[100]).replaceAll("\0", "x"),
new String(new char[namelen]).replaceAll("\0", "x"),
new String(new char[namelen-1]).replaceAll("\0", "x")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can simplify these?

Suggested change
new String(new char[100]).replaceAll("\0", "x"),
new String(new char[namelen]).replaceAll("\0", "x"),
new String(new char[namelen-1]).replaceAll("\0", "x")
"x".repeat(100),
"x".repeat(namelen),
"x".repeat(namelen - 1)

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

Labels

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

Development

Successfully merging this pull request may close these issues.

2 participants