Skip to content

Commit dc3c4aa

Browse files
strangelookingnerdok2c
authored andcommitted
Fix assertions
* wrong argument order * bad choice of assertion method
1 parent 5c79a0e commit dc3c4aa

24 files changed

+89
-84
lines changed

httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void testPlainStringDecodingRemainingContent() throws Exception {
154154

155155
final ByteArrayBuffer buffer = new ByteArrayBuffer(16);
156156
HPackDecoder.decodePlainString(buffer, src);
157-
Assertions.assertEquals(new String(buffer.array(), 0, buffer.length(), StandardCharsets.US_ASCII), "custom-key");
157+
Assertions.assertEquals("custom-key", new String(buffer.array(), 0, buffer.length(), StandardCharsets.US_ASCII));
158158
Assertions.assertEquals(4, src.remaining());
159159
}
160160

@@ -188,7 +188,8 @@ void testHuffmanDecodingRFC7541Examples() throws Exception {
188188

189189
final ByteArrayBuffer buffer = new ByteArrayBuffer(16);
190190
HPackDecoder.decodeHuffman(buffer, src);
191-
Assertions.assertEquals(new String(buffer.array(), 0, buffer.length(), StandardCharsets.US_ASCII), "www.example.com");
191+
Assertions.assertEquals("www.example.com",
192+
new String(buffer.array(), 0, buffer.length(), StandardCharsets.US_ASCII));
192193
Assertions.assertFalse(src.hasRemaining(), "Decoding completed");
193194
}
194195

@@ -240,7 +241,7 @@ void testEnsureCapacity() throws Exception {
240241
decoder.decodeString(wrap(buffer), strBuf);
241242
strBuf.delete(0,strBuf.length());
242243
}
243-
Assertions.assertEquals(decoder.getTmpBufSize(), 256);
244+
Assertions.assertEquals(256, decoder.getTmpBufSize());
244245
}
245246

246247
static final int SWISS_GERMAN_HELLO[] = {

httpcore5-reactive/src/test/java/org/apache/hc/core5/reactive/TestReactiveDataConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void testFullResponseBuffering() throws Exception {
177177
consumer.consume(data.duplicate());
178178
consumer.streamEnd(null);
179179

180-
Assertions.assertEquals(Flowable.fromPublisher(consumer).count().blockingGet().longValue(), 3L);
180+
Assertions.assertEquals(3L, Flowable.fromPublisher(consumer).count().blockingGet().longValue());
181181
}
182182

183183
@Test

httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientTestingAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void withLiveServerCustomRequestHandler() throws Exception {
217217
public void handle(final ClassicHttpRequest request, final ClassicHttpResponse response, final HttpContext context)
218218
throws HttpException, IOException {
219219
try {
220-
Assertions.assertEquals("method not expected", "junk", request.getMethod());
220+
Assertions.assertEquals("junk", request.getMethod(), "method not expected");
221221
} catch (final Throwable t) {
222222
thrown = t;
223223
}

httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestFrameworkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void defaults() throws Exception {
5050
final Map<String, Object> request = test.initRequest();
5151

5252
Assertions.assertNotNull(request, "request should not be null");
53-
Assertions.assertEquals(request.get(METHOD), "GET", "Default method should be GET");
53+
Assertions.assertEquals("GET", request.get(METHOD), "Default method should be GET");
5454

5555
Assertions.assertEquals(TestingFramework.DEFAULT_REQUEST_BODY,
5656
request.get(BODY), "Default request body expected.");

httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpExceptions.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ class TestHttpExceptions {
4242
@Test
4343
void testConstructor() {
4444
final Throwable cause = new Exception();
45-
new HttpException();
46-
new HttpException("Oppsie");
47-
new HttpException("Oppsie", cause);
48-
new ProtocolException();
49-
new ProtocolException("Oppsie");
50-
new ProtocolException("Oppsie", cause);
51-
new NoHttpResponseException("Oppsie");
52-
new ConnectionClosedException("Oppsie");
53-
new MethodNotSupportedException("Oppsie");
54-
new MethodNotSupportedException("Oppsie", cause);
55-
new UnsupportedHttpVersionException();
56-
new UnsupportedHttpVersionException("Oppsie");
45+
Assertions.assertDoesNotThrow(() -> new HttpException());
46+
Assertions.assertDoesNotThrow(() -> new HttpException("Oppsie"));
47+
Assertions.assertDoesNotThrow(() -> new HttpException("Oppsie", cause));
48+
Assertions.assertDoesNotThrow(() -> new ProtocolException());
49+
Assertions.assertDoesNotThrow(() -> new ProtocolException("Oppsie"));
50+
Assertions.assertDoesNotThrow(() -> new ProtocolException("Oppsie", cause));
51+
Assertions.assertDoesNotThrow(() -> new NoHttpResponseException("Oppsie"));
52+
Assertions.assertDoesNotThrow(() -> new ConnectionClosedException("Oppsie"));
53+
Assertions.assertDoesNotThrow(() -> new MethodNotSupportedException("Oppsie"));
54+
Assertions.assertDoesNotThrow(() -> new MethodNotSupportedException("Oppsie", cause));
55+
Assertions.assertDoesNotThrow(() -> new UnsupportedHttpVersionException());
56+
Assertions.assertDoesNotThrow(() -> new UnsupportedHttpVersionException("Oppsie"));
5757
}
5858

5959
@Test

httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ void testHashCode() throws Exception {
9090
"http", InetAddress.getByAddress("someotherhost",new byte[] {127,0,0,1}), 80);
9191

9292
Assertions.assertEquals(host1.hashCode(), host1.hashCode());
93-
Assertions.assertTrue(host1.hashCode() != host2.hashCode());
94-
Assertions.assertTrue(host1.hashCode() != host3.hashCode());
93+
Assertions.assertNotEquals(host1.hashCode(), host2.hashCode());
94+
Assertions.assertNotEquals(host1.hashCode(), host3.hashCode());
9595
Assertions.assertEquals(host2.hashCode(), host4.hashCode());
9696
Assertions.assertEquals(host2.hashCode(), host5.hashCode());
97-
Assertions.assertTrue(host5.hashCode() != host6.hashCode());
98-
Assertions.assertTrue(host7.hashCode() != host8.hashCode());
99-
Assertions.assertTrue(host8.hashCode() != host9.hashCode());
97+
Assertions.assertNotEquals(host5.hashCode(), host6.hashCode());
98+
Assertions.assertNotEquals(host7.hashCode(), host8.hashCode());
99+
Assertions.assertNotEquals(host8.hashCode(), host9.hashCode());
100100
Assertions.assertEquals(host9.hashCode(), host10.hashCode());
101-
Assertions.assertTrue(host10.hashCode() != host11.hashCode());
102-
Assertions.assertTrue(host9.hashCode() != host11.hashCode());
101+
Assertions.assertNotEquals(host10.hashCode(), host11.hashCode());
102+
Assertions.assertNotEquals(host9.hashCode(), host11.hashCode());
103103
}
104104

105105
@Test
@@ -127,7 +127,7 @@ void testEquals() throws Exception {
127127
Assertions.assertEquals(host2, host5);
128128
Assertions.assertNotEquals(host5, host6);
129129
Assertions.assertNotEquals(host7, host8);
130-
Assertions.assertFalse(host7.equals(host9));
130+
Assertions.assertNotEquals(host7, host9);
131131
Assertions.assertNotEquals(null, host1);
132132
Assertions.assertNotEquals("http://somehost", host1);
133133
Assertions.assertNotEquals("http://somehost", host9);

httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpVersion.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ void testHttpVersionEquality() {
8686
Assertions.assertEquals(ver1, ver1);
8787
Assertions.assertEquals(ver1, ver2);
8888

89-
Assertions.assertFalse(ver1.equals(Float.valueOf(1.1f)));
89+
Assertions.assertNotEquals(ver1, Float.valueOf(1.1f));
9090

91-
Assertions.assertEquals((new HttpVersion(0, 9)), HttpVersion.HTTP_0_9);
92-
Assertions.assertEquals((new HttpVersion(1, 0)), HttpVersion.HTTP_1_0);
93-
Assertions.assertEquals((new HttpVersion(1, 1)), HttpVersion.HTTP_1_1);
94-
Assertions.assertNotEquals((new HttpVersion(1, 1)), HttpVersion.HTTP_1_0);
91+
Assertions.assertEquals(HttpVersion.HTTP_0_9, (new HttpVersion(0, 9)));
92+
Assertions.assertEquals(HttpVersion.HTTP_1_0, (new HttpVersion(1, 0)));
93+
Assertions.assertEquals(HttpVersion.HTTP_1_1, (new HttpVersion(1, 1)));
94+
Assertions.assertNotEquals(HttpVersion.HTTP_1_0, (new HttpVersion(1, 1)));
9595

96-
Assertions.assertEquals((new ProtocolVersion("HTTP", 0, 9)), HttpVersion.HTTP_0_9);
97-
Assertions.assertEquals((new ProtocolVersion("HTTP", 1, 0)), HttpVersion.HTTP_1_0);
98-
Assertions.assertEquals((new ProtocolVersion("HTTP", 1, 1)), HttpVersion.HTTP_1_1);
99-
Assertions.assertNotEquals((new ProtocolVersion("http", 1, 1)), HttpVersion.HTTP_1_1);
96+
Assertions.assertEquals(HttpVersion.HTTP_0_9, (new ProtocolVersion("HTTP", 0, 9)));
97+
Assertions.assertEquals(HttpVersion.HTTP_1_0, (new ProtocolVersion("HTTP", 1, 0)));
98+
Assertions.assertEquals(HttpVersion.HTTP_1_1, (new ProtocolVersion("HTTP", 1, 1)));
99+
Assertions.assertNotEquals(HttpVersion.HTTP_1_1, (new ProtocolVersion("http", 1, 1)));
100100

101101
Assertions.assertEquals(HttpVersion.HTTP_0_9, new ProtocolVersion("HTTP", 0, 9));
102102
Assertions.assertEquals(HttpVersion.HTTP_1_0, new ProtocolVersion("HTTP", 1, 0));

httpcore5/src/test/java/org/apache/hc/core5/http/impl/IncomingEntityDetailsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void getContentLengthEmpty() {
5656
() -> assertEquals(-1, incomingEntityDetails.getContentLength()),
5757
() -> assertNull(incomingEntityDetails.getContentType()),
5858
() -> assertNull(incomingEntityDetails.getContentEncoding()),
59-
() -> assertEquals(incomingEntityDetails.getTrailerNames().size(), 0)
59+
() -> assertEquals(0, incomingEntityDetails.getTrailerNames().size())
6060
);
6161
}
6262

httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestChunkCoding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void testChunkedInputStreamLargeBuffer() throws IOException {
7070
in.close();
7171

7272
final String result = new String(out.toByteArray(), StandardCharsets.US_ASCII);
73-
Assertions.assertEquals(result, CHUNKED_RESULT);
73+
Assertions.assertEquals(CHUNKED_RESULT, result);
7474

7575
final Header[] footers = in.getFooters();
7676
Assertions.assertNotNull(footers);

httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestContentLengthInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void testBasics() throws IOException {
5656
outputStream.write(buffer, 0, len);
5757

5858
final String result = new String(outputStream.toByteArray(), StandardCharsets.US_ASCII);
59-
Assertions.assertEquals(result, "1234567890");
59+
Assertions.assertEquals("1234567890", result);
6060
in.close();
6161
}
6262

0 commit comments

Comments
 (0)