Skip to content

Commit

Permalink
8339515: [TestBug] Convert web tests to JUnit 5
Browse files Browse the repository at this point in the history
Reviewed-by: mhanl, arapte
  • Loading branch information
Jay Bhaskar committed Sep 19, 2024
1 parent 6d1dd29 commit e81b676
Show file tree
Hide file tree
Showing 46 changed files with 1,032 additions and 1,057 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@Ignore("JDK-8290292")
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@Disabled("JDK-8290292")
public class SharedBufferTest {

private static final int SEGMENT_SIZE = 0x1000;
Expand All @@ -52,7 +52,7 @@ public class SharedBufferTest {
private SharedBuffer sb = SharedBufferShim.createSharedBuffer();


@BeforeClass
@BeforeAll
public static void beforeClass() throws ClassNotFoundException {
if (PlatformUtil.isWindows()) {
// Must load Microsoft libs before loading jfxwebkit.dll
Expand Down Expand Up @@ -458,7 +458,7 @@ public void testDisposeZeroNativePointer() {
}


@After
@AfterEach
public void after() {
if (sb != null) {
SharedBufferShim.dispose(sb);
Expand All @@ -484,7 +484,7 @@ private byte[] getSomeData(double position, int length) {
int extraLength = random.nextBoolean() ? random.nextInt(200) : 0;
byte[] buffer = g(0, offset + length + extraLength);
int len = SharedBufferShim.getSomeData(sb, (long) position, buffer, offset, length);
assertTrue("Unexpected len: " + len, len >= 0);
assertTrue(len >= 0, "Unexpected len: " + len);
for (int i = 0; i < offset; i++) {
assertEquals((byte) (i & 0xff), buffer[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
import com.sun.webkit.WebPage;
import java.io.IOException;
import java.util.Random;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@Ignore("JDK-8290292")
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@Disabled("JDK-8290292")
public class SimpleSharedBufferInputStreamTest {

private static final int SEGMENT_SIZE = 0x1000;
Expand All @@ -54,7 +54,7 @@ public class SimpleSharedBufferInputStreamTest {
new SimpleSharedBufferInputStream(sb);


@BeforeClass
@BeforeAll
public static void beforeClass() throws ClassNotFoundException {
if (PlatformUtil.isWindows()) {
// Must load Microsoft libs before loading jfxwebkit.dll
Expand Down Expand Up @@ -560,7 +560,7 @@ public void testMarkSupported() {
}


@After
@AfterEach
public void after() {
SharedBufferShim.dispose(sb);
}
Expand Down Expand Up @@ -597,15 +597,15 @@ private byte[] read(int length) {
byte[] buffer = g(0, offset + length + extraLength);
int len = is.read(buffer, offset, length);
if (length == 0) {
assertEquals("Unexpected len", 0, len);
assertEquals(0, len, "Unexpected len");
}
if (len == -1) {
for (int i = 0; i < buffer.length; i++) {
assertEquals((byte) (i & 0xff), buffer[i]);
}
return null;
}
assertTrue("Unexpected len: " + len, len >= 0);
assertTrue(len >= 0, "Unexpected len: " + len);
for (int i = 0; i < offset; i++) {
assertEquals((byte) (i & 0xff), buffer[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
* A test for the {@link CookieManager} class.
Expand Down Expand Up @@ -67,8 +67,7 @@ public void testGetMultipleCookies() {
"foo=bar",
"baz=qux; Domain=example.org",
"quux=corge; Path=/grault");
assertEquals("quux=corge; foo=bar; baz=qux",
get("http://example.org/grault"));
assertEquals("quux=corge; foo=bar; baz=qux", get("http://example.org/grault"));
}

/**
Expand Down Expand Up @@ -128,10 +127,8 @@ public void testGetHostCaseInsensitiveness() {
"foo=bar",
"baz=qux; Domain=example.org",
"quux=corge; Path=/grault");
assertEquals("quux=corge; foo=bar; baz=qux",
get("http://Example.org/grault"));
assertEquals("quux=corge; foo=bar; baz=qux",
get("http://EXAMPLE.ORG/grault"));
assertEquals("quux=corge; foo=bar; baz=qux", get("http://Example.org/grault"));
assertEquals("quux=corge; foo=bar; baz=qux", get("http://EXAMPLE.ORG/grault"));
}

/**
Expand All @@ -144,18 +141,12 @@ public void testGetPathMismatch() {
"baz=qux; Path=/",
"quux=courge; Path=/lvl1",
"grault=garply; Path=/lvl1/lvl2");
assertEquals("grault=garply; quux=courge; foo=bar; baz=qux",
get("http://example.org/lvl1/lvl2/lvl3/lvl4"));
assertEquals("grault=garply; quux=courge; foo=bar; baz=qux",
get("http://example.org/lvl1/lvl2/lvl3"));
assertEquals("grault=garply; quux=courge; foo=bar; baz=qux",
get("http://example.org/lvl1/lvl2"));
assertEquals("quux=courge; foo=bar; baz=qux",
get("http://example.org/lvl1/lvl2A"));
assertEquals("quux=courge; foo=bar; baz=qux",
get("http://example.org/lvl1/lvlA"));
assertEquals("quux=courge; foo=bar; baz=qux",
get("http://example.org/lvl1"));
assertEquals("grault=garply; quux=courge; foo=bar; baz=qux", get("http://example.org/lvl1/lvl2/lvl3/lvl4"));
assertEquals("grault=garply; quux=courge; foo=bar; baz=qux", get("http://example.org/lvl1/lvl2/lvl3"));
assertEquals("grault=garply; quux=courge; foo=bar; baz=qux", get("http://example.org/lvl1/lvl2"));
assertEquals("quux=courge; foo=bar; baz=qux", get("http://example.org/lvl1/lvl2A"));
assertEquals("quux=courge; foo=bar; baz=qux", get("http://example.org/lvl1/lvlA"));
assertEquals("quux=courge; foo=bar; baz=qux", get("http://example.org/lvl1"));
assertEquals("foo=bar; baz=qux", get("http://example.org/lvl1A"));
assertEquals("foo=bar; baz=qux", get("http://example.org/lvlA"));
assertEquals("foo=bar; baz=qux", get("http://example.org/"));
Expand All @@ -173,8 +164,7 @@ public void testGetSecureOnlyAndHttpOnly() {
"quux=courge; HttpOnly",
"grault=garply; Secure; HttpOnly");
assertEquals("foo=bar; quux=courge", get("http://example.org/"));
assertEquals("foo=bar; baz=qux; quux=courge; grault=garply",
get("https://example.org/"));
assertEquals("foo=bar; baz=qux; quux=courge; grault=garply", get("https://example.org/"));
assertEquals("foo=bar", get("javascript://example.org/"));
assertEquals("foo=bar; baz=qux", get("javascripts://example.org/"));
}
Expand All @@ -188,8 +178,7 @@ public void testPathSorting() {
"foo=bar",
"baz=qux; Path=/lvl1",
"quux=courge; Path=/lvl1/lvl2");
assertEquals("quux=courge; baz=qux; foo=bar",
get("http://example.org/lvl1/lvl2"));
assertEquals("quux=courge; baz=qux; foo=bar", get("http://example.org/lvl1/lvl2"));
}

/**
Expand All @@ -198,15 +187,13 @@ public void testPathSorting() {
@Test
public void testCreationTimeSorting() {
put("http://example.org/", "foo=bar", "baz=qux", "quux=courge");
assertEquals("foo=bar; baz=qux; quux=courge",
get("http://example.org/"));
assertEquals("foo=bar; baz=qux; quux=courge", get("http://example.org/"));

sleep(10);

put("http://example.org/", "foo=discard; Max-Age=0");
put("http://example.org/", "foo=bar");
assertEquals("baz=qux; quux=courge; foo=bar",
get("http://example.org/"));
assertEquals("baz=qux; quux=courge; foo=bar", get("http://example.org/"));
}

/**
Expand All @@ -219,8 +206,7 @@ public void testPathAndCreationTimeSorting() {
"baz=qux; Path=/lvl1",
"quux=courge",
"grault=garply; Path=/lvl1/lvl2");
assertEquals("grault=garply; baz=qux; foo=bar; quux=courge",
get("http://example.org/lvl1/lvl2"));
assertEquals("grault=garply; baz=qux; foo=bar; quux=courge", get("http://example.org/lvl1/lvl2"));
}

/**
Expand Down Expand Up @@ -267,15 +253,13 @@ public void testPutHostCaseInsensitiveness() {
"foo=bar",
"baz=qux; Domain=example.org",
"quux=corge; Path=/grault");
assertEquals("quux=corge; foo=bar; baz=qux",
get("http://example.org/grault"));
assertEquals("quux=corge; foo=bar; baz=qux", get("http://example.org/grault"));

put("http://EXAMPLE.ORG/",
"foo=bar2",
"baz=qux2; Domain=example.org",
"quux=corge2; Path=/grault");
assertEquals("quux=corge2; foo=bar2; baz=qux2",
get("http://example.org/grault"));
assertEquals("quux=corge2; foo=bar2; baz=qux2", get("http://example.org/grault"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import com.sun.webkit.network.ExtendedTimeShim;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static java.lang.System.currentTimeMillis;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* A test for the {@link Cookie} class.
Expand Down Expand Up @@ -443,33 +443,25 @@ public CookieModel(String name, String value) {
}

private static void assertAsExpected(String testString,
CookieModel expected, CookieShim actual)
CookieModel expected, CookieShim actual)
{
String s = ", test string: [" + testString + "],";
if (expected == null) {
assertEquals("Unexpected cookie" + s, expected, actual);
assertEquals(expected, actual,"Unexpected cookie" + s);
return;
}

assertEquals("Unexpected name" + s, expected.name, actual.getName());
assertEquals("Unexpected value" + s, expected.value, actual.getValue());
assertEquals("Unexpected expiryTime" + s,
expected.expiryTime, actual.getExpiryTime());
assertEquals("Unexpected domain" + s,
expected.domain, actual.getDomain());
assertEquals("Unexpected path" + s, expected.path, actual.getPath());
assertTrue("Unexpected creationTime" + s,
expected.creationTime.equals(actual.getCreationTime()));
assertEquals("Unexpected lastAccessTime" + s,
expected.creationTime.baseTime(), actual.getLastAccessTime());
assertEquals("Unexpected persistent flag" + s,
expected.persistent, actual.getPersistent());
assertEquals("Unexpected hostOnly flag" + s,
false, actual.getHostOnly());
assertEquals("Unexpected secureOnly flag" + s,
expected.secureOnly, actual.getSecureOnly());
assertEquals("Unexpected httpOnly flag" + s,
expected.httpOnly, actual.getHttpOnly());
assertEquals(expected.name, actual.getName(), "Unexpected name" + s);
assertEquals(expected.value, actual.getValue(), "Unexpected value" + s);
assertEquals(expected.expiryTime, actual.getExpiryTime(), "Unexpected expiryTime" + s);
assertEquals(expected.domain, actual.getDomain(), "Unexpected domain" + s);
assertEquals(expected.path, actual.getPath(), "Unexpected path" + s);
assertTrue(expected.creationTime.equals(actual.getCreationTime()), "Unexpected creationTime" + s);
assertEquals(expected.creationTime.baseTime(), actual.getLastAccessTime(), "Unexpected lastAccessTime" + s);
assertEquals(expected.persistent, actual.getPersistent(), "Unexpected persistent flag" + s);
assertEquals(false, actual.getHostOnly(), "Unexpected hostOnly flag" + s);
assertEquals(expected.secureOnly, actual.getSecureOnly(), "Unexpected secureOnly flag" + s);
assertEquals(expected.httpOnly, actual.getHttpOnly(), "Unexpected httpOnly flag" + s);
}

/**
Expand Down Expand Up @@ -583,14 +575,10 @@ public void testDomainMatches() {
*/
@Test
public void testDefaultPath() {
assertEquals("/foo",
CookieShim.defaultPath(uri("http://hostname/foo/bar")));
assertEquals("/foo",
CookieShim.defaultPath(uri("http://hostname/foo/bar?")));
assertEquals("/foo",
CookieShim.defaultPath(uri("http://hostname/foo/bar?query")));
assertEquals("/foo",
CookieShim.defaultPath(uri("http://hostname/foo/bar?query=push")));
assertEquals("/foo", CookieShim.defaultPath(uri("http://hostname/foo/bar")));
assertEquals("/foo", CookieShim.defaultPath(uri("http://hostname/foo/bar?")));
assertEquals("/foo", CookieShim.defaultPath(uri("http://hostname/foo/bar?query")));
assertEquals("/foo", CookieShim.defaultPath(uri("http://hostname/foo/bar?query=push")));

assertEquals("/", CookieShim.defaultPath(uri("http://hostname")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
* A test for the {@link DateParser} class.
Expand Down Expand Up @@ -299,8 +299,9 @@ public void testDelimiters() {
private static void test(String dateString, String expectedResult) {
try {
long actualResult = DateParserShim.parse(dateString);
assertEquals("Unexpected result, date string: [" + dateString
+ "],", expectedResult, DF.format(new Date(actualResult)));
assertEquals(expectedResult, DF.format(new Date(actualResult)),
"Unexpected result, date string: [" + dateString
+ "],");
} catch (ParseException ex) {
throw new AssertionError(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
package test.com.sun.webkit.network;

import com.sun.webkit.network.PublicSuffixesShim;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* A test for the {@link PublicSuffixes} class.
Expand Down Expand Up @@ -99,7 +99,7 @@ public void testIdnRule() {
* Tests a given domain.
*/
private static void test(String domain, boolean expectedResult) {
assertEquals("Unexpected result, domain: [" + domain + "],",
expectedResult, PublicSuffixesShim.isPublicSuffix(domain));
assertEquals(expectedResult, PublicSuffixesShim.isPublicSuffix(domain),
"Unexpected result, domain: [" + domain + "],");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

package test.com.sun.webkit.network;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import static com.sun.webkit.network.Util.adjustUrlForWebKit;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class UtilTest {

Expand Down
Loading

3 comments on commit e81b676

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@kevinrushforth
Copy link
Member

Choose a reason for hiding this comment

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

/skara tag 24+10

@openjdk
Copy link

@openjdk openjdk bot commented on e81b676 Sep 19, 2024

Choose a reason for hiding this comment

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

@kevinrushforth The tag 24+10 was successfully created.

Please sign in to comment.