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
-
- org.hamcrest
- hamcrest
- ${hamcrest.version}
- test
-
org.mockito
mockito-core