-
Notifications
You must be signed in to change notification settings - Fork 6.4k
8368091: Use JUnit Jupiter API in sun/net/ext, sun/net/www and sun/net/spi tests #30645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2019, 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,19 @@ | |
| * questions. | ||
| */ | ||
|
|
||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
| import org.junit.jupiter.api.Test; | ||
| import sun.net.spi.DefaultProxySelector; | ||
|
|
||
| import java.net.ProxySelector; | ||
| import java.net.URI; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.fail; | ||
|
|
||
| /** | ||
| * @test | ||
| * @bug 6563286 6797318 8177648 | ||
| * @summary Tests sun.net.spi.DefaultProxySelector#select(URI) | ||
| * @run testng DefaultProxySelectorTest | ||
| * @run junit DefaultProxySelectorTest | ||
| * @modules java.base/sun.net.spi:+open | ||
| */ | ||
| public class DefaultProxySelectorTest { | ||
|
|
@@ -46,7 +47,7 @@ public void testIllegalArgForNull() { | |
| final ProxySelector selector = new DefaultProxySelector(); | ||
| try { | ||
| selector.select(null); | ||
| Assert.fail("select() was expected to fail for null URI"); | ||
| fail("select() was expected to fail for null URI"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could simplify and use |
||
| } catch (IllegalArgumentException iae) { | ||
| // expected | ||
| } | ||
|
|
@@ -82,7 +83,7 @@ public void testIllegalArgForNoScheme() throws Exception { | |
| private static void assertFailsWithIAE(final ProxySelector selector, final URI uri) { | ||
| try { | ||
| selector.select(uri); | ||
| Assert.fail("select() was expected to fail for URI " + uri); | ||
| fail("select() was expected to fail for URI " + uri); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Use assertThrows, even consider removind this method. |
||
| } catch (IllegalArgumentException iae) { | ||
| // expected | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
|
|
||
|
|
||
| /* | ||
| * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2022, 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 | ||
|
|
@@ -28,7 +28,7 @@ | |
| * @library /test/lib | ||
| * @summary Sanity check that HttpHeaderParser works same as MessageHeader | ||
| * @modules java.base/sun.net.www java.base/sun.net.www.protocol.http:open | ||
| * @run testng/othervm HttpHeaderParserTest | ||
| * @run junit/othervm HttpHeaderParserTest | ||
| */ | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
|
|
@@ -45,16 +45,17 @@ | |
| import static java.lang.String.format; | ||
| import static java.nio.charset.StandardCharsets.ISO_8859_1; | ||
| import static java.nio.charset.StandardCharsets.US_ASCII; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import jdk.test.lib.net.HttpHeaderParser; | ||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertTrue; | ||
| import org.testng.annotations.DataProvider; | ||
| import org.testng.annotations.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import sun.net.www.MessageHeader; | ||
|
|
||
| public class HttpHeaderParserTest { | ||
| @DataProvider(name = "responses") | ||
| public Object[][] responses() { | ||
| public static Object[][] responses() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider simplifying the method to use |
||
| List<String> responses = new ArrayList<>(); | ||
|
|
||
| String[] basic = | ||
|
|
@@ -318,8 +319,8 @@ static final String mixedCRLF(String headers) { | |
| return res.toString(); | ||
| } | ||
|
|
||
|
|
||
| @Test(dataProvider = "responses") | ||
| @ParameterizedTest | ||
| @MethodSource("responses") | ||
| public void verifyHeaders(String respString) throws Exception { | ||
| System.out.println("\ntesting:\n\t" + respString | ||
| .replace("\r\n", "<CRLF>") | ||
|
|
@@ -366,8 +367,7 @@ public void verifyHeaders(String respString) throws Exception { | |
| availableBytes, headerStream.available())); | ||
| } | ||
|
|
||
| @DataProvider(name = "errors") | ||
| public Object[][] errors() { | ||
| public static Object[][] errors() { | ||
|
mahendrachhipa marked this conversation as resolved.
Outdated
|
||
| List<String> responses = new ArrayList<>(); | ||
|
|
||
| // These responses are parsed, somewhat, by MessageHeaders but give | ||
|
|
@@ -441,16 +441,16 @@ public Object[][] errors() { | |
|
|
||
| }; | ||
| Arrays.stream(bad).forEach(responses::add); | ||
|
|
||
| return responses.stream().map(p -> new Object[] { p }).toArray(Object[][]::new); | ||
| } | ||
|
|
||
| @Test(dataProvider = "errors", expectedExceptions = IOException.class) | ||
| @ParameterizedTest | ||
| @MethodSource("errors") | ||
| public void errors(String respString) throws IOException { | ||
| byte[] bytes = respString.getBytes(US_ASCII); | ||
| HttpHeaderParser decoder = new HttpHeaderParser(); | ||
| ByteArrayInputStream bais = new ByteArrayInputStream(bytes); | ||
| decoder.parse(bais); | ||
| assertThrows(IOException.class, () -> decoder.parse(bais)); | ||
| } | ||
|
|
||
| void assertHeadersEqual(Map<String,List<String>> expected, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.