From 01680e9cf4f50a5dae466b6e9ddf3088992448ea Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Tue, 3 Feb 2026 09:41:26 +0100 Subject: [PATCH] Replace Hamcrest assertions with JUnit assertions Drop Hamcrest deps and update test helpers --- httpcore5-h2/pom.xml | 5 - .../hc/core5/http2/hpack/TestHPackCoding.java | 6 +- httpcore5-testing/pom.xml | 5 - .../core5/benchmark/ResultFormatterTest.java | 8 +- .../classic/ClassicAuthenticationTest.java | 27 +- .../classic/ClassicHttpCoreTransportTest.java | 26 +- .../ClassicServerBootstrapFilterTest.java | 7 +- .../classic/ClassicTLSIntegrationTest.java | 11 +- .../classic/ClassicHttpCompatTest.java | 6 +- .../classic/HttpBinClassicCompatTest.java | 5 +- .../framework/TestTestingFramework.java | 25 +- .../apache/hc/core5/testing/nio/AlpnTest.java | 33 +- .../nio/AsyncServerBootstrapFilterTest.java | 9 +- .../hc/core5/testing/nio/H2AlpnTest.java | 9 +- .../nio/H2CoreTransportMultiplexingTest.java | 53 ++- .../core5/testing/nio/H2IntegrationTest.java | 6 +- .../nio/H2ServerBootstrapFiltersTest.java | 9 +- .../testing/nio/Http1AuthenticationTest.java | 39 +- .../testing/nio/Http1CoreTransportTest.java | 21 +- .../testing/nio/Http1IntegrationTest.java | 14 +- .../testing/nio/HttpCoreTransportTest.java | 75 ++-- .../testing/nio/HttpIntegrationTest.java | 10 +- .../core5/testing/nio/TLSIntegrationTest.java | 7 +- .../hc/core5/testing/nio/TLSUpgradeTest.java | 14 +- .../testing/reactive/ReactiveClientTest.java | 6 +- httpcore5/pom.xml | 5 - .../concurrent/TestComplexCancellable.java | 9 +- .../core5/concurrent/TestComplexFuture.java | 24 +- .../apache/hc/core5/http/HeaderMatcher.java | 38 +- .../apache/hc/core5/http/HeadersMatcher.java | 52 +-- .../core5/http/NameValuePairListMatcher.java | 61 +-- .../hc/core5/http/TestProtocolVersion.java | 18 +- .../core5/http/TestProtocolVersionParser.java | 4 +- .../http/config/TestNamedElementChain.java | 97 +++-- .../http/impl/nio/TestExpandableBuffer.java | 43 +- .../org/apache/hc/core5/http/ssl/TLSTest.java | 17 +- .../support/TestBasicMessageBuilders.java | 109 +++-- .../apache/hc/core5/net/TestPercentCodec.java | 24 +- .../apache/hc/core5/net/TestURIAuthority.java | 81 ++-- .../apache/hc/core5/net/TestURIBuilder.java | 390 +++++++++--------- .../apache/hc/core5/net/TestWWWFormCodec.java | 95 ++--- .../reactor/TestAbstractIOSessionPool.java | 72 ++-- .../apache/hc/core5/util/TestTimeValue.java | 40 +- pom.xml | 7 - 44 files changed, 697 insertions(+), 925 deletions(-) diff --git a/httpcore5-h2/pom.xml b/httpcore5-h2/pom.xml index f62cb25d1c..be13065bb8 100644 --- a/httpcore5-h2/pom.xml +++ b/httpcore5-h2/pom.xml @@ -53,11 +53,6 @@ junit-jupiter test - - org.hamcrest - hamcrest - test - org.mockito mockito-core diff --git a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java index b93ed6084a..fde738a9d4 100644 --- a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java +++ b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.http2.hpack; -import static org.hamcrest.MatcherAssert.assertThat; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -38,7 +37,6 @@ import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.message.BasicHeader; import org.apache.hc.core5.util.ByteArrayBuffer; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -1073,10 +1071,10 @@ void testHeaderSizeLimit() throws Exception { "123456789012345678901234567890123456789012345678901234567890")), false); - assertThat(decoder.decodeHeaders(wrap(buf)).size(), CoreMatchers.equalTo(2)); + Assertions.assertEquals(2, decoder.decodeHeaders(wrap(buf)).size()); decoder.setMaxListSize(1000000); - assertThat(decoder.decodeHeaders(wrap(buf)).size(), CoreMatchers.equalTo(2)); + Assertions.assertEquals(2, decoder.decodeHeaders(wrap(buf)).size()); decoder.setMaxListSize(200); Assertions.assertThrows(HeaderListConstraintException.class, () -> diff --git a/httpcore5-testing/pom.xml b/httpcore5-testing/pom.xml index 2aad7462e5..3841455784 100644 --- a/httpcore5-testing/pom.xml +++ b/httpcore5-testing/pom.xml @@ -95,11 +95,6 @@ junit-platform-launcher test - - org.hamcrest - hamcrest - test - org.mockito mockito-core diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/ResultFormatterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/ResultFormatterTest.java index e9a19add0c..ba36247820 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/ResultFormatterTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/ResultFormatterTest.java @@ -26,14 +26,13 @@ */ package org.apache.hc.core5.benchmark; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; import org.apache.hc.core5.http.HttpVersion; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; class ResultFormatterTest { @@ -57,8 +56,7 @@ void testBasics() throws Exception { 50000000); final ByteArrayOutputStream buf = new ByteArrayOutputStream(); ResultFormatter.print(new PrintStream(buf, true, StandardCharsets.US_ASCII.name()), results); - assertThat(new String(buf.toByteArray(), StandardCharsets.US_ASCII).replace("\r\n", "\n"), - CoreMatchers.equalTo( + Assertions.assertEquals( "Server Software:\t\tTestServer/1.1\n" + "Protocol version:\t\tHTTP/1.1\n" + "Server Hostname:\t\tlocalhost\n" + @@ -77,7 +75,7 @@ void testBasics() throws Exception { "Time per request:\t\t0.850 [ms] (mean)\n" + "Time per request:\t\t0.170 [ms] (mean, across all concurrent requests)\n" + "Transfer rate:\t\t\t17,997.02 [Kbytes/sec] received\n" - )); + , new String(buf.toByteArray(), StandardCharsets.US_ASCII).replace("\r\n", "\n")); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicAuthenticationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicAuthenticationTest.java index 881508d98d..0c9086f49b 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicAuthenticationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicAuthenticationTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.classic; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.nio.charset.StandardCharsets; import java.util.Random; @@ -61,7 +61,6 @@ import org.apache.hc.core5.testing.extension.classic.HttpRequesterResource; import org.apache.hc.core5.testing.extension.classic.HttpServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -135,16 +134,16 @@ void testGetRequestAuthentication() throws Exception { final HttpCoreContext context = HttpCoreContext.create(); final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.GET, "/stuff"); try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) { - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_UNAUTHORIZED)); + Assertions.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getCode()); final String body1 = EntityUtils.toString(response1.getEntity()); - assertThat(body1, CoreMatchers.equalTo("You shall not pass!!!")); + Assertions.assertEquals("You shall not pass!!!", body1); } final ClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.GET, "/stuff"); request2.setHeader(HttpHeaders.AUTHORIZATION, "let me pass"); try (final ClassicHttpResponse response2 = requester.execute(target, request2, TIMEOUT, context)) { - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body1 = EntityUtils.toString(response2.getEntity()); - assertThat(body1, CoreMatchers.equalTo("")); + Assertions.assertEquals("", body1); } } @@ -163,17 +162,17 @@ void testPostRequestAuthentication() throws Exception { final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/stuff"); request1.setEntity(new ByteArrayEntity(stuff, ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) { - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_UNAUTHORIZED)); + Assertions.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getCode()); final String body1 = EntityUtils.toString(response1.getEntity()); - assertThat(body1, CoreMatchers.equalTo("You shall not pass!!!")); + Assertions.assertEquals("You shall not pass!!!", body1); } final ClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.POST, "/stuff"); request2.setHeader(HttpHeaders.AUTHORIZATION, "let me pass"); request2.setEntity(new ByteArrayEntity(stuff, ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response2 = requester.execute(target, request2, TIMEOUT, context)) { - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body1 = EntityUtils.toString(response2.getEntity()); - assertThat(body1, CoreMatchers.equalTo(new String(stuff, StandardCharsets.US_ASCII))); + Assertions.assertEquals(new String(stuff, StandardCharsets.US_ASCII), body1); } } @@ -193,18 +192,18 @@ void testPostRequestAuthenticationNoExpectContinue() throws Exception { request1.setVersion(HttpVersion.HTTP_1_0); request1.setEntity(new ByteArrayEntity(stuff, ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) { - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_UNAUTHORIZED)); + Assertions.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getCode()); final String body1 = EntityUtils.toString(response1.getEntity()); - assertThat(body1, CoreMatchers.equalTo("You shall not pass!!!")); + Assertions.assertEquals("You shall not pass!!!", body1); } final ClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.POST, "/stuff"); request2.setHeader(HttpHeaders.AUTHORIZATION, "let me pass"); request2.setVersion(HttpVersion.HTTP_1_0); request2.setEntity(new ByteArrayEntity(stuff, ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response2 = requester.execute(target, request2, TIMEOUT, context)) { - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body1 = EntityUtils.toString(response2.getEntity()); - assertThat(body1, CoreMatchers.equalTo(new String(stuff, StandardCharsets.US_ASCII))); + Assertions.assertEquals(new String(stuff, StandardCharsets.US_ASCII), body1); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicHttpCoreTransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicHttpCoreTransportTest.java index 07800628fb..5327f9bd39 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicHttpCoreTransportTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicHttpCoreTransportTest.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.testing.classic; -import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.concurrent.CountDownLatch; @@ -51,7 +50,6 @@ import org.apache.hc.core5.http.message.BasicClassicHttpRequest; import org.apache.hc.core5.http.protocol.HttpCoreContext; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -79,23 +77,23 @@ void testSequentialRequests() throws Exception { final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/stuff"); request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) { - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = EntityUtils.toString(response1.getEntity()); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); } final ClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.POST, "/other-stuff"); request2.setEntity(new StringEntity("some other stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response2 = requester.execute(target, request2, TIMEOUT, context)) { - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = EntityUtils.toString(response2.getEntity()); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); } final ClassicHttpRequest request3 = new BasicClassicHttpRequest(Method.POST, "/more-stuff"); request3.setEntity(new StringEntity("some more stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response3 = requester.execute(target, request3, TIMEOUT, context)) { - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = EntityUtils.toString(response3.getEntity()); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } } @@ -109,23 +107,23 @@ void testSequentialRequestsNonPersistentConnection() throws Exception { final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/no-keep-alive/stuff"); request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) { - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = EntityUtils.toString(response1.getEntity()); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); } final ClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.POST, "/no-keep-alive/other-stuff"); request2.setEntity(new StringEntity("some other stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response2 = requester.execute(target, request2, TIMEOUT, context)) { - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = EntityUtils.toString(response2.getEntity()); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); } final ClassicHttpRequest request3 = new BasicClassicHttpRequest(Method.POST, "/no-keep-alive/more-stuff"); request3.setEntity(new StringEntity("some more stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response3 = requester.execute(target, request3, TIMEOUT, context)) { - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = EntityUtils.toString(response3.getEntity()); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerBootstrapFilterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerBootstrapFilterTest.java index 435df746b5..43b25648d5 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerBootstrapFilterTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerBootstrapFilterTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.classic; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import org.apache.hc.core5.http.ClassicHttpRequest; @@ -53,7 +53,6 @@ import org.apache.hc.core5.testing.extension.classic.HttpRequesterResource; import org.apache.hc.core5.testing.extension.classic.HttpServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -118,9 +117,9 @@ void testFilters() throws Exception { final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/filters"); request.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response = requester.execute(target, request, TIMEOUT, context)) { - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final Header testFilterHeader = response.getHeader("X-Test-Filter"); - assertThat(testFilterHeader, CoreMatchers.notNullValue()); + Assertions.assertNotNull(testFilterHeader); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java index 3ab087be5a..c63145a300 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.testing.classic; -import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.net.InetAddress; @@ -59,7 +58,6 @@ import org.apache.hc.core5.ssl.SSLContexts; import org.apache.hc.core5.testing.SSLTestContexts; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.AfterEachCallback; @@ -138,16 +136,15 @@ void testTLSSuccess() throws Exception { final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/stuff"); request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) { - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = EntityUtils.toString(response1.getEntity()); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); } final SSLSession sslSession = sslSessionRef.getAndSet(null); final ProtocolVersion tlsVersion = TLS.parse(sslSession.getProtocol()); - assertThat(tlsVersion.greaterEquals(TLS.V_1_2.getVersion()), CoreMatchers.equalTo(true)); - assertThat(sslSession.getPeerPrincipal().getName(), - CoreMatchers.equalTo("CN=localhost,OU=Apache HttpComponents,O=Apache Software Foundation")); + Assertions.assertTrue(tlsVersion.greaterEquals(TLS.V_1_2.getVersion())); + Assertions.assertEquals("CN=localhost,OU=Apache HttpComponents,O=Apache Software Foundation", sslSession.getPeerPrincipal().getName()); } @Test diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java index 87651a688e..31d49dd1f7 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.testing.compatibility.classic; -import static org.hamcrest.MatcherAssert.assertThat; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -51,7 +50,6 @@ import org.apache.hc.core5.testing.compatibility.TLSTestContexts; import org.apache.hc.core5.testing.extension.classic.HttpRequesterResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -94,9 +92,9 @@ void test_sequential_requests() throws Exception { .setHttpHost(target) .build(); requester.execute(target, request, TIMEOUT, context, response -> { - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final String body1 = EntityUtils.toString(response.getEntity()); - assertThat(body1, CoreMatchers.equalTo(ContainerImages.AAA)); + Assertions.assertEquals(ContainerImages.AAA, body1); return null; }); } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/HttpBinClassicCompatTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/HttpBinClassicCompatTest.java index bf447fd0ed..6388a3ef8b 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/HttpBinClassicCompatTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/HttpBinClassicCompatTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.compatibility.classic; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.util.Arrays; import java.util.List; import java.util.function.Consumer; @@ -45,7 +45,6 @@ import org.apache.hc.core5.http.protocol.HttpCoreContext; import org.apache.hc.core5.testing.extension.classic.HttpRequesterResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -112,7 +111,7 @@ void test_sequential_request_execution() throws Exception { for (final ClassicHttpRequest request : requestMessages) { final HttpCoreContext context = HttpCoreContext.create(); client.execute(target, request, TIMEOUT, context, response -> { - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); return null; }); } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java index a4d33cf473..ccf0f7ce94 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java @@ -37,7 +37,6 @@ import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.REQUEST; import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.RESPONSE; import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS; -import static org.hamcrest.MatcherAssert.assertThat; import java.util.HashMap; import java.util.HashSet; @@ -45,9 +44,6 @@ import java.util.Set; import org.apache.hc.core5.http.ContentType; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; @@ -157,7 +153,7 @@ public Map execute( final Map request, final TestingFrameworkRequestHandler requestHandler, final Map responseExpectations) throws TestingFrameworkException { - assertThat(defaultURI, matchesDefaultURI()); + assertMatchesDefaultURI(defaultURI); Assertions.assertNotNull(request, "request should not be null"); @@ -191,22 +187,9 @@ public Map execute( Mockito.verify(mockRequestHandler).assertNothingThrown(); } - private Matcher matchesDefaultURI() { - final Matcher matcher = new BaseMatcher() { - private final String regex = "http://localhost:\\d+/"; - - @Override - public boolean matches(final Object o) { - return ((String) o).matches(regex); - } - - @Override - public void describeTo(final Description description) { - description.appendText("matches regex=" + regex); - } - }; - - return matcher; + private void assertMatchesDefaultURI(final String defaultURI) { + final String regex = "http://localhost:\\d+/"; + Assertions.assertTrue(defaultURI.matches(regex), "Default URI should match regex=" + regex); } @Test diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java index 9b26e85099..0c918a04b0 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.concurrent.Future; @@ -65,7 +65,6 @@ import org.apache.hc.core5.testing.extension.nio.H2AsyncRequesterResource; import org.apache.hc.core5.testing.extension.nio.H2AsyncServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -143,10 +142,10 @@ void testForceHttp1() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); - assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_1_1)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); + Assertions.assertEquals(HttpVersion.HTTP_1_1, response1.getVersion()); } @Test @@ -168,10 +167,10 @@ void testForceHttp1GlobalPolicy() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); - assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_1_1)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); + Assertions.assertEquals(HttpVersion.HTTP_1_1, response1.getVersion()); } @Test @@ -191,10 +190,10 @@ void testForceHttp2() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); - assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_2)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); + Assertions.assertEquals(HttpVersion.HTTP_2, response1.getVersion()); } @Test @@ -216,10 +215,10 @@ void testForceHttp2GlobalPolicy() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); - assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_2)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); + Assertions.assertEquals(HttpVersion.HTTP_2, response1.getVersion()); } @Test @@ -239,10 +238,10 @@ void testNegotiateProtocol() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); - assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_2)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); + Assertions.assertEquals(HttpVersion.HTTP_2, response1.getVersion()); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java index e9aa29961a..f9701ea014 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -64,7 +64,6 @@ import org.apache.hc.core5.testing.extension.nio.HttpAsyncRequesterResource; import org.apache.hc.core5.testing.extension.nio.HttpAsyncServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -137,11 +136,11 @@ void testFilters() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message); final HttpResponse response = message.getHead(); - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final Header testFilterHeader = response.getHeader("X-Test-Filter"); - assertThat(testFilterHeader, CoreMatchers.notNullValue()); + Assertions.assertNotNull(testFilterHeader); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java index db4726ecc4..cd67c4008c 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java @@ -27,7 +27,7 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -64,7 +64,6 @@ import org.apache.hc.core5.testing.extension.nio.H2AsyncServerResource; import org.apache.hc.core5.testing.extension.nio.H2MultiplexingRequesterResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -138,11 +137,11 @@ void testALPN() throws Exception { } assertTrue(h2Allowed, "h2 negotiation was disabled, but h2 was negotiated"); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java index 6d742dce42..e59753ee00 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.LinkedList; @@ -69,7 +69,6 @@ import org.apache.hc.core5.testing.extension.nio.H2MultiplexingRequesterResource; import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -121,33 +120,33 @@ void testSequentialRequests() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); final Future> resultFuture2 = requester.execute( new BasicRequestProducer(Method.POST, target, "/other-stuff", new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); final Future> resultFuture3 = requester.execute( new BasicRequestProducer(Method.POST, target, "/more-stuff", new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message3, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message3); final HttpResponse response3 = message3.getHead(); - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = message3.getBody(); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } @Test @@ -164,11 +163,11 @@ void testLargeRequest() throws Exception { new BasicRequestProducer(Method.POST, target, "/a-lot-of-stuff", AsyncEntityProducers.create(content, ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message); final HttpResponse response = message.getHead(); - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final String body = message.getBody(); - assertThat(body, CoreMatchers.equalTo(content)); + Assertions.assertEquals(content, body); } @Test @@ -198,11 +197,11 @@ void testMultiplexedRequests() throws Exception { while (!queue.isEmpty()) { final Future> resultFuture = queue.remove(); final Message message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message); final HttpResponse response = message.getHead(); - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final String body = message.getBody(); - assertThat(body, CoreMatchers.containsString("stuff")); + Assertions.assertTrue(body.contains("stuff")); } } @@ -221,11 +220,11 @@ void testValidityCheck() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); Thread.sleep(100); @@ -234,11 +233,11 @@ void testValidityCheck() throws Exception { new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); Thread.sleep(100); @@ -247,11 +246,11 @@ void testValidityCheck() throws Exception { new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message3, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message3); final HttpResponse response3 = message3.getHead(); - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = message3.getBody(); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } @Test @@ -278,7 +277,7 @@ void testMultiplexedRequestCancellation() throws Exception { Thread.sleep(random.nextInt(10)); cancellable.cancel(); } - assertThat(countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()), CoreMatchers.equalTo(true)); + Assertions.assertTrue(countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java index 535101c893..71a5c98d67 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.net.InetSocketAddress; @@ -75,7 +74,6 @@ import org.apache.hc.core5.reactor.Command; import org.apache.hc.core5.reactor.IOSession; import org.apache.hc.core5.testing.extension.nio.H2TestResources; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -454,10 +452,10 @@ void testRequestWithInvalidConnectionHeader() throws Exception { context, null); final ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())); - assertThat(exception.getCause(), CoreMatchers.instanceOf(ProtocolException.class)); + Assertions.assertInstanceOf(ProtocolException.class, exception.getCause()); final EndpointDetails endpointDetails = context.getEndpointDetails(); - assertThat(endpointDetails.getRequestCount(), CoreMatchers.equalTo(0L)); + Assertions.assertEquals(0L, endpointDetails.getRequestCount()); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java index 5c6d69970b..142cb33a52 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -65,7 +65,6 @@ import org.apache.hc.core5.testing.extension.nio.H2AsyncRequesterResource; import org.apache.hc.core5.testing.extension.nio.H2AsyncServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -141,11 +140,11 @@ void testSequentialRequests() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message); final HttpResponse response = message.getHead(); - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final Header testFilterHeader = response.getHeader("X-Test-Filter"); - assertThat(testFilterHeader, CoreMatchers.notNullValue()); + Assertions.assertNotNull(testFilterHeader); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java index 9b0fe38546..4885cdf900 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; @@ -69,7 +69,6 @@ import org.apache.hc.core5.testing.extension.nio.HttpAsyncRequesterResource; import org.apache.hc.core5.testing.extension.nio.HttpAsyncServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -150,11 +149,11 @@ void testGetRequestAuthentication() throws Exception { new BasicRequestProducer(request1, null), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_UNAUTHORIZED)); + Assertions.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("You shall not pass!!!")); + Assertions.assertEquals("You shall not pass!!!", body1); final HttpRequest request2 = new BasicHttpRequest(Method.GET, target, "/stuff"); request2.setHeader(HttpHeaders.AUTHORIZATION, "let me pass"); @@ -162,11 +161,11 @@ void testGetRequestAuthentication() throws Exception { new BasicRequestProducer(request2, null), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("")); + Assertions.assertEquals("", body2); } @Test @@ -188,11 +187,11 @@ void testPostRequestAuthentication() throws Exception { new BasicRequestProducer(request1, AsyncEntityProducers.create(stuff, ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_UNAUTHORIZED)); + Assertions.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("You shall not pass!!!")); + Assertions.assertEquals("You shall not pass!!!", body1); final HttpRequest request2 = new BasicHttpRequest(Method.POST, target, "/stuff"); request2.setHeader(HttpHeaders.AUTHORIZATION, "let me pass"); @@ -200,11 +199,11 @@ void testPostRequestAuthentication() throws Exception { new BasicRequestProducer(request2, AsyncEntityProducers.create(stuff, ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo(new String(stuff, StandardCharsets.US_ASCII))); + Assertions.assertEquals(new String(stuff, StandardCharsets.US_ASCII), body2); } @Test @@ -228,11 +227,11 @@ void testPostRequestAuthenticationNoExpectContinue() throws Exception { new BasicRequestProducer(request1, AsyncEntityProducers.create(stuff, ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_UNAUTHORIZED)); + Assertions.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("You shall not pass!!!")); + Assertions.assertEquals("You shall not pass!!!", body1); final HttpRequest request2 = new BasicHttpRequest(Method.POST, target, "/stuff"); request2.setVersion(HttpVersion.HTTP_1_0); @@ -241,11 +240,11 @@ void testPostRequestAuthenticationNoExpectContinue() throws Exception { new BasicRequestProducer(request2, AsyncEntityProducers.create(stuff, ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo(new String(stuff, StandardCharsets.US_ASCII))); + Assertions.assertEquals(new String(stuff, StandardCharsets.US_ASCII), body2); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java index ebf0e16368..9ecd2cad9c 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -66,7 +66,6 @@ import org.apache.hc.core5.testing.extension.nio.HttpAsyncRequesterResource; import org.apache.hc.core5.testing.extension.nio.HttpAsyncServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -159,33 +158,33 @@ void testSequentialRequestsNonPersistentConnection() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); final Future> resultFuture2 = requester.execute( new BasicRequestProducer(Method.POST, target, "/no-keep-alive/other-stuff", new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); final Future> resultFuture3 = requester.execute( new BasicRequestProducer(Method.POST, target, "/no-keep-alive/more-stuff", new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message3, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message3); final HttpResponse response3 = message3.getHead(); - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = message3.getBody(); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java index 49bf019f64..65a16d97fb 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.net.InetSocketAddress; @@ -103,7 +102,6 @@ import org.apache.hc.core5.testing.extension.nio.Http1TestResources; import org.apache.hc.core5.util.CharArrayBuffer; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -654,9 +652,7 @@ void testPipelinedConnectionClose() throws Exception { final Exception exception = Assertions.assertThrows(Exception.class, () -> future3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())); - assertThat(exception, CoreMatchers.anyOf( - CoreMatchers.instanceOf(CancellationException.class), - CoreMatchers.instanceOf(ExecutionException.class))); + Assertions.assertTrue(exception instanceof CancellationException || exception instanceof ExecutionException); final BasicHttpRequest request4 = BasicRequestBuilder.post() .setHttpHost(target) @@ -667,9 +663,7 @@ void testPipelinedConnectionClose() throws Exception { new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Exception exception2 = Assertions.assertThrows(Exception.class, () -> future4.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())); - assertThat(exception2, CoreMatchers.anyOf( - CoreMatchers.instanceOf(CancellationException.class), - CoreMatchers.instanceOf(ExecutionException.class))); + Assertions.assertTrue(exception2 instanceof CancellationException || exception2 instanceof ExecutionException); } @Test @@ -731,9 +725,7 @@ void testPipelinedInvalidRequest() throws Exception { final Exception exception = Assertions.assertThrows(Exception.class, () -> future3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())); - assertThat(exception, CoreMatchers.anyOf( - CoreMatchers.instanceOf(CancellationException.class), - CoreMatchers.instanceOf(ExecutionException.class))); + Assertions.assertTrue(exception instanceof CancellationException || exception instanceof ExecutionException); } private static final byte[] GARBAGE = "garbage".getBytes(StandardCharsets.US_ASCII); diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java index a5ccd65baf..2818d51dfa 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java @@ -27,8 +27,8 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -57,7 +57,6 @@ import org.apache.hc.core5.http.nio.support.BasicResponseConsumer; import org.apache.hc.core5.reactor.ListenerEndpoint; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; abstract class HttpCoreTransportTest { @@ -88,33 +87,33 @@ void testSequentialRequests() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); final Future> resultFuture2 = requester.execute( new BasicRequestProducer(Method.POST, target, "/other-stuff", new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); final Future> resultFuture3 = requester.execute( new BasicRequestProducer(Method.POST, target, "/more-stuff", new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message3, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message3); final HttpResponse response3 = message3.getHead(); - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = message3.getBody(); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } @Test @@ -131,11 +130,11 @@ void testLargeRequest() throws Exception { new BasicRequestProducer(Method.POST, target, "/a-lot-of-stuff", AsyncEntityProducers.create(content, ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message); final HttpResponse response = message.getHead(); - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final String body = message.getBody(); - assertThat(body, CoreMatchers.equalTo(content)); + Assertions.assertEquals(content, body); } @Test @@ -152,33 +151,33 @@ void testSequentialRequestsNonPersistentConnection() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); final Future> resultFuture2 = requester.execute( new BasicRequestProducer(Method.POST, target, "/no-keep-alive/other-stuff", new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); final Future> resultFuture3 = requester.execute( new BasicRequestProducer(Method.POST, target, "/no-keep-alive/more-stuff", new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message3, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message3); final HttpResponse response3 = message3.getHead(); - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = message3.getBody(); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } @Test @@ -199,33 +198,33 @@ void testSequentialRequestsSameEndpoint() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); final Future> resultFuture2 = endpoint.execute( new BasicRequestProducer(Method.POST, target, "/other-stuff", new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("some other stuff")); + Assertions.assertEquals("some other stuff", body2); final Future> resultFuture3 = endpoint.execute( new BasicRequestProducer(Method.POST, target, "/more-stuff", new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message3, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message3); final HttpResponse response3 = message3.getHead(); - assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response3.getCode()); final String body3 = message3.getBody(); - assertThat(body3, CoreMatchers.equalTo("some more stuff")); + Assertions.assertEquals("some more stuff", body3); } finally { endpoint.releaseAndReuse(); @@ -263,11 +262,11 @@ void testPipelinedRequests() throws Exception { while (!queue.isEmpty()) { final Future> resultFuture = queue.remove(); final Message message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message); final HttpResponse response = message.getHead(); - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); final String body = message.getBody(); - assertThat(body, CoreMatchers.containsString("stuff")); + Assertions.assertTrue(body.contains("stuff")); } } finally { @@ -296,10 +295,10 @@ void testNonPersistentHeads() throws Exception { while (!queue.isEmpty()) { final Future> resultFuture = queue.remove(); final Message message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message); final HttpResponse response = message.getHead(); - assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); - assertThat(message.getBody(), CoreMatchers.nullValue()); + Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); + Assertions.assertNull(message.getBody()); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpIntegrationTest.java index e018227bb0..73b87d2cad 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpIntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpIntegrationTest.java @@ -102,9 +102,6 @@ import org.apache.hc.core5.testing.extension.ExecutorResource; import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -1365,7 +1362,7 @@ protected void handle( final HttpResponse response = result.getHead(); Assertions.assertNotNull(response); Assertions.assertEquals(200, response.getCode()); - MatcherAssert.assertThat(result.getBody(), Matchers.startsWith("All is well")); + Assertions.assertTrue(result.getBody().startsWith("All is well")); } } @@ -1478,10 +1475,7 @@ void testHeaderTooLarge(final String method) throws Exception { final HttpResponse response1 = result1.getHead(); Assertions.assertNotNull(response1); Assertions.assertEquals(431, response1.getCode()); - MatcherAssert.assertThat(result1.getBody(), - CoreMatchers.allOf( - CoreMatchers.containsString("Maximum"), - CoreMatchers.containsString("exceeded"))); + Assertions.assertTrue(result1.getBody().contains("Maximum") && result1.getBody().contains("exceeded")); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java index 58be25efac..f47147854b 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java @@ -84,8 +84,6 @@ import org.apache.hc.core5.util.Args; import org.apache.hc.core5.util.ReflectionUtils; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.AfterEachCallback; @@ -222,9 +220,8 @@ void testTLSSuccess(final TLS tlsProtocol) throws Exception { Assertions.assertNotNull(tlsDetails); final SSLSession tlsSession = tlsDetails.getSSLSession(); final ProtocolVersion tlsVersion = TLS.parse(tlsSession.getProtocol()); - MatcherAssert.assertThat(tlsVersion.greaterEquals(tlsProtocol.version), CoreMatchers.equalTo(true)); - MatcherAssert.assertThat(tlsSession.getPeerPrincipal().getName(), - CoreMatchers.equalTo("CN=localhost,OU=Apache HttpComponents,O=Apache Software Foundation")); + Assertions.assertTrue(tlsVersion.greaterEquals(tlsProtocol.version)); + Assertions.assertEquals("CN=localhost,OU=Apache HttpComponents,O=Apache Software Foundation", tlsSession.getPeerPrincipal().getName()); } @Test diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java index 8809683b50..487674558c 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.testing.nio; -import static org.hamcrest.MatcherAssert.assertThat; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -63,7 +62,6 @@ import org.apache.hc.core5.testing.extension.nio.HttpAsyncRequesterResource; import org.apache.hc.core5.testing.extension.nio.HttpAsyncServerResource; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -113,11 +111,11 @@ void testTLSUpgrade() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null); final Message message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message1); final HttpResponse response1 = message1.getHead(); - assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); final String body1 = message1.getBody(); - assertThat(body1, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body1); // Connect using plain HTTP scheme final Future endpointFuture = requester.connect( @@ -139,11 +137,11 @@ void testTLSUpgrade() throws Exception { new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null); final Message message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); - assertThat(message2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(message2); final HttpResponse response2 = message2.getHead(); - assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK)); + Assertions.assertEquals(HttpStatus.SC_OK, response2.getCode()); final String body2 = message2.getBody(); - assertThat(body2, CoreMatchers.equalTo("some stuff")); + Assertions.assertEquals("some stuff", body2); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java index 9936d76e0d..76fbbd15d5 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.testing.reactive; import static java.lang.String.format; -import static org.hamcrest.MatcherAssert.assertThat; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -74,7 +73,6 @@ import org.apache.hc.core5.testing.reactive.Reactive3TestUtils.StreamDescription; import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -269,9 +267,7 @@ void testResponseCancellation() throws Exception { Assertions.assertTrue(responsePublisherWasCancelled.get(), "The response subscription should have been cancelled"); final Exception exception = Assertions.assertThrows(Exception.class, () -> future.get(RESULT_TIMEOUT.getDuration(), RESULT_TIMEOUT.getTimeUnit())); - assertThat(exception, CoreMatchers.anyOf( - CoreMatchers.instanceOf(CancellationException.class), - CoreMatchers.instanceOf(ExecutionException.class))); + Assertions.assertTrue(exception instanceof CancellationException || exception instanceof ExecutionException); Assertions.assertInstanceOf(HttpStreamResetException.class, exception.getCause()); Assertions.assertTrue(requestPublisherCancellation.await(RESULT_TIMEOUT.getDuration(), RESULT_TIMEOUT.getTimeUnit())); Assertions.assertNull(requestStreamError.get()); diff --git a/httpcore5/pom.xml b/httpcore5/pom.xml index e91d6b1bd4..435616b9c0 100644 --- a/httpcore5/pom.xml +++ b/httpcore5/pom.xml @@ -50,11 +50,6 @@ junit-platform-launcher test - - org.hamcrest - hamcrest - test - org.mockito mockito-core diff --git a/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexCancellable.java b/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexCancellable.java index e728bc6450..ce70bfba60 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexCancellable.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexCancellable.java @@ -26,10 +26,9 @@ */ package org.apache.hc.core5.concurrent; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import java.util.concurrent.CountDownLatch; @@ -46,12 +45,12 @@ void testCancelled() { assertFalse(cancellable.isCancelled()); cancellable.cancel(); - assertThat(cancellable.isCancelled(), CoreMatchers.is(true)); - assertThat(dependency1.isCancelled(), CoreMatchers.is(true)); + assertTrue(cancellable.isCancelled()); + assertTrue(dependency1.isCancelled()); final BasicFuture dependency2 = new BasicFuture<>(null); cancellable.setDependency(dependency2); - assertThat(dependency2.isCancelled(), CoreMatchers.is(true)); + assertTrue(dependency2.isCancelled()); } @Test diff --git a/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexFuture.java b/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexFuture.java index e50826b874..a644c4911e 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexFuture.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestComplexFuture.java @@ -26,11 +26,9 @@ */ package org.apache.hc.core5.concurrent; -import static org.hamcrest.MatcherAssert.assertThat; import java.util.concurrent.Future; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -46,12 +44,12 @@ void testCancelled() { Assertions.assertFalse(future.isDone()); future.cancel(); - assertThat(future.isCancelled(), CoreMatchers.is(true)); - assertThat(dependency1.isCancelled(), CoreMatchers.is(true)); + Assertions.assertTrue(future.isCancelled()); + Assertions.assertTrue(dependency1.isCancelled()); final Future dependency2 = new BasicFuture<>(null); future.setDependency(dependency2); - assertThat(dependency2.isCancelled(), CoreMatchers.is(true)); + Assertions.assertTrue(dependency2.isCancelled()); } @Test @@ -64,12 +62,12 @@ void testCompleted() { Assertions.assertFalse(future.isDone()); future.completed(Boolean.TRUE); - assertThat(future.isCancelled(), CoreMatchers.is(false)); - assertThat(dependency1.isCancelled(), CoreMatchers.is(false)); + Assertions.assertFalse(future.isCancelled()); + Assertions.assertFalse(dependency1.isCancelled()); final Future dependency2 = new BasicFuture<>(null); future.setDependency(dependency2); - assertThat(dependency2.isCancelled(), CoreMatchers.is(true)); + Assertions.assertTrue(dependency2.isCancelled()); } @Test @@ -88,19 +86,19 @@ public void completed(final Object result) { Assertions.assertFalse(future.isDone()); future.cancel(); - assertThat(future.isCancelled(), CoreMatchers.is(true)); - assertThat(dependency1.isCancelled(), CoreMatchers.is(true)); + Assertions.assertTrue(future.isCancelled()); + Assertions.assertTrue(dependency1.isCancelled()); final Future dependency2 = new BasicFuture<>(null); future.setDependency(dependency2); - assertThat(dependency2.isCancelled(), CoreMatchers.is(true)); + Assertions.assertTrue(dependency2.isCancelled()); } @Test void testCanceledAndFailed() { final ComplexFuture future = new ComplexFuture<>(null); - assertThat(future.cancel(), CoreMatchers.is(true)); - assertThat(future.failed(new Exception()), CoreMatchers.is(false)); + Assertions.assertTrue(future.cancel()); + Assertions.assertFalse(future.failed(new Exception())); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java b/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java index df7e048655..37324a2f84 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java @@ -28,38 +28,24 @@ import java.util.Objects; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; +import org.junit.jupiter.api.Assertions; -public class HeaderMatcher extends BaseMatcher
{ +public final class HeaderMatcher { - private final String headerName; - private final Object headerValue; - - public HeaderMatcher(final String headerName, final Object headerValue) { - this.headerName = headerName; - this.headerValue = headerValue; - } - - @Override - public boolean matches(final Object item) { - if (item instanceof Header) { - final Header header = (Header) item; - if (headerName.equalsIgnoreCase(header.getName()) && Objects.equals(headerValue, header.getValue())) { - return true; - } - } - return false; + private HeaderMatcher() { } - @Override - public void describeTo(final Description description) { - description.appendText("same header as ").appendValue(headerValue).appendText(": ").appendValue(headerValue); + public static void assertSame(final Header actual, final String headerName, final Object headerValue) { + Assertions.assertNotNull(actual, "header should not be null"); + Assertions.assertTrue(headerName.equalsIgnoreCase(actual.getName()), + "header name mismatch: expected=" + headerName + ", actual=" + actual.getName()); + Assertions.assertTrue(Objects.equals(headerValue, actual.getValue()), + "header value mismatch: expected=" + headerValue + ", actual=" + actual.getValue()); } - public static Matcher
same(final String headerName, final Object headerValue) { - return new HeaderMatcher(headerName, headerValue); + public static void assertSame(final Header actual, final Header expected) { + Assertions.assertNotNull(expected, "expected header should not be null"); + assertSame(actual, expected.getName(), expected.getValue()); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java b/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java index b4108428f8..5bbc140dca 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java @@ -26,46 +26,32 @@ */ package org.apache.hc.core5.http; -import java.util.Objects; +import org.junit.jupiter.api.Assertions; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; +public final class HeadersMatcher { -public class HeadersMatcher extends BaseMatcher { - - private final Header[] expectedHeaders; - - public HeadersMatcher(final Header... headers) { - this.expectedHeaders = headers; + private HeadersMatcher() { } - @Override - public boolean matches(final Object item) { - if (item instanceof Header[]) { - final Header[] headers = (Header[]) item; - if (headers.length == expectedHeaders.length) { - for (int i = 0; i < headers.length; i++) { - final Header h1 = headers[i]; - final Header h2 = expectedHeaders[i]; - if (!h1.getName().equalsIgnoreCase(h2.getName()) - || !Objects.equals(h1.getValue(), h2.getValue())) { - return false; - } - } - return true; - } + public static void assertSame(final Header[] actual, final Header... expected) { + Assertions.assertNotNull(actual, "headers should not be null"); + Assertions.assertEquals(expected.length, actual.length, + "header array length mismatch: expected=" + expected.length + ", actual=" + actual.length); + for (int i = 0; i < actual.length; i++) { + final Header actualHeader = actual[i]; + final Header expectedHeader = expected[i]; + Assertions.assertNotNull(expectedHeader, "expected header at index " + i + " should not be null"); + Assertions.assertNotNull(actualHeader, "actual header at index " + i + " should not be null"); + Assertions.assertTrue(expectedHeader.getName().equalsIgnoreCase(actualHeader.getName()), + "header name mismatch at index " + i + ": expected=" + expectedHeader.getName() + + ", actual=" + actualHeader.getName()); + Assertions.assertEquals(expectedHeader.getValue(), actualHeader.getValue(), "header value mismatch at index " + i + ": expected=" + expectedHeader.getValue() + + ", actual=" + actualHeader.getValue()); } - return false; - } - - @Override - public void describeTo(final Description description) { - description.appendText("same headers as ").appendValueList("[", "; ", "]", expectedHeaders); } - public static Matcher same(final Header... headers) { - return new HeadersMatcher(headers); + public static void assertSame(final Header[] actual) { + assertSame(actual, new Header[0]); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java b/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java index b802e8d82e..0e6ebdb8cc 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java @@ -29,54 +29,37 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Objects; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; +import org.junit.jupiter.api.Assertions; -public class NameValuePairListMatcher extends BaseMatcher> { +public final class NameValuePairListMatcher { - private final List nvps; - - public NameValuePairListMatcher(final List nvps) { - this.nvps = nvps; + private NameValuePairListMatcher() { } - @Override - public boolean matches(final Object item) { - if (item instanceof List) { - final List objects = (List) item; - if (objects.size() != nvps.size()) { - return false; - } - for (int i = 1; i < objects.size(); i++) { - final Object obj = objects.get(i); - if (obj instanceof NameValuePair) { - final NameValuePair nvp = (NameValuePair) obj; - final NameValuePair expected = nvps.get(i); - if (!Objects.equals(nvp.getName(), expected.getName()) - || !Objects.equals(nvp.getValue(), expected.getValue())) { - return false; - } - } - } - return true; - } - return false; + public static void assertEqualsTo(final List actual, final NameValuePair... expected) { + assertEqualsTo(actual, Arrays.asList(expected)); } - @Override - public void describeTo(final Description description) { - description.appendText("equals ").appendValueList("[", ";", "]", nvps); + public static void assertEmpty(final List actual) { + assertEqualsTo(actual, Collections.emptyList()); } - public static Matcher> equalsTo(final NameValuePair... nvps) { - return new NameValuePairListMatcher(Arrays.asList(nvps)); - } - - public static Matcher> isEmpty() { - return new NameValuePairListMatcher(Collections.emptyList()); + private static void assertEqualsTo(final List actual, + final List expected) { + Assertions.assertNotNull(actual, "name-value list should not be null"); + Assertions.assertEquals(expected.size(), actual.size(), + "name-value list size mismatch: expected=" + expected.size() + ", actual=" + actual.size()); + for (int i = 0; i < actual.size(); i++) { + final NameValuePair actualNvp = actual.get(i); + final NameValuePair expectedNvp = expected.get(i); + Assertions.assertNotNull(expectedNvp, "expected name-value pair at index " + i + " should not be null"); + Assertions.assertNotNull(actualNvp, "actual name-value pair at index " + i + " should not be null"); + Assertions.assertEquals(actualNvp.getName(), expectedNvp.getName(), "name mismatch at index " + i + ": expected=" + expectedNvp.getName() + + ", actual=" + actualNvp.getName()); + Assertions.assertEquals(actualNvp.getValue(), expectedNvp.getValue(), "value mismatch at index " + i + ": expected=" + expectedNvp.getValue() + + ", actual=" + actualNvp.getValue()); + } } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersion.java b/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersion.java index 91a4049bff..379f2708a8 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersion.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersion.java @@ -27,10 +27,8 @@ package org.apache.hc.core5.http; -import static org.hamcrest.MatcherAssert.assertThat; import org.apache.hc.core5.util.Tokenizer; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -51,19 +49,19 @@ void testEqualsMajorMinor() { @Test void testParseBasic() throws Exception { - assertThat(ProtocolVersion.parse("PROTO/1"), CoreMatchers.equalTo(new ProtocolVersion("PROTO", 1, 0))); - assertThat(ProtocolVersion.parse("PROTO/1.1"), CoreMatchers.equalTo(new ProtocolVersion("PROTO", 1, 1))); - assertThat(ProtocolVersion.parse("PROTO/1.2"), CoreMatchers.equalTo(new ProtocolVersion("PROTO", 1, 2))); - assertThat(ProtocolVersion.parse("PROTO/1.3 "), CoreMatchers.equalTo(new ProtocolVersion("PROTO", 1, 3))); - assertThat(ProtocolVersion.parse("PROTO/000.0000 "), CoreMatchers.equalTo(new ProtocolVersion("PROTO", 0, 0))); - assertThat(ProtocolVersion.parse("PROTO/22.356"), CoreMatchers.equalTo(new ProtocolVersion("PROTO", 22, 356))); + Assertions.assertEquals(new ProtocolVersion("PROTO", 1, 0), ProtocolVersion.parse("PROTO/1")); + Assertions.assertEquals(new ProtocolVersion("PROTO", 1, 1), ProtocolVersion.parse("PROTO/1.1")); + Assertions.assertEquals(new ProtocolVersion("PROTO", 1, 2), ProtocolVersion.parse("PROTO/1.2")); + Assertions.assertEquals(new ProtocolVersion("PROTO", 1, 3), ProtocolVersion.parse("PROTO/1.3 ")); + Assertions.assertEquals(new ProtocolVersion("PROTO", 0, 0), ProtocolVersion.parse("PROTO/000.0000 ")); + Assertions.assertEquals(new ProtocolVersion("PROTO", 22, 356), ProtocolVersion.parse("PROTO/22.356")); } @Test void testParseBuffer() throws Exception { final Tokenizer.Cursor cursor = new Tokenizer.Cursor(1, 13); - assertThat(ProtocolVersion.parse(" PROTO/1.2,0000", cursor, Tokenizer.delimiters(',')), CoreMatchers.equalTo(new ProtocolVersion("PROTO", 1, 2))); - assertThat(cursor.getPos(), CoreMatchers.equalTo(10)); + Assertions.assertEquals(new ProtocolVersion("PROTO", 1, 2), ProtocolVersion.parse(" PROTO/1.2,0000", cursor, Tokenizer.delimiters(','))); + Assertions.assertEquals(10, cursor.getPos()); } @Test diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersionParser.java b/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersionParser.java index 501c5763ab..9771f4c74e 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersionParser.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/TestProtocolVersionParser.java @@ -27,11 +27,9 @@ package org.apache.hc.core5.http; -import static org.hamcrest.MatcherAssert.assertThat; import org.apache.hc.core5.http.message.ParserCursor; import org.apache.hc.core5.util.Tokenizer; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -84,7 +82,7 @@ void testParseVersion() throws Exception { void testParseVersionWithCursor() throws Exception { final Tokenizer.Cursor cursor = new Tokenizer.Cursor(2, 13); Assertions.assertEquals(new ProtocolVersion("PROTO", 1, 20), parseStr("PROTO", " 1.20,0000,00000", cursor, Tokenizer.delimiters(','))); - assertThat(cursor.getPos(), CoreMatchers.equalTo(6)); + Assertions.assertEquals(6, cursor.getPos()); } @Test diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/config/TestNamedElementChain.java b/httpcore5/src/test/java/org/apache/hc/core5/http/config/TestNamedElementChain.java index 50b6251ac2..0f1e02a409 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/config/TestNamedElementChain.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/config/TestNamedElementChain.java @@ -27,13 +27,8 @@ package org.apache.hc.core5.http.config; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.CoreMatchers.is; -import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** @@ -44,67 +39,67 @@ class TestNamedElementChain { @Test void testBasics() { final NamedElementChain list = new NamedElementChain<>(); - assertThat(list.getFirst(), CoreMatchers.nullValue()); - assertThat(list.getLast(), CoreMatchers.nullValue()); + Assertions.assertNull(list.getFirst()); + Assertions.assertNull(list.getLast()); final NamedElementChain.Node nodeA = list.addFirst('a', "a"); - assertThat(list.getFirst(), CoreMatchers.sameInstance(nodeA)); - assertThat(list.getLast(), CoreMatchers.sameInstance(nodeA)); + Assertions.assertSame(nodeA, list.getFirst()); + Assertions.assertSame(nodeA, list.getLast()); final NamedElementChain.Node nodeB = list.addLast('b', "b"); - assertThat(list.getFirst(), CoreMatchers.sameInstance(nodeA)); - assertThat(list.getLast(), CoreMatchers.sameInstance(nodeB)); + Assertions.assertSame(nodeA, list.getFirst()); + Assertions.assertSame(nodeB, list.getLast()); final NamedElementChain.Node nodeZ = list.addLast('z', "z"); - assertThat(list.getFirst(), CoreMatchers.sameInstance(nodeA)); - assertThat(list.getLast(), CoreMatchers.sameInstance(nodeZ)); + Assertions.assertSame(nodeA, list.getFirst()); + Assertions.assertSame(nodeZ, list.getLast()); - assertThat(nodeA.getPrevious(), CoreMatchers.nullValue()); - assertThat(nodeA.getNext(), CoreMatchers.sameInstance(nodeB)); - assertThat(nodeB.getPrevious(), CoreMatchers.sameInstance(nodeA)); - assertThat(nodeB.getNext(), CoreMatchers.sameInstance(nodeZ)); - assertThat(nodeZ.getPrevious(), CoreMatchers.sameInstance(nodeB)); - assertThat(nodeZ.getNext(), CoreMatchers.nullValue()); + Assertions.assertNull(nodeA.getPrevious()); + Assertions.assertSame(nodeB, nodeA.getNext()); + Assertions.assertSame(nodeA, nodeB.getPrevious()); + Assertions.assertSame(nodeZ, nodeB.getNext()); + Assertions.assertSame(nodeB, nodeZ.getPrevious()); + Assertions.assertNull(nodeZ.getNext()); final NamedElementChain.Node nodeD = list.addAfter("b", 'd', "d"); - assertThat(nodeD.getPrevious(), CoreMatchers.sameInstance(nodeB)); - assertThat(nodeD.getNext(), CoreMatchers.sameInstance(nodeZ)); - assertThat(nodeB.getNext(), CoreMatchers.sameInstance(nodeD)); - assertThat(nodeZ.getPrevious(), CoreMatchers.sameInstance(nodeD)); + Assertions.assertSame(nodeB, nodeD.getPrevious()); + Assertions.assertSame(nodeZ, nodeD.getNext()); + Assertions.assertSame(nodeD, nodeB.getNext()); + Assertions.assertSame(nodeD, nodeZ.getPrevious()); final NamedElementChain.Node nodeC = list.addBefore("d", 'c', "c"); - assertThat(nodeC.getPrevious(), CoreMatchers.sameInstance(nodeB)); - assertThat(nodeC.getNext(), CoreMatchers.sameInstance(nodeD)); - assertThat(nodeB.getNext(), CoreMatchers.sameInstance(nodeC)); - assertThat(nodeD.getPrevious(), CoreMatchers.sameInstance(nodeC)); - assertThat(list.getSize(), CoreMatchers.equalTo(5)); - - assertThat(list.remove("a"), CoreMatchers.is(true)); - assertThat(list.remove("z"), CoreMatchers.is(true)); - assertThat(list.remove("c"), CoreMatchers.is(true)); - assertThat(list.remove("c"), CoreMatchers.is(false)); - assertThat(list.remove("blah"), CoreMatchers.is(false)); - - assertThat(list.getFirst(), CoreMatchers.sameInstance(nodeB)); - assertThat(list.getLast(), CoreMatchers.sameInstance(nodeD)); - - assertThat(list.getSize(), CoreMatchers.equalTo(2)); - assertThat(list.addBefore("blah", 'e', "e"), CoreMatchers.nullValue()); - assertThat(list.getSize(), CoreMatchers.equalTo(2)); - - assertThat(list.addAfter("yada", 'e', "e"), CoreMatchers.nullValue()); - assertThat(list.getSize(), CoreMatchers.equalTo(2)); + Assertions.assertSame(nodeB, nodeC.getPrevious()); + Assertions.assertSame(nodeD, nodeC.getNext()); + Assertions.assertSame(nodeC, nodeB.getNext()); + Assertions.assertSame(nodeC, nodeD.getPrevious()); + Assertions.assertEquals(5, list.getSize()); + + Assertions.assertTrue(list.remove("a")); + Assertions.assertTrue(list.remove("z")); + Assertions.assertTrue(list.remove("c")); + Assertions.assertFalse(list.remove("c")); + Assertions.assertFalse(list.remove("blah")); + + Assertions.assertSame(nodeB, list.getFirst()); + Assertions.assertSame(nodeD, list.getLast()); + + Assertions.assertEquals(2, list.getSize()); + Assertions.assertNull(list.addBefore("blah", 'e', "e")); + Assertions.assertEquals(2, list.getSize()); + + Assertions.assertNull(list.addAfter("yada", 'e', "e")); + Assertions.assertEquals(2, list.getSize()); } @Test void testFind() { final NamedElementChain list = new NamedElementChain<>(); list.addLast('c', "c"); - assertThat(list.find("c"), notNullValue()); - assertThat(list.find("a"), nullValue()); + Assertions.assertNotNull(list.find("c")); + Assertions.assertNull(list.find("a")); } @Test @@ -112,11 +107,11 @@ void testReplace() { final NamedElementChain list = new NamedElementChain<>(); list.addLast('c', "c"); final boolean found = list.replace("c",'z' ); - assertThat(found, is(true)); - assertThat(list.find("c").getValue(), equalTo('z')); - assertThat(list.find("c").getName(), equalTo("c")); + Assertions.assertTrue(found); + Assertions.assertEquals('z', list.find("c").getValue()); + Assertions.assertEquals("c", list.find("c").getName()); final boolean notFound = list.replace("X",'z' ); - assertThat(notFound, is(false)); + Assertions.assertFalse(notFound); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestExpandableBuffer.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestExpandableBuffer.java index 2193c3e7bd..673a36bec0 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestExpandableBuffer.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestExpandableBuffer.java @@ -27,9 +27,8 @@ package org.apache.hc.core5.http.impl.nio; -import static org.hamcrest.MatcherAssert.assertThat; -import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class TestExpandableBuffer { @@ -37,47 +36,47 @@ class TestExpandableBuffer { @Test void testBasics() { final ExpandableBuffer buffer = new ExpandableBuffer(16); - assertThat(buffer.mode(), CoreMatchers.equalTo(ExpandableBuffer.Mode.INPUT)); - assertThat(buffer.hasData(), CoreMatchers.equalTo(false)); + Assertions.assertEquals(ExpandableBuffer.Mode.INPUT, buffer.mode()); + Assertions.assertFalse(buffer.hasData()); buffer.setInputMode(); buffer.buffer().put(new byte[] { 0, 1, 2, 3, 4, 5}); - assertThat(buffer.hasData(), CoreMatchers.equalTo(true)); - assertThat(buffer.length(), CoreMatchers.equalTo(6)); - assertThat(buffer.buffer().capacity(), CoreMatchers.equalTo(16)); - assertThat(buffer.mode(), CoreMatchers.equalTo(ExpandableBuffer.Mode.OUTPUT)); + Assertions.assertTrue(buffer.hasData()); + Assertions.assertEquals(6, buffer.length()); + Assertions.assertEquals(16, buffer.buffer().capacity()); + Assertions.assertEquals(ExpandableBuffer.Mode.OUTPUT, buffer.mode()); buffer.setInputMode(); buffer.buffer().put(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); - assertThat(buffer.length(), CoreMatchers.equalTo(16)); - assertThat(buffer.buffer().capacity(), CoreMatchers.equalTo(16)); - assertThat(buffer.mode(), CoreMatchers.equalTo(ExpandableBuffer.Mode.OUTPUT)); + Assertions.assertEquals(16, buffer.length()); + Assertions.assertEquals(16, buffer.buffer().capacity()); + Assertions.assertEquals(ExpandableBuffer.Mode.OUTPUT, buffer.mode()); buffer.setInputMode(); buffer.ensureCapacity(22); buffer.buffer().put(new byte[] { 0, 1, 2, 3, 4, 5}); - assertThat(buffer.length(), CoreMatchers.equalTo(22)); - assertThat(buffer.buffer().capacity(), CoreMatchers.equalTo(22)); - assertThat(buffer.mode(), CoreMatchers.equalTo(ExpandableBuffer.Mode.OUTPUT)); + Assertions.assertEquals(22, buffer.length()); + Assertions.assertEquals(22, buffer.buffer().capacity()); + Assertions.assertEquals(ExpandableBuffer.Mode.OUTPUT, buffer.mode()); buffer.clear(); - assertThat(buffer.mode(), CoreMatchers.equalTo(ExpandableBuffer.Mode.INPUT)); - assertThat(buffer.hasData(), CoreMatchers.equalTo(false)); - assertThat(buffer.capacity(), CoreMatchers.equalTo(22)); + Assertions.assertEquals(ExpandableBuffer.Mode.INPUT, buffer.mode()); + Assertions.assertFalse(buffer.hasData()); + Assertions.assertEquals(22, buffer.capacity()); } @Test void testAdjustCapacity() { final ExpandableBuffer buffer = new ExpandableBuffer(16); - assertThat(buffer.capacity(), CoreMatchers.equalTo(16)); + Assertions.assertEquals(16, buffer.capacity()); buffer.ensureCapacity(21); - assertThat(buffer.capacity(), CoreMatchers.equalTo(21)); + Assertions.assertEquals(21, buffer.capacity()); buffer.ensureAdjustedCapacity(22); - assertThat(buffer.capacity(), CoreMatchers.equalTo(1024)); + Assertions.assertEquals(1024, buffer.capacity()); buffer.ensureAdjustedCapacity(1024); - assertThat(buffer.capacity(), CoreMatchers.equalTo(1024)); + Assertions.assertEquals(1024, buffer.capacity()); buffer.ensureAdjustedCapacity(1025); - assertThat(buffer.capacity(), CoreMatchers.equalTo(2048)); + Assertions.assertEquals(2048, buffer.capacity()); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/ssl/TLSTest.java b/httpcore5/src/test/java/org/apache/hc/core5/http/ssl/TLSTest.java index c7cafa6845..a7edb2befe 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/ssl/TLSTest.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/ssl/TLSTest.java @@ -27,14 +27,12 @@ package org.apache.hc.core5.http.ssl; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.hc.core5.http.ParseException; import org.apache.hc.core5.http.ProtocolVersion; import org.apache.hc.core5.util.Tokenizer; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -93,19 +91,18 @@ void excludeWeak() { @Test void testParseBasic() throws Exception { - assertThat(TLS.parse("TLSv1"), CoreMatchers.equalTo(TLS.V_1_0.getVersion())); - assertThat(TLS.parse("TLSv1.1"), CoreMatchers.equalTo(TLS.V_1_1.getVersion())); - assertThat(TLS.parse("TLSv1.2"), CoreMatchers.equalTo(TLS.V_1_2.getVersion())); - assertThat(TLS.parse("TLSv1.3 "), CoreMatchers.equalTo(TLS.V_1_3.getVersion())); - assertThat(TLS.parse("TLSv22.356"), CoreMatchers.equalTo(new ProtocolVersion("TLS", 22, 356))); + Assertions.assertEquals(TLS.V_1_0.getVersion(), TLS.parse("TLSv1")); + Assertions.assertEquals(TLS.V_1_1.getVersion(), TLS.parse("TLSv1.1")); + Assertions.assertEquals(TLS.V_1_2.getVersion(), TLS.parse("TLSv1.2")); + Assertions.assertEquals(TLS.V_1_3.getVersion(), TLS.parse("TLSv1.3 ")); + Assertions.assertEquals(new ProtocolVersion("TLS", 22, 356), TLS.parse("TLSv22.356")); } @Test void testParseBuffer() throws Exception { final Tokenizer.Cursor cursor = new Tokenizer.Cursor(1, 13); - assertThat(TLS.parse(" TLSv1.2,0000", cursor, Tokenizer.delimiters(',')), - CoreMatchers.equalTo(TLS.V_1_2.getVersion())); - assertThat(cursor.getPos(), CoreMatchers.equalTo(8)); + Assertions.assertEquals(TLS.V_1_2.getVersion(), TLS.parse(" TLSv1.2,0000", cursor, Tokenizer.delimiters(','))); + Assertions.assertEquals(8, cursor.getPos()); } @Test diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/support/TestBasicMessageBuilders.java b/httpcore5/src/test/java/org/apache/hc/core5/http/support/TestBasicMessageBuilders.java index a25d567518..aad3194334 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/support/TestBasicMessageBuilders.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/support/TestBasicMessageBuilders.java @@ -27,9 +27,12 @@ package org.apache.hc.core5.http.support; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + import org.apache.hc.core5.http.HeaderMatcher; import org.apache.hc.core5.http.HeadersMatcher; import org.apache.hc.core5.http.HttpRequest; @@ -44,10 +47,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; - /** * Simple tests for {@link BasicResponseBuilder} and {@link BasicRequestBuilder}. */ @@ -77,38 +76,38 @@ void testResponseBasics() { builder.addHeader("h1", "v1"); builder.addHeader("h1", "v2"); builder.addHeader("h2", "v2"); - assertThat(builder.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2"))); - assertThat(builder.getHeaders("h1"), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"))); - assertThat(builder.getFirstHeader("h1"), HeaderMatcher.same("h1", "v1")); - assertThat(builder.getLastHeader("h1"), HeaderMatcher.same("h1", "v2")); + HeadersMatcher.assertSame(builder.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2")); + HeadersMatcher.assertSame(builder.getHeaders("h1"), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2")); + HeaderMatcher.assertSame(builder.getFirstHeader("h1"), "h1", "v1"); + HeaderMatcher.assertSame(builder.getLastHeader("h1"), "h1", "v2"); final BasicHttpResponse r3 = builder.build(); - assertThat(r3.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2"))); - assertThat(r3.getHeaders("h1"), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"))); - assertThat(r3.getFirstHeader("h1"), HeaderMatcher.same("h1", "v1")); - assertThat(r3.getLastHeader("h1"), HeaderMatcher.same("h1", "v2")); + HeadersMatcher.assertSame(r3.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2")); + HeadersMatcher.assertSame(r3.getHeaders("h1"), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2")); + HeaderMatcher.assertSame(r3.getFirstHeader("h1"), "h1", "v1"); + HeaderMatcher.assertSame(r3.getLastHeader("h1"), "h1", "v2"); builder.removeHeader(new BasicHeader("h1", "v2")); - assertThat(builder.getHeaders("h1"), HeadersMatcher.same(new BasicHeader("h1", "v1"))); - assertThat(builder.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(builder.getHeaders("h1"), new BasicHeader("h1", "v1")); + HeadersMatcher.assertSame(builder.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2")); final BasicHttpResponse r4 = builder.build(); - assertThat(r4.getHeaders("h1"), HeadersMatcher.same(new BasicHeader("h1", "v1"))); - assertThat(r4.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(r4.getHeaders("h1"), new BasicHeader("h1", "v1")); + HeadersMatcher.assertSame(r4.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2")); builder.removeHeaders("h1"); - assertThat(builder.getHeaders("h1"), HeadersMatcher.same()); - assertThat(builder.getHeaders(), HeadersMatcher.same(new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(builder.getHeaders("h1")); + HeadersMatcher.assertSame(builder.getHeaders(), new BasicHeader("h2", "v2")); final BasicHttpResponse r5 = builder.build(); - assertThat(r5.getHeaders("h1"), HeadersMatcher.same()); - assertThat(r5.getHeaders(), HeadersMatcher.same(new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(r5.getHeaders("h1")); + HeadersMatcher.assertSame(r5.getHeaders(), new BasicHeader("h2", "v2")); } @Test @@ -171,38 +170,38 @@ void testRequestBasics() throws Exception { builder.addHeader("h1", "v1"); builder.addHeader("h1", "v2"); builder.addHeader("h2", "v2"); - assertThat(builder.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2"))); - assertThat(builder.getHeaders("h1"), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"))); - assertThat(builder.getFirstHeader("h1"), HeaderMatcher.same("h1", "v1")); - assertThat(builder.getLastHeader("h1"), HeaderMatcher.same("h1", "v2")); + HeadersMatcher.assertSame(builder.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2")); + HeadersMatcher.assertSame(builder.getHeaders("h1"), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2")); + HeaderMatcher.assertSame(builder.getFirstHeader("h1"), "h1", "v1"); + HeaderMatcher.assertSame(builder.getLastHeader("h1"), "h1", "v2"); final BasicHttpRequest r4 = builder.build(); - assertThat(r4.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2"))); - assertThat(r4.getHeaders("h1"), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"))); - assertThat(r4.getFirstHeader("h1"), HeaderMatcher.same("h1", "v1")); - assertThat(r4.getLastHeader("h1"), HeaderMatcher.same("h1", "v2")); + HeadersMatcher.assertSame(r4.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2")); + HeadersMatcher.assertSame(r4.getHeaders("h1"), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2")); + HeaderMatcher.assertSame(r4.getFirstHeader("h1"), "h1", "v1"); + HeaderMatcher.assertSame(r4.getLastHeader("h1"), "h1", "v2"); builder.removeHeader(new BasicHeader("h1", "v2")); - assertThat(builder.getHeaders("h1"), HeadersMatcher.same(new BasicHeader("h1", "v1"))); - assertThat(builder.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(builder.getHeaders("h1"), new BasicHeader("h1", "v1")); + HeadersMatcher.assertSame(builder.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2")); final BasicHttpRequest r5 = builder.build(); - assertThat(r5.getHeaders("h1"), HeadersMatcher.same(new BasicHeader("h1", "v1"))); - assertThat(r5.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(r5.getHeaders("h1"), new BasicHeader("h1", "v1")); + HeadersMatcher.assertSame(r5.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h2", "v2")); builder.removeHeaders("h1"); - assertThat(builder.getHeaders("h1"), HeadersMatcher.same()); - assertThat(builder.getHeaders(), HeadersMatcher.same(new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(builder.getHeaders("h1")); + HeadersMatcher.assertSame(builder.getHeaders(), new BasicHeader("h2", "v2")); final BasicHttpRequest r6 = builder.build(); - assertThat(r6.getHeaders("h1"), HeadersMatcher.same()); - assertThat(r6.getHeaders(), HeadersMatcher.same(new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(r6.getHeaders("h1")); + HeadersMatcher.assertSame(r6.getHeaders(), new BasicHeader("h2", "v2")); } @Test @@ -216,13 +215,13 @@ void testResponseCopy() { final BasicResponseBuilder builder = BasicResponseBuilder.copy(response); Assertions.assertEquals(400, builder.getStatus()); Assertions.assertEquals(HttpVersion.HTTP_2, builder.getVersion()); - assertThat(builder.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(builder.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2")); } @Test void testRequestCopy() { - final HttpRequest request = new BasicHttpRequest(Method.GET, URI.create("https://host:3456/stuff?blah")) ; + final HttpRequest request = new BasicHttpRequest(Method.GET, URI.create("https://host:3456/stuff?blah")); request.addHeader("h1", "v1"); request.addHeader("h1", "v2"); request.addHeader("h2", "v2"); @@ -234,15 +233,15 @@ void testRequestCopy() { Assertions.assertEquals(new URIAuthority("host", 3456), builder.getAuthority()); Assertions.assertEquals("/stuff?blah", builder.getPath()); Assertions.assertEquals(HttpVersion.HTTP_2, builder.getVersion()); - assertThat(builder.getHeaders(), HeadersMatcher.same( - new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2"))); + HeadersMatcher.assertSame(builder.getHeaders(), + new BasicHeader("h1", "v1"), new BasicHeader("h1", "v2"), new BasicHeader("h2", "v2")); } @Test void testIDNIntegration() { final String url = "http://müller.example.com:8080/path"; final HttpRequest request = new BasicHttpRequest(Method.GET, URI.create(url)); - assertEquals(new URIAuthority("xn--mller-kva.example.com",8080), request.getAuthority()); + assertEquals(new URIAuthority("xn--mller-kva.example.com", 8080), request.getAuthority()); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/net/TestPercentCodec.java b/httpcore5/src/test/java/org/apache/hc/core5/net/TestPercentCodec.java index 1ef4ddde88..7c1b72aeaf 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/net/TestPercentCodec.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/net/TestPercentCodec.java @@ -27,13 +27,11 @@ package org.apache.hc.core5.net; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.charset.StandardCharsets; import java.util.stream.Stream; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -49,27 +47,21 @@ void testCoding() { PercentCodec.encode(buf, "blah!", StandardCharsets.UTF_8); PercentCodec.encode(buf, " ~ ", StandardCharsets.UTF_8); PercentCodec.encode(buf, "huh?", StandardCharsets.UTF_8); - assertThat(buf.toString(), CoreMatchers.equalTo("blah%21%20~%20huh%3F")); + assertEquals("blah%21%20~%20huh%3F", buf.toString()); } @Test void testDecoding() { - assertThat(PercentCodec.decode("blah%21%20~%20huh%3F", StandardCharsets.UTF_8), - CoreMatchers.equalTo("blah! ~ huh?")); - assertThat(PercentCodec.decode("blah%21+~%20huh%3F", StandardCharsets.UTF_8), - CoreMatchers.equalTo("blah!+~ huh?")); - assertThat(PercentCodec.decode("blah%21+~%20huh%3F", StandardCharsets.UTF_8, true), - CoreMatchers.equalTo("blah! ~ huh?")); + assertEquals("blah! ~ huh?", PercentCodec.decode("blah%21%20~%20huh%3F", StandardCharsets.UTF_8)); + assertEquals("blah!+~ huh?", PercentCodec.decode("blah%21+~%20huh%3F", StandardCharsets.UTF_8)); + assertEquals("blah! ~ huh?", PercentCodec.decode("blah%21+~%20huh%3F", StandardCharsets.UTF_8, true)); } @Test void testDecodingPartialContent() { - assertThat(PercentCodec.decode("blah%21%20%", StandardCharsets.UTF_8), - CoreMatchers.equalTo("blah! %")); - assertThat(PercentCodec.decode("blah%21%20%a", StandardCharsets.UTF_8), - CoreMatchers.equalTo("blah! %a")); - assertThat(PercentCodec.decode("blah%21%20%wa", StandardCharsets.UTF_8), - CoreMatchers.equalTo("blah! %wa")); + assertEquals("blah! %", PercentCodec.decode("blah%21%20%", StandardCharsets.UTF_8)); + assertEquals("blah! %a", PercentCodec.decode("blah%21%20%a", StandardCharsets.UTF_8)); + assertEquals("blah! %wa", PercentCodec.decode("blah%21%20%wa", StandardCharsets.UTF_8)); } @ParameterizedTest @@ -95,7 +87,7 @@ static Stream params() { @Test void verifyRfc5987EncodingandDecoding() { final String s = "!\"$£%^&*()_-+={[}]:@~;'#,./<>?\\|✓éèæðŃœ"; - assertThat(PercentCodec.RFC5987.decode(PercentCodec.RFC5987.encode(s)), CoreMatchers.equalTo(s)); + assertEquals(s, PercentCodec.RFC5987.decode(PercentCodec.RFC5987.encode(s))); } @Test diff --git a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java index 07b4f09362..b2fcb4dfa3 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.net; -import static org.hamcrest.MatcherAssert.assertThat; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -35,7 +34,6 @@ import java.io.ObjectOutputStream; import java.net.URISyntaxException; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -122,61 +120,36 @@ void testSerialization() throws Exception { @Test void testParse() throws Exception { - assertThat(URIAuthority.parse("somehost"), - CoreMatchers.equalTo(new URIAuthority("somehost", -1))); - assertThat(URIAuthority.parse("somehost/blah"), - CoreMatchers.equalTo(new URIAuthority("somehost", -1))); - assertThat(URIAuthority.parse("somehost?blah"), - CoreMatchers.equalTo(new URIAuthority("somehost", -1))); - assertThat(URIAuthority.parse("somehost#blah"), - CoreMatchers.equalTo(new URIAuthority("somehost", -1))); - assertThat(URIAuthority.parse("aaaa@:8080"), - CoreMatchers.equalTo(new URIAuthority("aaaa", "", 8080))); - assertThat(URIAuthority.parse("@:"), - CoreMatchers.equalTo(new URIAuthority(null, "", -1))); - assertThat(URIAuthority.parse("somehost:8080"), - CoreMatchers.equalTo(new URIAuthority("somehost", 8080))); - assertThat(URIAuthority.parse("somehost:8080/blah"), - CoreMatchers.equalTo(new URIAuthority("somehost", 8080))); - assertThat(URIAuthority.parse("somehost:8080?blah"), - CoreMatchers.equalTo(new URIAuthority("somehost", 8080))); - assertThat(URIAuthority.parse("somehost:8080#blah"), - CoreMatchers.equalTo(new URIAuthority("somehost", 8080))); - assertThat(URIAuthority.parse("somehost:008080"), - CoreMatchers.equalTo(new URIAuthority("somehost", 8080))); + Assertions.assertEquals(new URIAuthority("somehost", -1), URIAuthority.parse("somehost")); + Assertions.assertEquals(new URIAuthority("somehost", -1), URIAuthority.parse("somehost/blah")); + Assertions.assertEquals(new URIAuthority("somehost", -1), URIAuthority.parse("somehost?blah")); + Assertions.assertEquals(new URIAuthority("somehost", -1), URIAuthority.parse("somehost#blah")); + Assertions.assertEquals(new URIAuthority("aaaa", "", 8080), URIAuthority.parse("aaaa@:8080")); + Assertions.assertEquals(new URIAuthority(null, "", -1), URIAuthority.parse("@:")); + Assertions.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.parse("somehost:8080")); + Assertions.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.parse("somehost:8080/blah")); + Assertions.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.parse("somehost:8080?blah")); + Assertions.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.parse("somehost:8080#blah")); + Assertions.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.parse("somehost:008080")); Assertions.assertThrows(URISyntaxException.class, () -> URIAuthority.create("somehost:aaaaa")); Assertions.assertThrows(URISyntaxException.class, () -> URIAuthority.create("somehost:90ab")); - assertThat(URIAuthority.parse("someuser@somehost"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - assertThat(URIAuthority.parse("someuser@somehost/blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - assertThat(URIAuthority.parse("someuser@somehost?blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - assertThat(URIAuthority.parse("someuser@somehost#blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - - assertThat(URIAuthority.parse("someuser@somehost:"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - assertThat(URIAuthority.parse("someuser@somehost:/blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - assertThat(URIAuthority.parse("someuser@somehost:?blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - assertThat(URIAuthority.parse("someuser@somehost:#blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", -1))); - - assertThat(URIAuthority.parse("someuser@somehost:8080"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", 8080))); - assertThat(URIAuthority.parse("someuser@somehost:8080/blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", 8080))); - assertThat(URIAuthority.parse("someuser@somehost:8080?blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", 8080))); - assertThat(URIAuthority.parse("someuser@somehost:8080#blah"), - CoreMatchers.equalTo(new URIAuthority("someuser", "somehost", 8080))); - assertThat(URIAuthority.parse("@somehost:8080"), - CoreMatchers.equalTo(new URIAuthority("somehost", 8080))); - assertThat(URIAuthority.parse("test:test@localhost:38339"), - CoreMatchers.equalTo(new URIAuthority("test:test", "localhost", 38339))); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost/blah")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost?blah")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost#blah")); + + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost:")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost:/blah")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost:?blah")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", -1), URIAuthority.parse("someuser@somehost:#blah")); + + Assertions.assertEquals(new URIAuthority("someuser", "somehost", 8080), URIAuthority.parse("someuser@somehost:8080")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", 8080), URIAuthority.parse("someuser@somehost:8080/blah")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", 8080), URIAuthority.parse("someuser@somehost:8080?blah")); + Assertions.assertEquals(new URIAuthority("someuser", "somehost", 8080), URIAuthority.parse("someuser@somehost:8080#blah")); + Assertions.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.parse("@somehost:8080")); + Assertions.assertEquals(new URIAuthority("test:test", "localhost", 38339), URIAuthority.parse("test:test@localhost:38339")); Assertions.assertThrows(URISyntaxException.class, () -> URIAuthority.create("blah@goggle.com:80@google.com/")); } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java index 74e7a6016c..3483309a3b 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java @@ -26,7 +26,6 @@ */ package org.apache.hc.core5.net; -import static org.hamcrest.MatcherAssert.assertThat; import java.net.InetAddress; import java.net.URI; @@ -43,7 +42,6 @@ import org.apache.hc.core5.http.NameValuePairListMatcher; import org.apache.hc.core5.http.URIScheme; import org.apache.hc.core5.http.message.BasicNameValuePair; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -59,16 +57,14 @@ static List parsePath(final CharSequence s) { @Test void testParseSegments() { - assertThat(parsePath("/this/that"), CoreMatchers.equalTo(Arrays.asList("this", "that"))); - assertThat(parsePath("this/that"), CoreMatchers.equalTo(Arrays.asList("this", "that"))); - assertThat(parsePath("this//that"), CoreMatchers.equalTo(Arrays.asList("this", "", "that"))); - assertThat(parsePath("this//that/"), CoreMatchers.equalTo(Arrays.asList("this", "", "that", ""))); - assertThat(parsePath("this//that/%2fthis%20and%20that"), - CoreMatchers.equalTo(Arrays.asList("this", "", "that", "/this and that"))); - assertThat(parsePath("this///that//"), - CoreMatchers.equalTo(Arrays.asList("this", "", "", "that", "", ""))); - assertThat(parsePath("/"), CoreMatchers.equalTo(Collections.singletonList(""))); - assertThat(parsePath(""), CoreMatchers.equalTo(Collections.emptyList())); + Assertions.assertEquals(Arrays.asList("this", "that"), parsePath("/this/that")); + Assertions.assertEquals(Arrays.asList("this", "that"), parsePath("this/that")); + Assertions.assertEquals(Arrays.asList("this", "", "that"), parsePath("this//that")); + Assertions.assertEquals(Arrays.asList("this", "", "that", ""), parsePath("this//that/")); + Assertions.assertEquals(Arrays.asList("this", "", "that", "/this and that"), parsePath("this//that/%2fthis%20and%20that")); + Assertions.assertEquals(Arrays.asList("this", "", "", "that", "", ""), parsePath("this///that//")); + Assertions.assertEquals(Collections.singletonList(""), parsePath("/")); + Assertions.assertEquals(Collections.emptyList(), parsePath("")); } static String formatPath(final String... pathSegments) { @@ -79,14 +75,12 @@ static String formatPath(final String... pathSegments) { @Test void testFormatSegments() { - assertThat(formatPath("this", "that"), CoreMatchers.equalTo("/this/that")); - assertThat(formatPath("this", "", "that"), CoreMatchers.equalTo("/this//that")); - assertThat(formatPath("this", "", "that", "/this and that"), - CoreMatchers.equalTo("/this//that/%2Fthis%20and%20that")); - assertThat(formatPath("this", "", "", "that", "", ""), - CoreMatchers.equalTo("/this///that//")); - assertThat(formatPath(""), CoreMatchers.equalTo("/")); - assertThat(formatPath(), CoreMatchers.equalTo("")); + Assertions.assertEquals("/this/that", formatPath("this", "that")); + Assertions.assertEquals("/this//that", formatPath("this", "", "that")); + Assertions.assertEquals("/this//that/%2Fthis%20and%20that", formatPath("this", "", "that", "/this and that")); + Assertions.assertEquals("/this///that//", formatPath("this", "", "", "that", "", "")); + Assertions.assertEquals("/", formatPath("")); + Assertions.assertEquals("", formatPath()); } static List parseQuery(final CharSequence s) { @@ -95,43 +89,30 @@ static List parseQuery(final CharSequence s) { @Test void testParseQuery() { - assertThat(parseQuery(""), NameValuePairListMatcher.isEmpty()); - assertThat(parseQuery("Name0"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name0", null))); - assertThat(parseQuery("Name1=Value1"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name1", "Value1"))); - assertThat(parseQuery("Name2="), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name2", ""))); - assertThat(parseQuery(" Name3 "), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name3", null))); - assertThat(parseQuery("Name4=Value%204%21"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value 4!"))); - assertThat(parseQuery("Name4=Value%2B4%21"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value+4!"))); - assertThat(parseQuery("Name4=Value%204%21%20%214"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value 4! !4"))); - assertThat(parseQuery("Name5=aaa&Name6=bbb"), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("Name5", "aaa"), - new BasicNameValuePair("Name6", "bbb"))); - assertThat(parseQuery("Name7=aaa&Name7=b%2Cb&Name7=ccc"), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("Name7", "aaa"), - new BasicNameValuePair("Name7", "b,b"), - new BasicNameValuePair("Name7", "ccc"))); - assertThat(parseQuery("Name8=xx%2C%20%20yy%20%20%2Czz"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name8", "xx, yy ,zz"))); - assertThat(parseQuery("price=10%20%E2%82%AC"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("price", "10 \u20AC"))); - assertThat(parseQuery("a=b\"c&d=e"), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("a", "b\"c"), - new BasicNameValuePair("d", "e"))); - assertThat(parseQuery("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + + NameValuePairListMatcher.assertEmpty(parseQuery("")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name0"), new BasicNameValuePair("Name0", null)); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name1=Value1"), new BasicNameValuePair("Name1", "Value1")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name2="), new BasicNameValuePair("Name2", "")); + NameValuePairListMatcher.assertEqualsTo(parseQuery(" Name3 "), new BasicNameValuePair("Name3", null)); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name4=Value%204%21"), new BasicNameValuePair("Name4", "Value 4!")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name4=Value%2B4%21"), new BasicNameValuePair("Name4", "Value+4!")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name4=Value%204%21%20%214"), new BasicNameValuePair("Name4", "Value 4! !4")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name5=aaa&Name6=bbb"), + new BasicNameValuePair("Name5", "aaa"), + new BasicNameValuePair("Name6", "bbb")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name7=aaa&Name7=b%2Cb&Name7=ccc"), + new BasicNameValuePair("Name7", "aaa"), + new BasicNameValuePair("Name7", "b,b"), + new BasicNameValuePair("Name7", "ccc")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("Name8=xx%2C%20%20yy%20%20%2Czz"), new BasicNameValuePair("Name8", "xx, yy ,zz")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("price=10%20%E2%82%AC"), new BasicNameValuePair("price", "10 \u20AC")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("a=b\"c&d=e"), + new BasicNameValuePair("a", "b\"c"), + new BasicNameValuePair("d", "e")); + NameValuePairListMatcher.assertEqualsTo(parseQuery("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8)), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("russian", RU_HELLO), - new BasicNameValuePair("swiss", CH_HELLO))); + new BasicNameValuePair("russian", RU_HELLO), + new BasicNameValuePair("swiss", CH_HELLO)); } static String formatQuery(final NameValuePair... params) { @@ -142,30 +123,25 @@ static String formatQuery(final NameValuePair... params) { @Test void testFormatQuery() { - assertThat(formatQuery(new BasicNameValuePair("Name0", null)), CoreMatchers.equalTo("Name0")); - assertThat(formatQuery(new BasicNameValuePair("Name1", "Value1")), CoreMatchers.equalTo("Name1=Value1")); - assertThat(formatQuery(new BasicNameValuePair("Name2", "")), CoreMatchers.equalTo("Name2=")); - assertThat(formatQuery(new BasicNameValuePair("Name4", "Value 4&")), - CoreMatchers.equalTo("Name4=Value%204%26")); - assertThat(formatQuery(new BasicNameValuePair("Name4", "Value+4&")), - CoreMatchers.equalTo("Name4=Value%2B4%26")); - assertThat(formatQuery(new BasicNameValuePair("Name4", "Value 4& =4")), - CoreMatchers.equalTo("Name4=Value%204%26%20%3D4")); - assertThat(formatQuery( + Assertions.assertEquals("Name0", formatQuery(new BasicNameValuePair("Name0", null))); + Assertions.assertEquals("Name1=Value1", formatQuery(new BasicNameValuePair("Name1", "Value1"))); + Assertions.assertEquals("Name2=", formatQuery(new BasicNameValuePair("Name2", ""))); + Assertions.assertEquals("Name4=Value%204%26", formatQuery(new BasicNameValuePair("Name4", "Value 4&"))); + Assertions.assertEquals("Name4=Value%2B4%26", formatQuery(new BasicNameValuePair("Name4", "Value+4&"))); + Assertions.assertEquals("Name4=Value%204%26%20%3D4", formatQuery(new BasicNameValuePair("Name4", "Value 4& =4"))); + Assertions.assertEquals("Name5=aaa&Name6=bbb", formatQuery( new BasicNameValuePair("Name5", "aaa"), - new BasicNameValuePair("Name6", "bbb")), CoreMatchers.equalTo("Name5=aaa&Name6=bbb")); - assertThat(formatQuery( + new BasicNameValuePair("Name6", "bbb"))); + Assertions.assertEquals("Name7=aaa&Name7=b%2Cb&Name7=ccc", formatQuery( new BasicNameValuePair("Name7", "aaa"), new BasicNameValuePair("Name7", "b,b"), new BasicNameValuePair("Name7", "ccc") - ), CoreMatchers.equalTo("Name7=aaa&Name7=b%2Cb&Name7=ccc")); - assertThat(formatQuery(new BasicNameValuePair("Name8", "xx, yy ,zz")), - CoreMatchers.equalTo("Name8=xx%2C%20%20yy%20%20%2Czz")); - assertThat(formatQuery( + )); + Assertions.assertEquals("Name8=xx%2C%20%20yy%20%20%2Czz", formatQuery(new BasicNameValuePair("Name8", "xx, yy ,zz"))); + Assertions.assertEquals("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + + "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8), formatQuery( new BasicNameValuePair("russian", RU_HELLO), - new BasicNameValuePair("swiss", CH_HELLO)), - CoreMatchers.equalTo("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + - "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8))); + new BasicNameValuePair("swiss", CH_HELLO))); } @Test @@ -371,7 +347,7 @@ void testSetParameter() throws Exception { void testGetFirstNamedParameter() throws Exception { final URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null); URIBuilder uribuilder = new URIBuilder(uri).setParameter("param", "some other stuff") - .setParameter("blah", "blah"); + .setParameter("blah", "blah"); Assertions.assertEquals("some other stuff", uribuilder.getFirstQueryParam("param").getValue()); Assertions.assertEquals("blah", uribuilder.getFirstQueryParam("blah").getValue()); Assertions.assertNull(uribuilder.getFirstQueryParam("DoesNotExist")); @@ -418,7 +394,7 @@ void testSetParametersWithNullList() throws Exception { void testParameterWithSpecialChar() throws Exception { final URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null); final URIBuilder uribuilder = new URIBuilder(uri).addParameter("param", "1 + 1 = 2") - .addParameter("param", "blah&blah"); + .addParameter("param", "blah&blah"); final URI result = uribuilder.build(); Assertions.assertEquals(new URI("http://localhost:80/?param=stuff¶m=1%20%2B%201%20%3D%202&" + "param=blah%26blah"), result); @@ -428,7 +404,7 @@ void testParameterWithSpecialChar() throws Exception { void testAddParameter() throws Exception { final URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null); final URIBuilder uribuilder = new URIBuilder(uri).addParameter("param", "some other stuff") - .addParameter("blah", "blah"); + .addParameter("blah", "blah"); final URI result = uribuilder.build(); Assertions.assertEquals(new URI("http://localhost:80/?param=stuff&blah&blah&" + "param=some%20other%20stuff&blah=blah"), result); @@ -439,8 +415,8 @@ void testQueryEncoding() throws Exception { final URI uri1 = new URI("https://somehost.com/stuff?client_id=1234567890" + "&redirect_uri=https%3A%2F%2Fsomehost.com%2Fblah%20blah%2F"); final URI uri2 = new URIBuilder("https://somehost.com/stuff") - .addParameter("client_id","1234567890") - .addParameter("redirect_uri","https://somehost.com/blah blah/").build(); + .addParameter("client_id", "1234567890") + .addParameter("redirect_uri", "https://somehost.com/blah blah/").build(); Assertions.assertEquals(uri1, uri2); } @@ -448,9 +424,9 @@ void testQueryEncoding() throws Exception { void testQueryAndParameterEncoding() throws Exception { final URI uri1 = new URI("https://somehost.com/stuff?param1=12345¶m2=67890"); final URI uri2 = new URIBuilder("https://somehost.com/stuff") - .setCustomQuery("this&that") - .addParameter("param1","12345") - .addParameter("param2","67890").build(); + .setCustomQuery("this&that") + .addParameter("param1", "12345") + .addParameter("param2", "67890").build(); Assertions.assertEquals(uri1, uri2); } @@ -458,10 +434,10 @@ void testQueryAndParameterEncoding() throws Exception { void testPathEncoding() throws Exception { final URI uri1 = new URI("https://somehost.com/some%20path%20with%20blanks/"); final URI uri2 = new URIBuilder() - .setScheme("https") - .setHost("somehost.com") - .setPath("/some path with blanks/") - .build(); + .setScheme("https") + .setHost("somehost.com") + .setPath("/some path with blanks/") + .build(); Assertions.assertEquals(uri1, uri2); } @@ -580,31 +556,29 @@ void testRelativePathWithAuthority() throws Exception { @Test void testTolerateNullInput() throws Exception { - assertThat(new URIBuilder() - .setScheme(null) - .setHost("localhost") - .setUserInfo(null) - .setPort(8443) - .setPath(null) - .setCustomQuery(null) - .setFragment(null) - .build(), - CoreMatchers.equalTo(URI.create("//localhost:8443"))); + Assertions.assertEquals(URI.create("//localhost:8443"), new URIBuilder() + .setScheme(null) + .setHost("localhost") + .setUserInfo(null) + .setPort(8443) + .setPath(null) + .setCustomQuery(null) + .setFragment(null) + .build()); } @Test void testTolerateBlankInput() throws Exception { - assertThat(new URIBuilder() - .setScheme("") - .setHost("localhost") - .setUserInfo("") - .setPort(8443) - .setPath("") - .setPath("") - .setCustomQuery("") - .setFragment("") - .build(), - CoreMatchers.equalTo(URI.create("//localhost:8443"))); + Assertions.assertEquals(URI.create("//localhost:8443"), new URIBuilder() + .setScheme("") + .setHost("localhost") + .setUserInfo("") + .setPort(8443) + .setPath("") + .setPath("") + .setCustomQuery("") + .setFragment("") + .build()); } @Test @@ -636,7 +610,7 @@ void testMultipleLeadingPathSlashes() throws Exception { .setHost("somehost") .setPath("//blah//blah") .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("ftp://somehost//blah//blah"))); + Assertions.assertEquals(URI.create("ftp://somehost//blah//blah"), uri); } @Test @@ -645,155 +619,155 @@ void testNoAuthorityAndPath() throws Exception { .setScheme("file") .setPath("/blah") .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("file:/blah"))); + Assertions.assertEquals(URI.create("file:/blah"), uri); } @Test void testSetPathSegmentList() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .setPathSegments(Arrays.asList("api", "products")) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost/api/products"))); + .setScheme("https") + .setHost("somehost") + .setPathSegments(Arrays.asList("api", "products")) + .build(); + Assertions.assertEquals(URI.create("https://somehost/api/products"), uri); } @Test void testSetPathSegmentsVarargs() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .setPathSegments("api", "products") - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost/api/products"))); + .setScheme("https") + .setHost("somehost") + .setPathSegments("api", "products") + .build(); + Assertions.assertEquals(URI.create("https://somehost/api/products"), uri); } @Test void testSetPathSegmentsRootlessList() throws Exception { final URI uri = new URIBuilder() - .setScheme("file") - .setPathSegmentsRootless(Arrays.asList("dir", "foo")) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("file:dir/foo"))); + .setScheme("file") + .setPathSegmentsRootless(Arrays.asList("dir", "foo")) + .build(); + Assertions.assertEquals(URI.create("file:dir/foo"), uri); } @Test void testSetPathSegmentsRootlessVarargs() throws Exception { final URI uri = new URIBuilder() - .setScheme("file") - .setPathSegmentsRootless("dir", "foo") - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("file:dir/foo"))); + .setScheme("file") + .setPathSegmentsRootless("dir", "foo") + .build(); + Assertions.assertEquals(URI.create("file:dir/foo"), uri); } @Test void testAppendToExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .setPath("api") - .appendPath("v1/resources") - .appendPath("idA") - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost/api/v1/resources/idA"))); + .setScheme("https") + .setHost("somehost") + .setPath("api") + .appendPath("v1/resources") + .appendPath("idA") + .build(); + Assertions.assertEquals(URI.create("https://somehost/api/v1/resources/idA"), uri); } @Test void testAppendToNonExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .appendPath("api/v2/customers") - .appendPath("idA") - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost/api/v2/customers/idA"))); + .setScheme("https") + .setHost("somehost") + .appendPath("api/v2/customers") + .appendPath("idA") + .build(); + Assertions.assertEquals(URI.create("https://somehost/api/v2/customers/idA"), uri); } @Test void testAppendNullToExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .setPath("api") - .appendPath(null) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost/api"))); + .setScheme("https") + .setHost("somehost") + .setPath("api") + .appendPath(null) + .build(); + Assertions.assertEquals(URI.create("https://somehost/api"), uri); } @Test void testAppendNullToNonExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .appendPath(null) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost"))); + .setScheme("https") + .setHost("somehost") + .appendPath(null) + .build(); + Assertions.assertEquals(URI.create("https://somehost"), uri); } @Test void testAppendSegmentsVarargsToExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("myhost") - .setPath("api") - .appendPathSegments("v3", "products") - .appendPathSegments("idA") - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://myhost/api/v3/products/idA"))); + .setScheme("https") + .setHost("myhost") + .setPath("api") + .appendPathSegments("v3", "products") + .appendPathSegments("idA") + .build(); + Assertions.assertEquals(URI.create("https://myhost/api/v3/products/idA"), uri); } @Test void testAppendSegmentsVarargsToNonExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .appendPathSegments("api", "v2", "customers") - .appendPathSegments("idA") - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost/api/v2/customers/idA"))); + .setScheme("https") + .setHost("somehost") + .appendPathSegments("api", "v2", "customers") + .appendPathSegments("idA") + .build(); + Assertions.assertEquals(URI.create("https://somehost/api/v2/customers/idA"), uri); } @Test void testAppendNullSegmentsVarargs() throws Exception { final String pathSegment = null; final URI uri = new URIBuilder() - .setScheme("https") - .setHost("somehost") - .appendPathSegments(pathSegment) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("https://somehost/"))); + .setScheme("https") + .setHost("somehost") + .appendPathSegments(pathSegment) + .build(); + Assertions.assertEquals(URI.create("https://somehost/"), uri); } @Test void testAppendSegmentsListToExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("http") - .setHost("myhost") - .setPath("api") - .appendPathSegments(Arrays.asList("v3", "products")) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("http://myhost/api/v3/products"))); + .setScheme("http") + .setHost("myhost") + .setPath("api") + .appendPathSegments(Arrays.asList("v3", "products")) + .build(); + Assertions.assertEquals(URI.create("http://myhost/api/v3/products"), uri); } @Test void testAppendSegmentsListToNonExistingPath() throws Exception { final URI uri = new URIBuilder() - .setScheme("http") - .setHost("myhost") - .appendPathSegments(Arrays.asList("api", "v3", "customers")) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("http://myhost/api/v3/customers"))); + .setScheme("http") + .setHost("myhost") + .appendPathSegments(Arrays.asList("api", "v3", "customers")) + .build(); + Assertions.assertEquals(URI.create("http://myhost/api/v3/customers"), uri); } @Test void testAppendNullSegmentsList() throws Exception { final List pathSegments = null; final URI uri = new URIBuilder() - .setScheme("http") - .setHost("myhost") - .appendPathSegments(pathSegments) - .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("http://myhost"))); + .setScheme("http") + .setHost("myhost") + .appendPathSegments(pathSegments) + .build(); + Assertions.assertEquals(URI.create("http://myhost"), uri); } @Test @@ -802,7 +776,7 @@ void testNoAuthorityAndPathSegments() throws Exception { .setScheme("file") .setPathSegments("this", "that") .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("file:/this/that"))); + Assertions.assertEquals(URI.create("file:/this/that"), uri); } @Test @@ -811,7 +785,7 @@ void testNoAuthorityAndRootlessPath() throws Exception { .setScheme("file") .setPath("blah") .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("file:blah"))); + Assertions.assertEquals(URI.create("file:blah"), uri); } @Test @@ -820,14 +794,14 @@ void testNoAuthorityAndRootlessPathSegments() throws Exception { .setScheme("file") .setPathSegmentsRootless("this", "that") .build(); - assertThat(uri, CoreMatchers.equalTo(URI.create("file:this/that"))); + Assertions.assertEquals(URI.create("file:this/that"), uri); } @Test void testOpaque() throws Exception { final URIBuilder uriBuilder = new URIBuilder("http://host.com"); final URI uri = uriBuilder.build(); - assertThat(uriBuilder.isOpaque(), CoreMatchers.equalTo(uri.isOpaque())); + Assertions.assertEquals(uri.isOpaque(), uriBuilder.isOpaque()); } @Test @@ -842,37 +816,41 @@ void testAddParameterEncodingEquivalence() throws Exception { @Test void testSchemeSpecificPartParametersNull() throws Exception { - final URIBuilder uribuilder = new URIBuilder("http://host.com").setParameter("par", "parvalue") - .setSchemeSpecificPart("", (NameValuePair)null); - Assertions.assertEquals(new URI("http://host.com?par=parvalue"), uribuilder.build()); + final URIBuilder uribuilder = new URIBuilder("http://host.com").setParameter("par", "parvalue") + .setSchemeSpecificPart("", (NameValuePair) null); + Assertions.assertEquals(new URI("http://host.com?par=parvalue"), uribuilder.build()); } @Test void testSchemeSpecificPartSetGet() { - final URIBuilder uribuilder = new URIBuilder().setSchemeSpecificPart("specificpart"); - Assertions.assertEquals("specificpart", uribuilder.getSchemeSpecificPart()); + final URIBuilder uribuilder = new URIBuilder().setSchemeSpecificPart("specificpart"); + Assertions.assertEquals("specificpart", uribuilder.getSchemeSpecificPart()); } - /** Common use case: mailto: scheme. See https://tools.ietf.org/html/rfc6068#section-2 */ + /** + * Common use case: mailto: scheme. See https://tools.ietf.org/html/rfc6068#section-2 + */ @Test void testSchemeSpecificPartNameValuePairByRFC6068Sample() throws Exception { - final URIBuilder uribuilder = new URIBuilder().setScheme("mailto") - .setSchemeSpecificPart("my@email.server", new BasicNameValuePair("subject", "mail subject")); - final String result = uribuilder.build().toString(); - Assertions.assertTrue(result.contains("my@email.server"), "mail address as scheme specific part expected"); - Assertions.assertTrue(result.contains("mail%20subject"), "correct parameter encoding expected for that scheme"); + final URIBuilder uribuilder = new URIBuilder().setScheme("mailto") + .setSchemeSpecificPart("my@email.server", new BasicNameValuePair("subject", "mail subject")); + final String result = uribuilder.build().toString(); + Assertions.assertTrue(result.contains("my@email.server"), "mail address as scheme specific part expected"); + Assertions.assertTrue(result.contains("mail%20subject"), "correct parameter encoding expected for that scheme"); } - /** Common use case: mailto: scheme. See https://tools.ietf.org/html/rfc6068#section-2 */ + /** + * Common use case: mailto: scheme. See https://tools.ietf.org/html/rfc6068#section-2 + */ @Test void testSchemeSpecificPartNameValuePairListByRFC6068Sample() throws Exception { final List parameters = new ArrayList<>(); parameters.add(new BasicNameValuePair("subject", "mail subject")); - final URIBuilder uribuilder = new URIBuilder().setScheme("mailto").setSchemeSpecificPart("my@email.server", parameters); - final String result = uribuilder.build().toString(); - Assertions.assertTrue(result.contains("my@email.server"), "mail address as scheme specific part expected"); - Assertions.assertTrue(result.contains("mail%20subject"), "correct parameter encoding expected for that scheme"); + final URIBuilder uribuilder = new URIBuilder().setScheme("mailto").setSchemeSpecificPart("my@email.server", parameters); + final String result = uribuilder.build().toString(); + Assertions.assertTrue(result.contains("my@email.server"), "mail address as scheme specific part expected"); + Assertions.assertTrue(result.contains("mail%20subject"), "correct parameter encoding expected for that scheme"); } @Test diff --git a/httpcore5/src/test/java/org/apache/hc/core5/net/TestWWWFormCodec.java b/httpcore5/src/test/java/org/apache/hc/core5/net/TestWWWFormCodec.java index dc8e3682b6..44933476ea 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/net/TestWWWFormCodec.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/net/TestWWWFormCodec.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.net; -import static org.hamcrest.MatcherAssert.assertThat; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -36,7 +35,7 @@ import org.apache.hc.core5.http.NameValuePair; import org.apache.hc.core5.http.NameValuePairListMatcher; import org.apache.hc.core5.http.message.BasicNameValuePair; -import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class TestWWWFormCodec { @@ -50,43 +49,30 @@ private static List parse(final String params) { @Test void testParse() { - assertThat(parse(""), NameValuePairListMatcher.isEmpty()); - assertThat(parse("Name0"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name0", null))); - assertThat(parse("Name1=Value1"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name1", "Value1"))); - assertThat(parse("Name2="), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name2", ""))); - assertThat(parse(" Name3 "), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name3", null))); - assertThat(parse("Name4=Value%204%21"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value 4!"))); - assertThat(parse("Name4=Value%2B4%21"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value+4!"))); - assertThat(parse("Name4=Value%204%21%20%214"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value 4! !4"))); - assertThat(parse("Name5=aaa&Name6=bbb"), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("Name5", "aaa"), - new BasicNameValuePair("Name6", "bbb"))); - assertThat(parse("Name7=aaa&Name7=b%2Cb&Name7=ccc"), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("Name7", "aaa"), - new BasicNameValuePair("Name7", "b,b"), - new BasicNameValuePair("Name7", "ccc"))); - assertThat(parse("Name8=xx%2C%20%20yy%20%20%2Czz"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name8", "xx, yy ,zz"))); - assertThat(parse("price=10%20%E2%82%AC"), - NameValuePairListMatcher.equalsTo(new BasicNameValuePair("price", "10 \u20AC"))); - assertThat(parse("a=b\"c&d=e"), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("a", "b\"c"), - new BasicNameValuePair("d", "e"))); - assertThat(parse("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + + NameValuePairListMatcher.assertEmpty(parse("")); + NameValuePairListMatcher.assertEqualsTo(parse("Name0"), new BasicNameValuePair("Name0", null)); + NameValuePairListMatcher.assertEqualsTo(parse("Name1=Value1"), new BasicNameValuePair("Name1", "Value1")); + NameValuePairListMatcher.assertEqualsTo(parse("Name2="), new BasicNameValuePair("Name2", "")); + NameValuePairListMatcher.assertEqualsTo(parse(" Name3 "), new BasicNameValuePair("Name3", null)); + NameValuePairListMatcher.assertEqualsTo(parse("Name4=Value%204%21"), new BasicNameValuePair("Name4", "Value 4!")); + NameValuePairListMatcher.assertEqualsTo(parse("Name4=Value%2B4%21"), new BasicNameValuePair("Name4", "Value+4!")); + NameValuePairListMatcher.assertEqualsTo(parse("Name4=Value%204%21%20%214"), new BasicNameValuePair("Name4", "Value 4! !4")); + NameValuePairListMatcher.assertEqualsTo(parse("Name5=aaa&Name6=bbb"), + new BasicNameValuePair("Name5", "aaa"), + new BasicNameValuePair("Name6", "bbb")); + NameValuePairListMatcher.assertEqualsTo(parse("Name7=aaa&Name7=b%2Cb&Name7=ccc"), + new BasicNameValuePair("Name7", "aaa"), + new BasicNameValuePair("Name7", "b,b"), + new BasicNameValuePair("Name7", "ccc")); + NameValuePairListMatcher.assertEqualsTo(parse("Name8=xx%2C%20%20yy%20%20%2Czz"), new BasicNameValuePair("Name8", "xx, yy ,zz")); + NameValuePairListMatcher.assertEqualsTo(parse("price=10%20%E2%82%AC"), new BasicNameValuePair("price", "10 \u20AC")); + NameValuePairListMatcher.assertEqualsTo(parse("a=b\"c&d=e"), + new BasicNameValuePair("a", "b\"c"), + new BasicNameValuePair("d", "e")); + NameValuePairListMatcher.assertEqualsTo(parse("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8)), - NameValuePairListMatcher.equalsTo( - new BasicNameValuePair("russian", RU_HELLO), - new BasicNameValuePair("swiss", CH_HELLO))); + new BasicNameValuePair("russian", RU_HELLO), + new BasicNameValuePair("swiss", CH_HELLO)); } private static String format(final NameValuePair... nvps) { @@ -95,30 +81,25 @@ private static String format(final NameValuePair... nvps) { @Test void testFormat() { - assertThat(format(new BasicNameValuePair("Name0", null)), CoreMatchers.equalTo("Name0")); - assertThat(format(new BasicNameValuePair("Name1", "Value1")), CoreMatchers.equalTo("Name1=Value1")); - assertThat(format(new BasicNameValuePair("Name2", "")), CoreMatchers.equalTo("Name2=")); - assertThat(format(new BasicNameValuePair("Name4", "Value 4&")), - CoreMatchers.equalTo("Name4=Value+4%26")); - assertThat(format(new BasicNameValuePair("Name4", "Value+4&")), - CoreMatchers.equalTo("Name4=Value%2B4%26")); - assertThat(format(new BasicNameValuePair("Name4", "Value 4& =4")), - CoreMatchers.equalTo("Name4=Value+4%26+%3D4")); - assertThat(format( + Assertions.assertEquals("Name0", format(new BasicNameValuePair("Name0", null))); + Assertions.assertEquals("Name1=Value1", format(new BasicNameValuePair("Name1", "Value1"))); + Assertions.assertEquals("Name2=", format(new BasicNameValuePair("Name2", ""))); + Assertions.assertEquals("Name4=Value+4%26", format(new BasicNameValuePair("Name4", "Value 4&"))); + Assertions.assertEquals("Name4=Value%2B4%26", format(new BasicNameValuePair("Name4", "Value+4&"))); + Assertions.assertEquals("Name4=Value+4%26+%3D4", format(new BasicNameValuePair("Name4", "Value 4& =4"))); + Assertions.assertEquals("Name5=aaa&Name6=bbb", format( new BasicNameValuePair("Name5", "aaa"), - new BasicNameValuePair("Name6", "bbb")), CoreMatchers.equalTo("Name5=aaa&Name6=bbb")); - assertThat(format( + new BasicNameValuePair("Name6", "bbb"))); + Assertions.assertEquals("Name7=aaa&Name7=b%2Cb&Name7=ccc", format( new BasicNameValuePair("Name7", "aaa"), new BasicNameValuePair("Name7", "b,b"), new BasicNameValuePair("Name7", "ccc") - ), CoreMatchers.equalTo("Name7=aaa&Name7=b%2Cb&Name7=ccc")); - assertThat(format(new BasicNameValuePair("Name8", "xx, yy ,zz")), - CoreMatchers.equalTo("Name8=xx%2C++yy++%2Czz")); - assertThat(format( + )); + Assertions.assertEquals("Name8=xx%2C++yy++%2Czz", format(new BasicNameValuePair("Name8", "xx, yy ,zz"))); + Assertions.assertEquals("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + + "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8), format( new BasicNameValuePair("russian", RU_HELLO), - new BasicNameValuePair("swiss", CH_HELLO)), - CoreMatchers.equalTo("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + - "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8))); + new BasicNameValuePair("swiss", CH_HELLO))); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/reactor/TestAbstractIOSessionPool.java b/httpcore5/src/test/java/org/apache/hc/core5/reactor/TestAbstractIOSessionPool.java index 581b79c308..ef188cf87b 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/reactor/TestAbstractIOSessionPool.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/reactor/TestAbstractIOSessionPool.java @@ -26,7 +26,6 @@ */ package org.apache.hc.core5.reactor; -import static org.hamcrest.MatcherAssert.assertThat; import java.net.UnknownHostException; import java.util.concurrent.Future; @@ -36,7 +35,6 @@ import org.apache.hc.core5.io.CloseMode; import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.Timeout; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -90,9 +88,9 @@ void testGetSessions() throws Exception { Mockito.when(ioSession1.isOpen()).thenReturn(true); final Future future1 = impl.getSession("somehost", Timeout.ofSeconds(123L), null); - assertThat(future1, CoreMatchers.notNullValue()); - assertThat(future1.isDone(), CoreMatchers.equalTo(false)); - assertThat(impl.getRoutes(), CoreMatchers.hasItem("somehost")); + Assertions.assertNotNull(future1); + Assertions.assertFalse(future1.isDone()); + Assertions.assertTrue(impl.getRoutes().contains("somehost")); Mockito.verify(impl).connectSession( ArgumentMatchers.eq("somehost"), @@ -100,9 +98,9 @@ void testGetSessions() throws Exception { ArgumentMatchers.any()); final Future future2 = impl.getSession("somehost", Timeout.ofSeconds(123L), null); - assertThat(future2, CoreMatchers.notNullValue()); - assertThat(future2.isDone(), CoreMatchers.equalTo(false)); - assertThat(impl.getRoutes(), CoreMatchers.hasItem("somehost")); + Assertions.assertNotNull(future2); + Assertions.assertFalse(future2.isDone()); + Assertions.assertTrue(impl.getRoutes().contains("somehost")); Mockito.verify(impl, Mockito.times(1)).connectSession( ArgumentMatchers.eq("somehost"), @@ -112,11 +110,11 @@ void testGetSessions() throws Exception { return true; })); - assertThat(future1.isDone(), CoreMatchers.equalTo(true)); - assertThat(future1.get(), CoreMatchers.sameInstance(ioSession1)); + Assertions.assertTrue(future1.isDone()); + Assertions.assertSame(ioSession1, future1.get()); - assertThat(future2.isDone(), CoreMatchers.equalTo(true)); - assertThat(future2.get(), CoreMatchers.sameInstance(ioSession1)); + Assertions.assertTrue(future2.isDone()); + Assertions.assertSame(ioSession1, future2.get()); Mockito.verify(impl, Mockito.times(2)).validateSession(ArgumentMatchers.any(), ArgumentMatchers.any()); @@ -129,8 +127,8 @@ void testGetSessions() throws Exception { Mockito.verify(impl, Mockito.times(3)).validateSession(ArgumentMatchers.any(), ArgumentMatchers.any()); - assertThat(future3.isDone(), CoreMatchers.equalTo(true)); - assertThat(future3.get(), CoreMatchers.sameInstance(ioSession1)); + Assertions.assertEquals(true, future3.isDone()); + Assertions.assertSame(ioSession1, future3.get()); } @Test @@ -142,9 +140,9 @@ void testGetSessionConnectFailure() { ArgumentMatchers.any())).thenReturn(connectFuture); final Future future1 = impl.getSession("somehost", Timeout.ofSeconds(123L), null); - assertThat(future1, CoreMatchers.notNullValue()); - assertThat(future1.isDone(), CoreMatchers.equalTo(false)); - assertThat(impl.getRoutes(), CoreMatchers.hasItem("somehost")); + Assertions.assertNotNull(future1); + Assertions.assertFalse(future1.isDone()); + Assertions.assertTrue(impl.getRoutes().contains("somehost")); Mockito.verify(impl).connectSession( ArgumentMatchers.eq("somehost"), @@ -152,31 +150,31 @@ void testGetSessionConnectFailure() { connectCallbackCaptor.capture()); final Future future2 = impl.getSession("somehost", Timeout.ofSeconds(123L), null); - assertThat(future2, CoreMatchers.notNullValue()); - assertThat(future2.isDone(), CoreMatchers.equalTo(false)); - assertThat(impl.getRoutes(), CoreMatchers.hasItem("somehost")); + Assertions.assertNotNull(future2); + Assertions.assertFalse(future2.isDone()); + Assertions.assertTrue(impl.getRoutes().contains("somehost")); final FutureCallback connectCallback = connectCallbackCaptor.getValue(); Assertions.assertNotNull(connectCallback); connectCallback.failed(new Exception("Boom")); // Ensure connect failure invalidates all pending futures - assertThat(future1.isDone(), CoreMatchers.equalTo(true)); - assertThat(future2.isDone(), CoreMatchers.equalTo(true)); + Assertions.assertTrue(future1.isDone()); + Assertions.assertTrue(future2.isDone()); } @Test void testShutdownPool() { final AbstractIOSessionPool.PoolEntry entry1 = impl.getPoolEntry("host1"); - assertThat(entry1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry1); entry1.session = ioSession1; final AbstractIOSessionPool.PoolEntry entry2 = impl.getPoolEntry("host2"); - assertThat(entry2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry2); entry2.session = ioSession2; final AbstractIOSessionPool.PoolEntry entry3 = impl.getPoolEntry("host3"); - assertThat(entry3, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry3); entry3.sessionFuture = connectFuture; entry3.requestQueue.add(callback1); entry3.requestQueue.add(callback2); @@ -193,11 +191,11 @@ void testShutdownPool() { @Test void testCloseIdleSessions() { final AbstractIOSessionPool.PoolEntry entry1 = impl.getPoolEntry("host1"); - assertThat(entry1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry1); entry1.session = ioSession1; final AbstractIOSessionPool.PoolEntry entry2 = impl.getPoolEntry("host2"); - assertThat(entry2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry2); entry2.session = ioSession2; impl.closeIdle(TimeValue.ZERO_MILLISECONDS); @@ -205,18 +203,18 @@ void testCloseIdleSessions() { Mockito.verify(impl).closeSession(ioSession1, CloseMode.GRACEFUL); Mockito.verify(impl).closeSession(ioSession2, CloseMode.GRACEFUL); - assertThat(entry1.session, CoreMatchers.nullValue()); - assertThat(entry2.session, CoreMatchers.nullValue()); + Assertions.assertNull(entry1.session); + Assertions.assertNull(entry2.session); } @Test void testEnumSessions() { final AbstractIOSessionPool.PoolEntry entry1 = impl.getPoolEntry("host1"); - assertThat(entry1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry1); entry1.session = ioSession1; final AbstractIOSessionPool.PoolEntry entry2 = impl.getPoolEntry("host2"); - assertThat(entry2, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry2); entry2.session = ioSession2; impl.enumAvailable(ioSession -> ioSession.close(CloseMode.GRACEFUL)); @@ -227,7 +225,7 @@ void testEnumSessions() { @Test void testGetSessionReconnectAfterValidate() { final AbstractIOSessionPool.PoolEntry entry1 = impl.getPoolEntry("somehost"); - assertThat(entry1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry1); entry1.session = ioSession1; Mockito.when(ioSession1.isOpen()).thenReturn(true); @@ -248,7 +246,7 @@ void testGetSessionReconnectAfterValidate() { @Test void testGetSessionReconnectIfClosed() { final AbstractIOSessionPool.PoolEntry entry1 = impl.getPoolEntry("somehost"); - assertThat(entry1, CoreMatchers.notNullValue()); + Assertions.assertNotNull(entry1); entry1.session = ioSession1; Mockito.when(ioSession1.isOpen()).thenReturn(false); @@ -274,12 +272,12 @@ void testGetSessionConnectUnknownHost() { }))).thenReturn(connectFuture); final Future future1 = impl.getSession("somehost", Timeout.ofSeconds(123L), null); - assertThat(future1, CoreMatchers.notNullValue()); - assertThat(future1.isDone(), CoreMatchers.equalTo(true)); + Assertions.assertNotNull(future1); + Assertions.assertTrue(future1.isDone()); final Future future2 = impl.getSession("somehost", Timeout.ofSeconds(123L), null); - assertThat(future2, CoreMatchers.notNullValue()); - assertThat(future2.isDone(), CoreMatchers.equalTo(true)); + Assertions.assertNotNull(future2); + Assertions.assertTrue(future2.isDone()); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java index 9c2a1b8ee2..72bd74e93b 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java @@ -27,13 +27,11 @@ package org.apache.hc.core5.util; -import static org.hamcrest.MatcherAssert.assertThat; import java.text.ParseException; import java.time.Duration; import java.util.concurrent.TimeUnit; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -299,19 +297,19 @@ void testEqualsAndHashCode() { final TimeValue tv4 = TimeValue.ofSeconds(1L); final TimeValue tv5 = TimeValue.ofSeconds(1000L); - assertThat(tv1.equals(tv1), CoreMatchers.equalTo(true)); - assertThat(tv1.equals(null), CoreMatchers.equalTo(false)); - assertThat(tv1.equals(tv2), CoreMatchers.equalTo(false)); - assertThat(tv1.equals(tv3), CoreMatchers.equalTo(true)); - assertThat(tv1.equals(tv4), CoreMatchers.equalTo(true)); - assertThat(tv4.equals(tv1), CoreMatchers.equalTo(true)); - assertThat(tv1.equals(tv5), CoreMatchers.equalTo(false)); + Assertions.assertEquals(tv1, tv1); + Assertions.assertNotEquals(null, tv1); + Assertions.assertNotEquals(tv1, tv2); + Assertions.assertEquals(tv1, tv3); + Assertions.assertEquals(tv1, tv4); + Assertions.assertEquals(tv4, tv1); + Assertions.assertNotEquals(tv1, tv5); - assertThat(tv1.hashCode() == tv2.hashCode(), CoreMatchers.equalTo(false)); - assertThat(tv1.hashCode() == tv3.hashCode(), CoreMatchers.equalTo(true)); - assertThat(tv1.hashCode() == tv4.hashCode(), CoreMatchers.equalTo(true)); - assertThat(tv4.hashCode() == tv1.hashCode(), CoreMatchers.equalTo(true)); - assertThat(tv1.hashCode() == tv5.hashCode(), CoreMatchers.equalTo(false)); + Assertions.assertNotEquals(tv1.hashCode(), tv2.hashCode()); + Assertions.assertEquals(tv1.hashCode(), tv3.hashCode()); + Assertions.assertEquals(tv1.hashCode(), tv4.hashCode()); + Assertions.assertEquals(tv4.hashCode(), tv1.hashCode()); + Assertions.assertNotEquals(tv1.hashCode(), tv5.hashCode()); } @Test @@ -323,13 +321,13 @@ void testCompareTo() { final TimeValue tv5 = TimeValue.ofSeconds(60L); final TimeValue tv6 = TimeValue.ofMinutes(1L); - assertThat(tv1.compareTo(tv1) == 0, CoreMatchers.equalTo(true)); - assertThat(tv1.compareTo(tv2) < 0, CoreMatchers.equalTo(true)); - assertThat(tv1.compareTo(tv3) == 0, CoreMatchers.equalTo(true)); - assertThat(tv1.compareTo(tv4) == 0, CoreMatchers.equalTo(true)); - assertThat(tv1.compareTo(tv5) < 0, CoreMatchers.equalTo(true)); - assertThat(tv6.compareTo(tv5) == 0, CoreMatchers.equalTo(true)); - assertThat(tv6.compareTo(tv4) > 0, CoreMatchers.equalTo(true)); + Assertions.assertEquals(true, tv1.compareTo(tv1) == 0); + Assertions.assertEquals(true, tv1.compareTo(tv2) < 0); + Assertions.assertEquals(true, tv1.compareTo(tv3) == 0); + Assertions.assertEquals(true, tv1.compareTo(tv4) == 0); + Assertions.assertEquals(true, tv1.compareTo(tv5) < 0); + Assertions.assertEquals(true, tv6.compareTo(tv5) == 0); + Assertions.assertEquals(true, tv6.compareTo(tv4) > 0); Assertions.assertThrows(NullPointerException.class, () -> tv1.compareTo(null)); } diff --git a/pom.xml b/pom.xml index 224f1fd01a..5139685f28 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,6 @@ true 2.5.2 5.14.2 - 3.0 5.0.0 4.11.0 1.7.36 @@ -125,12 +124,6 @@ pom import - - org.hamcrest - hamcrest - ${hamcrest.version} - test - org.mockito mockito-core