From 5e89669d180a4ac969f13cf6c066efbdb9998dc5 Mon Sep 17 00:00:00 2001 From: Mahendra Chhipa Date: Thu, 2 Apr 2026 19:59:21 +0000 Subject: [PATCH] 8381568: Refactor java/net/spi/InetAddressResolverProvider test from testNg to use JUnit Reviewed-by: dfuchs --- .../AddressesCachingTest.java | 37 +++++++------ .../AddressesStaleCachingTest.java | 24 +++++---- .../BootstrapResolverUsageTest.java | 12 ++--- .../BuiltInResolverTest.java | 22 ++++---- .../EmptyResultsStreamTest.java | 28 +++++----- .../InetAddressUsageInGetProviderTest.java | 7 ++- .../LookupPolicyMappingTest.java | 53 ++++++++++--------- .../LookupPolicyOfTest.java | 25 ++++----- .../ProviderGetExceptionTest.java | 20 +++---- .../ResolutionWithExceptionTest.java | 18 ++++--- .../ReverseLookupDelegationTest.java | 14 ++--- .../classpath/ClasspathProviderTest.java | 9 ++-- .../module/ModularProviderTest.java | 7 +-- 13 files changed, 148 insertions(+), 128 deletions(-) diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesCachingTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesCachingTest.java index 26dabc00063..f4fa2016983 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesCachingTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesCachingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,10 +24,13 @@ import java.net.InetAddress; import java.net.UnknownHostException; -import org.testng.Assert; -import org.testng.annotations.Test; import impl.SimpleResolverProviderImpl; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /* @@ -37,26 +40,26 @@ import impl.SimpleResolverProviderImpl; * @library lib providers/simple * @build test.library/testlib.ResolutionRegistry * simple.provider/impl.SimpleResolverProviderImpl AddressesCachingTest - * @run testng/othervm -Djava.security.properties=${test.src}/props/NeverCache.props + * @run junit/othervm -Djava.security.properties=${test.src}/props/NeverCache.props * -Dtest.cachingDisabled=true AddressesCachingTest - * @run testng/othervm -Djava.security.properties=${test.src}/props/ForeverCache.props + * @run junit/othervm -Djava.security.properties=${test.src}/props/ForeverCache.props * -Dtest.cachingDisabled=false AddressesCachingTest - * @run testng/othervm + * @run junit/othervm * -Djava.security.properties=${test.src}/props/NeverCacheIgnoreMinusStale.props * -Dtest.cachingDisabled=true AddressesCachingTest - * @run testng/othervm + * @run junit/othervm * -Djava.security.properties=${test.src}/props/NeverCacheIgnorePositiveStale.props * -Dtest.cachingDisabled=true AddressesCachingTest - * @run testng/othervm + * @run junit/othervm * -Djava.security.properties=${test.src}/props/NeverCacheIgnoreZeroStale.props * -Dtest.cachingDisabled=true AddressesCachingTest - * @run testng/othervm + * @run junit/othervm * -Djava.security.properties=${test.src}/props/ForeverCacheIgnoreMinusStale.props * -Dtest.cachingDisabled=false AddressesCachingTest - * @run testng/othervm + * @run junit/othervm * -Djava.security.properties=${test.src}/props/ForeverCacheIgnorePositiveStale.props * -Dtest.cachingDisabled=false AddressesCachingTest - * @run testng/othervm + * @run junit/othervm * -Djava.security.properties=${test.src}/props/ForeverCacheIgnoreZeroStale.props * -Dtest.cachingDisabled=false AddressesCachingTest */ @@ -66,10 +69,10 @@ public class AddressesCachingTest { public void testPositiveCaching() { boolean observedTwoLookups = performLookups(false); if (CACHING_DISABLED) { - Assert.assertTrue(observedTwoLookups, + assertTrue(observedTwoLookups, "Two positive lookups are expected with caching disabled"); } else { - Assert.assertFalse(observedTwoLookups, + assertFalse(observedTwoLookups, "Only one positive lookup is expected with caching enabled"); } } @@ -78,10 +81,10 @@ public class AddressesCachingTest { public void testNegativeCaching() { boolean observedTwoLookups = performLookups(true); if (CACHING_DISABLED) { - Assert.assertTrue(observedTwoLookups, + assertTrue(observedTwoLookups, "Two negative lookups are expected with caching disabled"); } else { - Assert.assertFalse(observedTwoLookups, + assertFalse(observedTwoLookups, "Only one negative lookup is expected with caching enabled"); } } @@ -107,11 +110,11 @@ public class AddressesCachingTest { try { InetAddress.getByName(hostName); if (performNegativeLookup) { - Assert.fail("Host name is expected to get unresolved"); + fail("Host name is expected to get unresolved"); } } catch (UnknownHostException uhe) { if (!performNegativeLookup) { - Assert.fail("Host name is expected to get resolved"); + fail("Host name is expected to get resolved"); } } } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesStaleCachingTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesStaleCachingTest.java index a8393221a72..a2c5c3e8443 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesStaleCachingTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/AddressesStaleCachingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,8 +27,11 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import impl.SimpleResolverProviderImpl; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /* @@ -38,7 +41,7 @@ import org.testng.annotations.Test; * @library lib providers/simple * @build test.library/testlib.ResolutionRegistry * simple.provider/impl.SimpleResolverProviderImpl AddressesStaleCachingTest - * @run testng/othervm -Djava.security.properties=${test.src}/props/CacheStale.props AddressesStaleCachingTest + * @run junit/othervm -Djava.security.properties=${test.src}/props/CacheStale.props AddressesStaleCachingTest */ public class AddressesStaleCachingTest { @@ -64,20 +67,21 @@ public class AddressesStaleCachingTest { Thread.sleep(10000); // intentionally big delay > x2 stale property // The refreshTime is expired, we will do the successful lookup. Lookup second = doLookup(false, 0); - Assert.assertNotEquals(first.timestamp, second.timestamp, + assertNotEquals(first.timestamp, second.timestamp, "Two lookups are expected"); Thread.sleep(10000); // intentionally big delay > x2 stale property // The refreshTime is expired again, we will do the failed lookup. Lookup third = doLookup(true, 0); - Assert.assertNotEquals(second.timestamp, third.timestamp, + assertNotEquals(second.timestamp, third.timestamp, "Two lookups are expected"); // The stale cache is enabled, so we should get valid/same data for // all requests(even for the failed request). - Assert.assertEquals(first.address, second.address, + assertArrayEquals(first.address, second.address, "Same address is expected"); - Assert.assertEquals(second.address, third.address, + + assertArrayEquals(second.address, third.address, "Same address is expected"); } @@ -133,10 +137,10 @@ public class AddressesStaleCachingTest { byte[] secondAddress = InetAddress.getByName("javaTest.org").getAddress(); long secondTimestamp = SimpleResolverProviderImpl.getLastLookupTimestamp(); - Assert.assertEquals(firstAddress, secondAddress, + assertArrayEquals(firstAddress, secondAddress, "Same address is expected"); if (timeout == 0 || timeout - System.nanoTime() > 0) { - Assert.assertEquals(firstTimestamp, secondTimestamp, + assertEquals(firstTimestamp, secondTimestamp, "Only one positive lookup is expected with caching enabled"); } return new Lookup(firstAddress, firstTimestamp); diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/BootstrapResolverUsageTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/BootstrapResolverUsageTest.java index 9f0902d2c1d..012410c1566 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/BootstrapResolverUsageTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/BootstrapResolverUsageTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,12 +21,13 @@ * questions. */ +import org.junit.jupiter.api.Test; + import java.net.InetAddress; -import org.testng.Assert; -import org.testng.annotations.Test; import static impl.WithBootstrapResolverUsageProvider.numberOfGetCalls; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @test @@ -35,7 +36,7 @@ import static impl.WithBootstrapResolverUsageProvider.numberOfGetCalls; * InetAddressResolverProvider.get method uses InetAddress lookup API. * @library providers/bootstrapUsage * @build bootstrap.usage.provider/impl.WithBootstrapResolverUsageProvider - * @run testng/othervm BootstrapResolverUsageTest + * @run junit/othervm BootstrapResolverUsageTest */ public class BootstrapResolverUsageTest { @@ -43,7 +44,6 @@ public class BootstrapResolverUsageTest { @Test public void testSuccessfulProviderInstantiationTest() throws Exception { System.err.println(InetAddress.getAllByName(InetAddress.getLocalHost().getHostName())); - Assert.assertEquals(numberOfGetCalls, 1, - "InetAddressResolverProvider.get was called more than once"); + assertEquals(1, numberOfGetCalls, "InetAddressResolverProvider.get was called more than once"); } } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/BuiltInResolverTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/BuiltInResolverTest.java index 8b8b866d7b2..e91446e540a 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/BuiltInResolverTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/BuiltInResolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,30 +21,34 @@ * questions. */ -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.net.InetAddress; import java.net.UnknownHostException; import java.net.spi.InetAddressResolver; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /* * @test * @summary white-box test to check that the built-in resolver * is used by default. * @modules java.base/java.net:open - * @run testng/othervm BuiltInResolverTest + * @run junit/othervm BuiltInResolverTest */ public class BuiltInResolverTest { - private Field builtInResolverField, resolverField; + private static Field builtInResolverField, resolverField; - @BeforeTest - public void beforeTest() throws NoSuchFieldException { + @BeforeAll + public static void beforeTest() throws NoSuchFieldException { Class inetAddressClass = InetAddress.class; // Needs to happen for InetAddress.resolver to be initialized try { @@ -72,7 +76,7 @@ public class BuiltInResolverTest { assertNotNull(defaultClassName, "defaultClassName not set"); assertNotNull(currentClassName, "currentClassName name not set"); - assertEquals(currentClassName, defaultClassName, + assertEquals(defaultClassName, currentClassName, "BUILTIN_RESOLVER resolver was not used."); System.err.println("Resolver used by default is the built-in resolver"); } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/EmptyResultsStreamTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/EmptyResultsStreamTest.java index 17b9aa5d011..db0f293b712 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/EmptyResultsStreamTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/EmptyResultsStreamTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,32 +21,36 @@ * questions. */ -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; +import static org.junit.jupiter.api.Assertions.assertThrows; /* * @test * @summary checks that InetAddress forward lookup API throw UnknownHostException * when resolver returns empty address stream. * @library providers/empty * @build empty.results.provider/impl.EmptyResultsProviderImpl - * @run testng/othervm EmptyResultsStreamTest + * @run junit/othervm EmptyResultsStreamTest */ public class EmptyResultsStreamTest { - @Test(expectedExceptions = UnknownHostException.class) - public void getAllByNameTest() throws UnknownHostException { - System.err.println("getAllByName unexpectedly completed: " + - Arrays.deepToString(InetAddress.getAllByName("test1.org"))); + @Test() + public void getAllByNameTest() { + assertThrows(UnknownHostException.class, () -> { + System.err.println("getAllByName unexpectedly completed: " + + Arrays.deepToString(InetAddress.getAllByName("test1.org"))); + }); } - @Test(expectedExceptions = UnknownHostException.class) - public void getByNameTest() throws UnknownHostException { - System.err.println("getByName unexpectedly completed: " + - InetAddress.getByName("test2.org")); + @Test() + public void getByNameTest() { + assertThrows(UnknownHostException.class, () -> { + System.err.println("getByName unexpectedly completed: " + + InetAddress.getByName("test2.org")); + }); } } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/InetAddressUsageInGetProviderTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/InetAddressUsageInGetProviderTest.java index dd52893c1e8..3458270960b 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/InetAddressUsageInGetProviderTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/InetAddressUsageInGetProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,8 +21,7 @@ * questions. */ -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.net.InetAddress; @@ -32,7 +31,7 @@ import java.net.InetAddress; * wouldn't cause stack overflow and will be successfully installed. * @library providers/recursive * @build recursive.init.provider/impl.InetAddressUsageInGetProviderImpl - * @run testng/othervm InetAddressUsageInGetProviderTest + * @run junit/othervm InetAddressUsageInGetProviderTest */ public class InetAddressUsageInGetProviderTest { diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyMappingTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyMappingTest.java index e845e2e0461..bbfa9f5555c 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyMappingTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyMappingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,9 +34,10 @@ import static java.net.spi.InetAddressResolver.LookupPolicy.IPV6_FIRST; import jdk.test.lib.net.IPSupport; import jdk.test.lib.NetworkConfiguration; -import org.testng.annotations.Test; -import org.testng.Assert; -import org.testng.SkipException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.abort; /* * @test @@ -45,26 +46,26 @@ import org.testng.SkipException; * @library lib providers/simple /test/lib * @build test.library/testlib.ResolutionRegistry simple.provider/impl.SimpleResolverProviderImpl * jdk.test.lib.net.IPSupport LookupPolicyMappingTest - * @run testng/othervm LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=true LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack=false LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv4Stack LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest - * @run testng/othervm -Djava.net.preferIPv6Addresses LookupPolicyMappingTest + * @run junit/othervm LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=true LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack=false LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack -Djava.net.preferIPv6Addresses LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv4Stack LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv6Addresses=true LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv6Addresses=false LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv6Addresses=system LookupPolicyMappingTest + * @run junit/othervm -Djava.net.preferIPv6Addresses LookupPolicyMappingTest */ public class LookupPolicyMappingTest { @@ -88,7 +89,7 @@ public class LookupPolicyMappingTest { String expectedResultsKey = calculateMapKey(preferIPv4Stack, preferIPv6Addresses); int expectedCharacteristics = EXPECTED_RESULTS_MAP.get(expectedResultsKey); - Assert.assertTrue(characteristicsMatch( + assertTrue(characteristicsMatch( runtimeCharacteristics, expectedCharacteristics), "Unexpected LookupPolicy observed"); } @@ -100,7 +101,7 @@ public class LookupPolicyMappingTest { // If preferIPv4=true and no IPv4 - skip if (IPSupport.preferIPv4Stack()) { if (!IPSupport.hasIPv4()) { - throw new SkipException("Skip tests - IPv4 support required"); + abort("Skip tests - IPv4 support required"); } return; } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyOfTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyOfTest.java index 73e2581f5cd..09585322c83 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyOfTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/LookupPolicyOfTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,11 +25,11 @@ * @test * @summary check if LookupPolicy.of correctly handles valid and illegal * combinations of characteristics bit mask flags. - * @run testng LookupPolicyOfTest + * @run junit LookupPolicyOfTest */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.net.spi.InetAddressResolver.LookupPolicy; import java.util.List; @@ -38,21 +38,23 @@ import static java.net.spi.InetAddressResolver.LookupPolicy.IPV4; import static java.net.spi.InetAddressResolver.LookupPolicy.IPV4_FIRST; import static java.net.spi.InetAddressResolver.LookupPolicy.IPV6; import static java.net.spi.InetAddressResolver.LookupPolicy.IPV6_FIRST; +import static org.junit.jupiter.api.Assertions.assertThrows; public class LookupPolicyOfTest { - @Test(dataProvider = "validCharacteristics") + @ParameterizedTest + @MethodSource("validCharacteristicValue") public void testValidCharacteristicCombinations(List validCombination) { LookupPolicy.of(bitFlagsToCharacteristicsValue(validCombination)); } - @Test(dataProvider = "invalidCharacteristics", expectedExceptions = IllegalArgumentException.class) - public void testInvalidCharacteristicCombinations(List invalidCombination) { - LookupPolicy.of(bitFlagsToCharacteristicsValue(invalidCombination)); + @ParameterizedTest + @MethodSource("illegalCharacteristicValue") + public void testInvalidCharacteristicCombination(List invalidCombination) { + assertThrows(IllegalArgumentException.class, () -> LookupPolicy.of(bitFlagsToCharacteristicsValue(invalidCombination))); } - @DataProvider(name = "validCharacteristics") - public Object[][] validCharacteristicValue() { + public static Object[][] validCharacteristicValue() { return new Object[][]{ {List.of(IPV4)}, {List.of(IPV4, IPV4_FIRST)}, @@ -68,8 +70,7 @@ public class LookupPolicyOfTest { }; } - @DataProvider(name = "invalidCharacteristics") - public Object[][] illegalCharacteristicValue() { + public static Object[][] illegalCharacteristicValue() { return new Object[][]{ {List.of()}, {List.of(IPV4_FIRST)}, diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/ProviderGetExceptionTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/ProviderGetExceptionTest.java index fe5269c7b46..7df304bc235 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/ProviderGetExceptionTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/ProviderGetExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,13 +21,15 @@ * questions. */ +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import java.net.InetAddress; import java.util.Arrays; -import org.testng.Assert; -import org.testng.annotations.Test; - import static impl.FaultyResolverProviderGetImpl.EXCEPTION_MESSAGE; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; /* * @test @@ -35,7 +37,7 @@ import static impl.FaultyResolverProviderGetImpl.EXCEPTION_MESSAGE; * instantiate a resolver. * @library providers/faulty * @build faulty.provider/impl.FaultyResolverProviderGetImpl - * @run testng/othervm ProviderGetExceptionTest + * @run junit/othervm ProviderGetExceptionTest */ public class ProviderGetExceptionTest { @@ -54,10 +56,10 @@ public class ProviderGetExceptionTest { callInetAddressAndCheckException(() -> InetAddress.getByAddress(address).getHostName()); } - private void callInetAddressAndCheckException(Assert.ThrowingRunnable apiCall) { - IllegalArgumentException iae = Assert.expectThrows(IllegalArgumentException.class, apiCall); + private void callInetAddressAndCheckException(Executable apiCall) { + IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, apiCall); System.out.println("Got exception of expected type:" + iae); - Assert.assertNull(iae.getCause(), "cause is not null"); - Assert.assertEquals(iae.getMessage(), EXCEPTION_MESSAGE); + assertNull(iae.getCause(), "cause is not null"); + assertEquals(EXCEPTION_MESSAGE, iae.getMessage()); } } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/ResolutionWithExceptionTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/ResolutionWithExceptionTest.java index dd17c1d987c..ce68f8a8e6f 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/ResolutionWithExceptionTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/ResolutionWithExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,9 +27,11 @@ import java.net.UnknownHostException; import impl.ThrowingLookupsProviderImpl; import static impl.ThrowingLookupsProviderImpl.RUNTIME_EXCEPTION_MESSAGE; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /* * @test @@ -37,7 +39,7 @@ import org.testng.annotations.Test; * implementation throws RuntimeException during forward or reverse lookup. * @library providers/throwing * @build throwing.lookups.provider/impl.ThrowingLookupsProviderImpl - * @run testng/othervm ResolutionWithExceptionTest + * @run junit/othervm ResolutionWithExceptionTest */ public class ResolutionWithExceptionTest { @@ -68,7 +70,7 @@ public class ResolutionWithExceptionTest { private void runGetByNameTest() { // InetAddress.getByName() is expected to throw UnknownHostException in all cases - UnknownHostException uhe = Assert.expectThrows(UnknownHostException.class, + UnknownHostException uhe = Assertions.assertThrows(UnknownHostException.class, () -> InetAddress.getByName("doesnt.matter.com")); // If provider is expected to throw RuntimeException - check that UnknownHostException // is set as its cause @@ -76,10 +78,10 @@ public class ResolutionWithExceptionTest { Throwable cause = uhe.getCause(); if (cause instanceof RuntimeException re) { // Check RuntimeException message - Assert.assertEquals(re.getMessage(), RUNTIME_EXCEPTION_MESSAGE, + assertEquals(RUNTIME_EXCEPTION_MESSAGE, re.getMessage(), "incorrect exception message"); } else { - Assert.fail("UnknownHostException cause is not RuntimeException"); + fail("UnknownHostException cause is not RuntimeException"); } } } @@ -89,6 +91,6 @@ public class ResolutionWithExceptionTest { // if there is an error during reverse lookup operation the literal IP // address String will be returned. String literalIP = InetAddress.getByAddress(new byte[]{1, 2, 3, 4}).getCanonicalHostName(); - Assert.assertEquals(literalIP, "1.2.3.4"); + assertEquals("1.2.3.4", literalIP); } } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/ReverseLookupDelegationTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/ReverseLookupDelegationTest.java index 439521736db..d72a6b1fc0e 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/ReverseLookupDelegationTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/ReverseLookupDelegationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,9 +21,9 @@ * questions. */ -import impl.DelegatingProviderImpl; -import org.testng.Assert; -import org.testng.annotations.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; import java.net.InetAddress; import java.net.UnknownHostException; @@ -37,7 +37,7 @@ import static impl.DelegatingProviderImpl.lastReverseLookupThrowable; * InetAddressResolver. * @library providers/delegating * @build delegating.provider/impl.DelegatingProviderImpl - * @run testng/othervm ReverseLookupDelegationTest + * @run junit/othervm ReverseLookupDelegationTest */ public class ReverseLookupDelegationTest { @@ -53,10 +53,10 @@ public class ReverseLookupDelegationTest { // Check that originally supplied byte array was used to construct canonical host name after // failed reverse lookup. - Assert.assertEquals("1.2.3.4", canonicalHostName, "unexpected canonical hostname"); + assertEquals("1.2.3.4", canonicalHostName, "unexpected canonical hostname"); // Check that on a provider side the IllegalArgumentException has been thrown by the built-in resolver - Assert.assertTrue(lastReverseLookupThrowable instanceof IllegalArgumentException, + assertTrue(lastReverseLookupThrowable instanceof IllegalArgumentException, "wrong exception type is thrown by the built-in resolver"); } } diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/classpath/ClasspathProviderTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/classpath/ClasspathProviderTest.java index 51285fb045c..c82f2442831 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/classpath/ClasspathProviderTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/classpath/ClasspathProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,18 +21,17 @@ * questions. */ +import org.junit.jupiter.api.Test; + import java.net.InetAddress; -import org.testng.annotations.Test; - -import static org.testng.Assert.assertThrows; /* * @test * @summary Test that InetAddressResolverProvider implementation can be installed to a class path. * @library ../../lib * @build test.library/testlib.ResolutionRegistry ClasspathResolverProviderImpl - * @run testng/othervm ClasspathProviderTest + * @run junit/othervm ClasspathProviderTest */ public class ClasspathProviderTest { diff --git a/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/module/ModularProviderTest.java b/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/module/ModularProviderTest.java index 410f25aa9c3..56e52d52729 100644 --- a/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/module/ModularProviderTest.java +++ b/test/jdk/java/net/spi/InetAddressResolverProvider/serviceProviderOriginType/module/ModularProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,9 +21,10 @@ * questions. */ +import org.junit.jupiter.api.Test; + import java.net.InetAddress; -import org.testng.annotations.Test; /* * @test @@ -31,7 +32,7 @@ import org.testng.annotations.Test; * @library ../../lib ../../providers/simple * @build test.library/testlib.ResolutionRegistry simple.provider/impl.SimpleResolverProviderImpl * ModularProviderTest - * @run testng/othervm ModularProviderTest + * @run junit/othervm ModularProviderTest */