|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
49 | 49 | import java.nio.ByteBuffer;
|
50 | 50 | import java.nio.charset.StandardCharsets;
|
51 | 51 | import java.util.ArrayList;
|
| 52 | +import java.util.Arrays; |
52 | 53 | import java.util.Base64;
|
| 54 | +import java.util.HexFormat; |
53 | 55 | import java.util.List;
|
54 | 56 | import java.util.concurrent.CompletableFuture;
|
55 | 57 | import java.util.concurrent.CompletionException;
|
@@ -148,6 +150,35 @@ public Object[][] servers() {
|
148 | 150 | };
|
149 | 151 | }
|
150 | 152 |
|
| 153 | + record bytes(byte[] bytes) { |
| 154 | + @Override |
| 155 | + public boolean equals(Object o) { |
| 156 | + if (this == o) return true; |
| 157 | + if (o instanceof bytes other) { |
| 158 | + return Arrays.equals(bytes(), other.bytes()); |
| 159 | + } |
| 160 | + return false; |
| 161 | + } |
| 162 | + @Override |
| 163 | + public int hashCode() { return Arrays.hashCode(bytes()); } |
| 164 | + public String toString() { |
| 165 | + return "0x" + HexFormat.of() |
| 166 | + .withUpperCase() |
| 167 | + .formatHex(bytes()); |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + static List<bytes> ofBytes(List<byte[]> bytes) { |
| 172 | + return bytes.stream().map(bytes::new).toList(); |
| 173 | + } |
| 174 | + |
| 175 | + static String diagnose(List<byte[]> a, List<byte[]> b) { |
| 176 | + var actual = ofBytes(a); |
| 177 | + var expected = ofBytes(b); |
| 178 | + var message = actual.equals(expected) ? "match" : "differ"; |
| 179 | + return "%s and %s %s".formatted(actual, expected, message); |
| 180 | + } |
| 181 | + |
151 | 182 | @Test(dataProvider = "servers")
|
152 | 183 | public void simpleAggregatingBinaryMessages
|
153 | 184 | (Function<int[],DummySecureWebSocketServer> serverSupplier,
|
@@ -236,7 +267,7 @@ public void onError(WebSocket webSocket, Throwable error) {
|
236 | 267 | .join();
|
237 | 268 |
|
238 | 269 | List<byte[]> a = actual.join();
|
239 |
| - assertEquals(a, expected); |
| 270 | + assertEquals(ofBytes(a), ofBytes(expected), diagnose(a, expected)); |
240 | 271 | }
|
241 | 272 | }
|
242 | 273 |
|
|
0 commit comments