Skip to content
Permalink
Browse files
8266250: WebSocketTest and WebSocketProxyTest call assertEquals(List<…
…byte[]>, List<byte[]>)

Reviewed-by: prappo
  • Loading branch information
dfuch committed Apr 29, 2021
1 parent 5f15666 commit 01415f33e34621294832c165f21b112ed1c54103
Showing with 66 additions and 4 deletions.
  1. +33 −2 test/jdk/java/net/httpclient/websocket/WebSocketProxyTest.java
  2. +33 −2 test/jdk/java/net/httpclient/websocket/WebSocketTest.java
@@ -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.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 @@ protected PasswordAuthentication getPasswordAuthentication() {
};
}

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 void onError(WebSocket webSocket, Throwable error) {
.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.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 @@ protected PasswordAuthentication getPasswordAuthentication() {
};
}

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 void onError(WebSocket webSocket, Throwable error) {
.join();
try {
List<byte[]> a = actual.join();
assertEquals(a, expected);
assertEquals(ofBytes(a), ofBytes(expected), diagnose(a, expected));
} finally {
webSocket.abort();
}

1 comment on commit 01415f3

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 01415f3 Apr 29, 2021

Please sign in to comment.