8266250: WebSocketTest and WebSocketProxyTest call assertEquals(List<byte[]>, List<byte[]>)

Reviewed-by: prappo
This commit is contained in:
Daniel Fuchs 2021-04-29 16:15:06 +00:00
parent 5f15666092
commit 01415f33e3
2 changed files with 66 additions and 4 deletions
test/jdk/java/net/httpclient/websocket

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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
@ -49,7 +49,9 @@ import java.net.http.WebSocketHandshakeException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HexFormat;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
@ -148,6 +150,35 @@ public class WebSocketProxyTest {
};
}
record bytes(byte[] bytes) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof bytes other) {
return Arrays.equals(bytes(), other.bytes());
}
return false;
}
@Override
public int hashCode() { return Arrays.hashCode(bytes()); }
public String toString() {
return "0x" + HexFormat.of()
.withUpperCase()
.formatHex(bytes());
}
}
static List<bytes> ofBytes(List<byte[]> bytes) {
return bytes.stream().map(bytes::new).toList();
}
static String diagnose(List<byte[]> a, List<byte[]> b) {
var actual = ofBytes(a);
var expected = ofBytes(b);
var message = actual.equals(expected) ? "match" : "differ";
return "%s and %s %s".formatted(actual, expected, message);
}
@Test(dataProvider = "servers")
public void simpleAggregatingBinaryMessages
(Function<int[],DummySecureWebSocketServer> serverSupplier,
@ -236,7 +267,7 @@ public class WebSocketProxyTest {
.join();
List<byte[]> a = actual.join();
assertEquals(a, expected);
assertEquals(ofBytes(a), ofBytes(expected), diagnose(a, expected));
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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
@ -41,7 +41,9 @@ import java.net.http.WebSocketHandshakeException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HexFormat;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
@ -432,6 +434,35 @@ public class WebSocketTest {
};
}
record bytes(byte[] bytes) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof bytes other) {
return Arrays.equals(bytes(), other.bytes());
}
return false;
}
@Override
public int hashCode() { return Arrays.hashCode(bytes()); }
public String toString() {
return "0x" + HexFormat.of()
.withUpperCase()
.formatHex(bytes());
}
}
static List<bytes> ofBytes(List<byte[]> bytes) {
return bytes.stream().map(bytes::new).toList();
}
static String diagnose(List<byte[]> a, List<byte[]> b) {
var actual = ofBytes(a);
var expected = ofBytes(b);
var message = actual.equals(expected) ? "match" : "differ";
return "%s and %s %s".formatted(actual, expected, message);
}
@Test(dataProvider = "servers")
public void simpleAggregatingBinaryMessages
(Function<int[],DummyWebSocketServer> serverSupplier)
@ -525,7 +556,7 @@ public class WebSocketTest {
.join();
try {
List<byte[]> a = actual.join();
assertEquals(a, expected);
assertEquals(ofBytes(a), ofBytes(expected), diagnose(a, expected));
} finally {
webSocket.abort();
}