You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/05/24 16:45:57 UTC

[httpcomponents-client] branch master updated (8580d7f -> e8b0ec6)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.


    from 8580d7f  Redundant type declarations
     new 1c171e1  Upgraded JUnit to version 4.13
     new 82432f5  Removed references to deprecated Assert#assertThat
     new e8b0ec6  Updated test cases with exception asserts

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../TestAbstractSerializingAsyncCacheStorage.java  |  23 ++---
 .../cache/TestAbstractSerializingCacheStorage.java |  23 ++---
 .../cache/TestByteArrayCacheEntrySerializer.java   |   4 +-
 .../http/impl/cache/TestCacheRevalidatorBase.java  |   9 +-
 .../http/impl/cache/TestCacheUpdateHandler.java    |  26 +++---
 .../TestHttpByteArrayCacheEntrySerializer.java     |  55 ++++++-----
 .../impl/cache/TestResponseProtocolCompliance.java |   6 +-
 .../http/schedule/TestConcurrentCountMap.java      |   6 +-
 .../async/AbstractHttpAsyncFundamentalsTest.java   |  36 +++----
 .../async/AbstractHttpAsyncRedirectsTest.java      |  42 ++++-----
 .../AbstractHttpReactiveFundamentalsTest.java      |  29 +++---
 .../hc/client5/testing/async/TestHttp1Async.java   |  34 +++----
 .../client5/testing/async/TestHttp1Reactive.java   |  36 +++----
 .../testing/async/TestHttp1RequestReExecution.java |  10 +-
 .../testing/async/TestHttpAsyncMinimal.java        |   8 +-
 .../testing/async/TestHttpMinimalReactive.java     |   8 +-
 .../hc/client5/testing/fluent/TestFluent.java      |   5 +-
 .../testing/sync/TestBasicConnectionManager.java   |   5 +-
 .../testing/sync/TestClientRequestExecution.java   |   5 +-
 .../hc/client5/testing/sync/TestRedirects.java     |  52 ++++-------
 .../client5/testing/sync/TestSSLSocketFactory.java |  36 ++++---
 .../http/classic/methods/TestHttpTrace.java        |   6 +-
 .../hc/client5/http/cookie/TestCookieOrigin.java   |  24 ++---
 .../hc/client5/http/entity/TestEntityBuilder.java  |   7 +-
 .../http/entity/mime/HttpRFC7578MultipartTest.java |  14 +--
 .../impl/TestDefaultConnKeepAliveStrategy.java     |   5 +-
 .../http/impl/TestDefaultRedirectStrategy.java     |  15 +--
 .../hc/client5/http/impl/TestProtocolSupport.java  |  12 +--
 .../http/impl/auth/TestAuthChallengeParser.java    | 104 +++++++++++----------
 .../client5/http/impl/auth/TestBasicAuthCache.java |   5 +-
 .../client5/http/impl/auth/TestDigestScheme.java   |  37 +++++---
 .../http/impl/auth/TestHttpAuthenticator.java      |   2 +-
 .../http/impl/auth/TestRequestAuthCache.java       |  10 +-
 .../http/impl/classic/TestCloseableHttpClient.java |  38 ++++----
 .../client5/http/impl/classic/TestConnectExec.java |  25 +++--
 .../impl/classic/TestContentCompressionExec.java   |   5 +-
 .../classic/TestFutureRequestExecutionService.java |  20 ++--
 .../impl/classic/TestHttpRequestRetryExec.java     |  68 ++++++--------
 .../http/impl/classic/TestInternalExecRuntime.java |  15 +--
 .../http/impl/classic/TestInternalHttpClient.java  |   5 +-
 .../http/impl/classic/TestMainClientExec.java      |  44 ++++-----
 .../http/impl/classic/TestProtocolExec.java        |  33 +++----
 .../http/impl/classic/TestRedirectExec.java        |  39 ++++----
 .../impl/cookie/TestBasicCookieAttribHandlers.java |  10 +-
 .../impl/cookie/TestLaxCookieAttribHandlers.java   |  60 +++++++-----
 .../http/impl/cookie/TestRFC6265CookieSpec.java    |  10 +-
 .../io/TestBasicHttpClientConnectionManager.java   |  15 +--
 .../impl/io/TestHttpClientConnectionOperator.java  |  23 +++--
 .../io/TestPoolingHttpClientConnectionManager.java |  10 +-
 .../http/impl/routing/TestDefaultRoutePlanner.java |   5 +-
 .../http/impl/routing/TestRouteDirector.java       |   5 +-
 .../http/impl/routing/TestRoutingSupport.java      |  10 +-
 .../http/protocol/TestRequestAddCookies.java       |  10 +-
 .../protocol/TestRequestClientConnControl.java     |   5 +-
 .../http/protocol/TestRequestDefaultHeaders.java   |   5 +-
 .../http/protocol/TestResponseProcessCookies.java  |  10 +-
 .../http/ssl/TestDistinguishedNameParser.java      |  22 ++---
 .../apache/hc/client5/http/utils/TesDnsUtils.java  |  18 ++--
 .../hc/client5/http/utils/TestDateUtils.java       |  25 ++---
 pom.xml                                            |   2 +-
 60 files changed, 628 insertions(+), 608 deletions(-)

[httpcomponents-client] 02/03: Removed references to deprecated Assert#assertThat

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 82432f50d9c068d3bf71476915f757017f366ce4
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon May 24 16:54:03 2021 +0200

    Removed references to deprecated Assert#assertThat
---
 .../TestAbstractSerializingAsyncCacheStorage.java  | 23 +++---
 .../cache/TestAbstractSerializingCacheStorage.java | 23 +++---
 .../cache/TestByteArrayCacheEntrySerializer.java   |  4 +-
 .../http/impl/cache/TestCacheRevalidatorBase.java  |  9 ++-
 .../http/impl/cache/TestCacheUpdateHandler.java    | 26 +++----
 .../http/schedule/TestConcurrentCountMap.java      |  6 +-
 .../async/AbstractHttpAsyncFundamentalsTest.java   | 36 ++++-----
 .../AbstractHttpReactiveFundamentalsTest.java      | 29 +++----
 .../hc/client5/testing/async/TestHttp1Async.java   | 34 ++++-----
 .../client5/testing/async/TestHttp1Reactive.java   | 36 ++++-----
 .../testing/async/TestHttp1RequestReExecution.java | 10 +--
 .../testing/async/TestHttpAsyncMinimal.java        |  8 +-
 .../testing/async/TestHttpMinimalReactive.java     |  8 +-
 .../hc/client5/testing/sync/TestRedirects.java     |  7 +-
 .../hc/client5/http/impl/TestProtocolSupport.java  | 12 +--
 .../http/impl/auth/TestAuthChallengeParser.java    | 89 +++++++++++-----------
 .../http/impl/auth/TestHttpAuthenticator.java      |  2 +-
 .../http/impl/routing/TestRoutingSupport.java      |  6 +-
 .../http/ssl/TestDistinguishedNameParser.java      | 22 +++---
 .../apache/hc/client5/http/utils/TesDnsUtils.java  | 18 ++---
 .../hc/client5/http/utils/TestDateUtils.java       | 25 +++---
 21 files changed, 220 insertions(+), 213 deletions(-)

diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
index 6dc2048..921ad6c 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
@@ -42,6 +42,7 @@ import org.apache.hc.client5.http.cache.ResourceIOException;
 import org.apache.hc.core5.concurrent.Cancellable;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -116,7 +117,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
         impl.getEntry(key, cacheEntryCallback);
         final ArgumentCaptor<HttpCacheEntry> argumentCaptor = ArgumentCaptor.forClass(HttpCacheEntry.class);
         Mockito.verify(cacheEntryCallback).completed(argumentCaptor.capture());
-        Assert.assertThat(argumentCaptor.getValue(), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(argumentCaptor.getValue(), CoreMatchers.nullValue());
         Mockito.verify(impl).restore(ArgumentMatchers.eq("bar"), ArgumentMatchers.any());
     }
 
@@ -136,7 +137,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
         final ArgumentCaptor<HttpCacheEntry> argumentCaptor = ArgumentCaptor.forClass(HttpCacheEntry.class);
         Mockito.verify(cacheEntryCallback).completed(argumentCaptor.capture());
         final HttpCacheEntry resultingEntry = argumentCaptor.getValue();
-        Assert.assertThat(resultingEntry, HttpCacheEntryMatcher.equivalent(value));
+        MatcherAssert.assertThat(resultingEntry, HttpCacheEntryMatcher.equivalent(value));
         Mockito.verify(impl).restore(ArgumentMatchers.eq("bar"), ArgumentMatchers.any());
     }
 
@@ -154,7 +155,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
         impl.getEntry(key, cacheEntryCallback);
         final ArgumentCaptor<HttpCacheEntry> argumentCaptor = ArgumentCaptor.forClass(HttpCacheEntry.class);
         Mockito.verify(cacheEntryCallback).completed(argumentCaptor.capture());
-        Assert.assertThat(argumentCaptor.getValue(), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(argumentCaptor.getValue(), CoreMatchers.nullValue());
         Mockito.verify(impl).restore(ArgumentMatchers.eq("bar"), ArgumentMatchers.any());
     }
 
@@ -197,7 +198,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
                 });
 
         impl.updateEntry(key, existing -> {
-            Assert.assertThat(existing, CoreMatchers.nullValue());
+            MatcherAssert.assertThat(existing, CoreMatchers.nullValue());
             return updatedValue;
         }, operationCallback);
 
@@ -261,7 +262,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
                 });
 
         impl.updateEntry(key, existing -> {
-            Assert.assertThat(existing, CoreMatchers.nullValue());
+            MatcherAssert.assertThat(existing, CoreMatchers.nullValue());
             return updatedValue;
         }, operationCallback);
 
@@ -383,9 +384,9 @@ public class TestAbstractSerializingAsyncCacheStorage {
         Mockito.verify(bulkCacheEntryCallback).completed(argumentCaptor.capture());
 
         final Map<String, HttpCacheEntry> entryMap = argumentCaptor.getValue();
-        Assert.assertThat(entryMap, CoreMatchers.notNullValue());
-        Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
-        Assert.assertThat(entryMap.get(key2), HttpCacheEntryMatcher.equivalent(value2));
+        MatcherAssert.assertThat(entryMap, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
+        MatcherAssert.assertThat(entryMap.get(key2), HttpCacheEntryMatcher.equivalent(value2));
 
         verify(impl, Mockito.times(2)).digestToStorageKey(key1);
         verify(impl, Mockito.times(2)).digestToStorageKey(key2);
@@ -428,9 +429,9 @@ public class TestAbstractSerializingAsyncCacheStorage {
         Mockito.verify(bulkCacheEntryCallback).completed(argumentCaptor.capture());
 
         final Map<String, HttpCacheEntry> entryMap = argumentCaptor.getValue();
-        Assert.assertThat(entryMap, CoreMatchers.notNullValue());
-        Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
-        Assert.assertThat(entryMap.get(key2), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(entryMap, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
+        MatcherAssert.assertThat(entryMap.get(key2), CoreMatchers.nullValue());
 
         verify(impl, Mockito.times(2)).digestToStorageKey(key1);
         verify(impl, Mockito.times(2)).digestToStorageKey(key2);
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
index db4c690..6747301 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
@@ -40,6 +40,7 @@ import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
 import org.apache.hc.client5.http.cache.HttpCacheUpdateException;
 import org.apache.hc.client5.http.cache.ResourceIOException;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -90,7 +91,7 @@ public class TestAbstractSerializingCacheStorage {
 
         verify(impl).restore("bar");
 
-        Assert.assertThat(resultingEntry, CoreMatchers.nullValue());
+        MatcherAssert.assertThat(resultingEntry, CoreMatchers.nullValue());
     }
 
     @Test
@@ -105,7 +106,7 @@ public class TestAbstractSerializingCacheStorage {
 
         verify(impl).restore("bar");
 
-        Assert.assertThat(resultingEntry, HttpCacheEntryMatcher.equivalent(value));
+        MatcherAssert.assertThat(resultingEntry, HttpCacheEntryMatcher.equivalent(value));
     }
 
     @Test
@@ -120,7 +121,7 @@ public class TestAbstractSerializingCacheStorage {
 
         verify(impl).restore("bar");
 
-        Assert.assertThat(resultingEntry, CoreMatchers.nullValue());
+        MatcherAssert.assertThat(resultingEntry, CoreMatchers.nullValue());
     }
 
     @Test
@@ -142,7 +143,7 @@ public class TestAbstractSerializingCacheStorage {
         when(impl.getForUpdateCAS("bar")).thenReturn(null);
 
         impl.updateEntry(key, existing -> {
-            Assert.assertThat(existing, CoreMatchers.nullValue());
+            MatcherAssert.assertThat(existing, CoreMatchers.nullValue());
             return updatedValue;
         });
 
@@ -180,7 +181,7 @@ public class TestAbstractSerializingCacheStorage {
         when(impl.updateCAS(ArgumentMatchers.eq("bar"), ArgumentMatchers.eq("stuff"), ArgumentMatchers.any())).thenReturn(true);
 
         impl.updateEntry(key, existing -> {
-            Assert.assertThat(existing, CoreMatchers.nullValue());
+            MatcherAssert.assertThat(existing, CoreMatchers.nullValue());
             return updatedValue;
         });
 
@@ -254,9 +255,9 @@ public class TestAbstractSerializingCacheStorage {
         });
 
         final Map<String, HttpCacheEntry> entryMap = impl.getEntries(Arrays.asList(key1, key2));
-        Assert.assertThat(entryMap, CoreMatchers.notNullValue());
-        Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
-        Assert.assertThat(entryMap.get(key2), HttpCacheEntryMatcher.equivalent(value2));
+        MatcherAssert.assertThat(entryMap, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
+        MatcherAssert.assertThat(entryMap.get(key2), HttpCacheEntryMatcher.equivalent(value2));
 
         verify(impl, Mockito.times(2)).digestToStorageKey(key1);
         verify(impl, Mockito.times(2)).digestToStorageKey(key2);
@@ -288,9 +289,9 @@ public class TestAbstractSerializingCacheStorage {
         });
 
         final Map<String, HttpCacheEntry> entryMap = impl.getEntries(Arrays.asList(key1, key2));
-        Assert.assertThat(entryMap, CoreMatchers.notNullValue());
-        Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
-        Assert.assertThat(entryMap.get(key2), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(entryMap, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
+        MatcherAssert.assertThat(entryMap.get(key2), CoreMatchers.nullValue());
 
         verify(impl, Mockito.times(2)).digestToStorageKey(key1);
         verify(impl, Mockito.times(2)).digestToStorageKey(key2);
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestByteArrayCacheEntrySerializer.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestByteArrayCacheEntrySerializer.java
index 2ea0e44..59d4881 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestByteArrayCacheEntrySerializer.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestByteArrayCacheEntrySerializer.java
@@ -28,7 +28,6 @@ package org.apache.hc.client5.http.impl.cache;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
@@ -47,6 +46,7 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.StatusLine;
+import org.hamcrest.MatcherAssert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -253,7 +253,7 @@ public class TestByteArrayCacheEntrySerializer {
         final HttpCacheStorageEntry readEntry = impl.deserialize(bytes);
         // compare
         assertEquals(readEntry.getKey(), writeEntry.getKey());
-        assertThat(readEntry.getContent(), HttpCacheEntryMatcher.equivalent(writeEntry.getContent()));
+        MatcherAssert. assertThat(readEntry.getContent(), HttpCacheEntryMatcher.equivalent(writeEntry.getContent()));
     }
 
     private HttpCacheStorageEntry makeCacheEntryWithVariantMap(final String key) {
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheRevalidatorBase.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheRevalidatorBase.java
index 787a022..980149c 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheRevalidatorBase.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheRevalidatorBase.java
@@ -40,6 +40,7 @@ import org.apache.hc.core5.http.message.BasicHttpResponse;
 import org.apache.hc.core5.util.TimeValue;
 import org.apache.hc.core5.util.Timeout;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -128,18 +129,18 @@ public class TestCacheRevalidatorBase {
     public void testStaleResponse() {
         final HttpResponse response1 = new BasicHttpResponse(HttpStatus.SC_OK);
         response1.addHeader(HeaderConstants.WARNING, "110 localhost \"Response is stale\"");
-        Assert.assertThat(impl.isStale(response1), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(impl.isStale(response1), CoreMatchers.equalTo(true));
 
         final HttpResponse response2 = new BasicHttpResponse(HttpStatus.SC_OK);
         response2.addHeader(HeaderConstants.WARNING, "111 localhost \"Revalidation failed\"");
-        Assert.assertThat(impl.isStale(response2), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(impl.isStale(response2), CoreMatchers.equalTo(true));
 
         final HttpResponse response3 = new BasicHttpResponse(HttpStatus.SC_OK);
         response3.addHeader(HeaderConstants.WARNING, "xxx localhost \"Huh?\"");
-        Assert.assertThat(impl.isStale(response3), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(impl.isStale(response3), CoreMatchers.equalTo(false));
 
         final HttpResponse response4 = new BasicHttpResponse(HttpStatus.SC_OK);
-        Assert.assertThat(impl.isStale(response4), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(impl.isStale(response4), CoreMatchers.equalTo(false));
     }
 
     @Test
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
index 26b441f..fb8f9dd 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
@@ -28,7 +28,6 @@ package org.apache.hc.client5.http.impl.cache;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -43,6 +42,7 @@ import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.hamcrest.MatcherAssert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -96,8 +96,8 @@ public class TestCacheUpdateHandler {
         final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
                 new Date(), new Date(), response);
 
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(responseDate)));
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(responseDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
     }
 
     @Test
@@ -116,10 +116,10 @@ public class TestCacheUpdateHandler {
         final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
                 new Date(), new Date(), response);
 
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(requestDate)));
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatDate(responseDate)));
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("Cache-Control", "public"));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(requestDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatDate(responseDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Cache-Control", "public"));
     }
 
     @Test
@@ -136,10 +136,10 @@ public class TestCacheUpdateHandler {
         final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
                 new Date(), new Date(), response);
 
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(requestDate)));
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatDate(responseDate)));
-        assertThat(updatedEntry, ContainsHeaderMatcher.contains("Cache-Control", "public"));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(requestDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatDate(responseDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Cache-Control", "public"));
     }
 
     @Test
@@ -154,8 +154,8 @@ public class TestCacheUpdateHandler {
         response.setHeader("ETag", "\"old-etag\"");
         final HttpCacheEntry result = impl.updateCacheEntry("A", entry, new Date(),
                 new Date(), response);
-        assertThat(result, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(oneSecondAgo)));
-        assertThat(result, ContainsHeaderMatcher.contains("ETag", "\"new-etag\""));
+        MatcherAssert. assertThat(result, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(oneSecondAgo)));
+        MatcherAssert. assertThat(result, ContainsHeaderMatcher.contains("ETag", "\"new-etag\""));
     }
 
     @Test
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/schedule/TestConcurrentCountMap.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/schedule/TestConcurrentCountMap.java
index 3c07190..9781b0d 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/schedule/TestConcurrentCountMap.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/schedule/TestConcurrentCountMap.java
@@ -27,7 +27,7 @@
 package org.apache.hc.client5.http.schedule;
 
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
 public class TestConcurrentCountMap
@@ -41,10 +41,10 @@ public class TestConcurrentCountMap
     public void testBasics() {
         map.increaseCount(IDENTIFIER);
         map.increaseCount(IDENTIFIER);
-        Assert.assertThat(map.getCount(IDENTIFIER), CoreMatchers.equalTo(2));
+        MatcherAssert.assertThat(map.getCount(IDENTIFIER), CoreMatchers.equalTo(2));
 
         map.resetCount(IDENTIFIER);
-        Assert.assertThat(map.getCount(IDENTIFIER), CoreMatchers.equalTo(0));
+        MatcherAssert.assertThat(map.getCount(IDENTIFIER), CoreMatchers.equalTo(0));
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java
index 446151a..d85b6dd 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java
@@ -52,7 +52,7 @@ import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityConsumer;
 import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
 import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
 public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpAsyncClient> extends AbstractIntegrationTestBase<T> {
@@ -71,11 +71,11 @@ public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpA
                             .setPath("/random/2048")
                             .build(), null);
             final SimpleHttpResponse response = future.get();
-            Assert.assertThat(response, CoreMatchers.notNullValue());
-            Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
             final String body = response.getBodyText();
-            Assert.assertThat(body, CoreMatchers.notNullValue());
-            Assert.assertThat(body.length(), CoreMatchers.equalTo(2048));
+            MatcherAssert.assertThat(body, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(body.length(), CoreMatchers.equalTo(2048));
         }
     }
 
@@ -89,10 +89,10 @@ public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpA
                             .setPath("/random/2048")
                             .build(), null);
             final SimpleHttpResponse response = future.get();
-            Assert.assertThat(response, CoreMatchers.notNullValue());
-            Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
             final String body = response.getBodyText();
-            Assert.assertThat(body, CoreMatchers.nullValue());
+            MatcherAssert.assertThat(body, CoreMatchers.nullValue());
         }
     }
 
@@ -108,11 +108,11 @@ public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpA
                             AsyncEntityProducers.create(b1, ContentType.APPLICATION_OCTET_STREAM)),
                     new BasicResponseConsumer<>(new BasicAsyncEntityConsumer()), HttpClientContext.create(), null);
             final Message<HttpResponse, byte[]> responseMessage = future.get();
-            Assert.assertThat(responseMessage, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(responseMessage, CoreMatchers.notNullValue());
             final HttpResponse response = responseMessage.getHead();
-            Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
             final byte[] b2 = responseMessage.getBody();
-            Assert.assertThat(b1, CoreMatchers.equalTo(b2));
+            MatcherAssert.assertThat(b1, CoreMatchers.equalTo(b2));
         }
     }
 
@@ -137,11 +137,11 @@ public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpA
         while (!queue.isEmpty()) {
             final Future<Message<HttpResponse, byte[]>> future = queue.remove();
             final Message<HttpResponse, byte[]> responseMessage = future.get();
-            Assert.assertThat(responseMessage, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(responseMessage, CoreMatchers.notNullValue());
             final HttpResponse response = responseMessage.getHead();
-            Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
             final byte[] b2 = responseMessage.getBody();
-            Assert.assertThat(b1, CoreMatchers.equalTo(b2));
+            MatcherAssert.assertThat(b1, CoreMatchers.equalTo(b2));
         }
     }
 
@@ -196,7 +196,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpA
             });
         }
 
-        Assert.assertThat(countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()), CoreMatchers.equalTo(true));
 
         executorService.shutdownNow();
         executorService.awaitTermination(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
@@ -206,7 +206,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpA
             if (response == null) {
                 break;
             }
-            Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
         }
     }
 
@@ -219,8 +219,8 @@ public abstract class AbstractHttpAsyncFundamentalsTest<T extends CloseableHttpA
                         .setPath("/random/boom")
                         .build(), null);
         final SimpleHttpResponse response = future.get();
-        Assert.assertThat(response, CoreMatchers.notNullValue());
-        Assert.assertThat(response.getCode(), CoreMatchers.equalTo(400));
+        MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(400));
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpReactiveFundamentalsTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpReactiveFundamentalsTest.java
index 3fff89e..77ddbb7 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpReactiveFundamentalsTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpReactiveFundamentalsTest.java
@@ -62,6 +62,7 @@ import org.apache.hc.core5.testing.reactive.ReactiveTestUtils;
 import org.apache.hc.core5.testing.reactive.ReactiveTestUtils.StreamDescription;
 import org.apache.hc.core5.util.TextUtils;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Test;
 import org.reactivestreams.Publisher;
@@ -89,12 +90,12 @@ public abstract class AbstractHttpReactiveFundamentalsTest<T extends CloseableHt
             httpclient.execute(AsyncRequestBuilder.get(target + "/random/2048").build(), consumer, null);
 
             final Message<HttpResponse, Publisher<ByteBuffer>> response = consumer.getResponseFuture().get();
-            Assert.assertThat(response, CoreMatchers.notNullValue());
-            Assert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
 
             final String body = publisherToString(response.getBody());
-            Assert.assertThat(body, CoreMatchers.notNullValue());
-            Assert.assertThat(body.length(), CoreMatchers.equalTo(2048));
+            MatcherAssert.assertThat(body, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(body.length(), CoreMatchers.equalTo(2048));
         }
     }
 
@@ -107,11 +108,11 @@ public abstract class AbstractHttpReactiveFundamentalsTest<T extends CloseableHt
             httpclient.execute(AsyncRequestBuilder.head(target + "/random/2048").build(), consumer, null);
 
             final Message<HttpResponse, Publisher<ByteBuffer>> response = consumer.getResponseFuture().get();
-            Assert.assertThat(response, CoreMatchers.notNullValue());
-            Assert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
 
             final String body = publisherToString(response.getBody());
-            Assert.assertThat(body, CoreMatchers.nullValue());
+            MatcherAssert.assertThat(body, CoreMatchers.nullValue());
         }
     }
 
@@ -132,11 +133,11 @@ public abstract class AbstractHttpReactiveFundamentalsTest<T extends CloseableHt
 
             final Future<Message<HttpResponse, Publisher<ByteBuffer>>> responseFuture = consumer.getResponseFuture();
             final Message<HttpResponse, Publisher<ByteBuffer>> responseMessage = responseFuture.get();
-            Assert.assertThat(responseMessage, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(responseMessage, CoreMatchers.notNullValue());
             final HttpResponse response = responseMessage.getHead();
-            Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
             final byte[] b2 = publisherToByteArray(responseMessage.getBody());
-            Assert.assertThat(b1, CoreMatchers.equalTo(b2));
+            MatcherAssert.assertThat(b1, CoreMatchers.equalTo(b2));
         }
     }
 
@@ -229,7 +230,7 @@ public abstract class AbstractHttpReactiveFundamentalsTest<T extends CloseableHt
             });
         }
 
-        Assert.assertThat(countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()), CoreMatchers.equalTo(true));
 
         executorService.shutdownNow();
         executorService.awaitTermination(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
@@ -239,7 +240,7 @@ public abstract class AbstractHttpReactiveFundamentalsTest<T extends CloseableHt
             if (response == null) {
                 break;
             }
-            Assert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
         }
     }
 
@@ -253,8 +254,8 @@ public abstract class AbstractHttpReactiveFundamentalsTest<T extends CloseableHt
 
         final Future<Message<HttpResponse, Publisher<ByteBuffer>>> future = consumer.getResponseFuture();
         final HttpResponse response = future.get().getHead();
-        Assert.assertThat(response, CoreMatchers.notNullValue());
-        Assert.assertThat(response.getCode(), CoreMatchers.equalTo(400));
+        MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(400));
     }
 
     static String publisherToString(final Publisher<ByteBuffer> publisher) throws Exception {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
index 38b12b8..5d1eccd 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
@@ -47,7 +47,7 @@ import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.config.Http1Config;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExternalResource;
@@ -131,11 +131,11 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
                             .addHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE)
                             .build(), null);
             final SimpleHttpResponse response = future.get();
-            Assert.assertThat(response, CoreMatchers.notNullValue());
-            Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
             final String body = response.getBodyText();
-            Assert.assertThat(body, CoreMatchers.notNullValue());
-            Assert.assertThat(body.length(), CoreMatchers.equalTo(2048));
+            MatcherAssert.assertThat(body, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(body.length(), CoreMatchers.equalTo(2048));
         }
     }
 
@@ -162,11 +162,11 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
                         .setPath("/random/2048")
                         .build(), null);
         final SimpleHttpResponse response1 = future1.get();
-        Assert.assertThat(response1, CoreMatchers.notNullValue());
-        Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(200));
+        MatcherAssert.assertThat(response1, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response1.getCode(), CoreMatchers.equalTo(200));
         final String body1 = response1.getBodyText();
-        Assert.assertThat(body1, CoreMatchers.notNullValue());
-        Assert.assertThat(body1.length(), CoreMatchers.equalTo(2048));
+        MatcherAssert.assertThat(body1, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(body1.length(), CoreMatchers.equalTo(2048));
 
 
         try (final CloseableHttpAsyncClient httpclient2 = HttpAsyncClients.custom()
@@ -180,11 +180,11 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
                             .setPath("/random/2048")
                             .build(), null);
             final SimpleHttpResponse response2 = future2.get();
-            Assert.assertThat(response2, CoreMatchers.notNullValue());
-            Assert.assertThat(response2.getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response2, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response2.getCode(), CoreMatchers.equalTo(200));
             final String body2 = response2.getBodyText();
-            Assert.assertThat(body2, CoreMatchers.notNullValue());
-            Assert.assertThat(body2.length(), CoreMatchers.equalTo(2048));
+            MatcherAssert.assertThat(body2, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(body2.length(), CoreMatchers.equalTo(2048));
         }
 
         final Future<SimpleHttpResponse> future3 = httpclient.execute(
@@ -193,11 +193,11 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
                         .setPath("/random/2048")
                         .build(), null);
         final SimpleHttpResponse response3 = future3.get();
-        Assert.assertThat(response3, CoreMatchers.notNullValue());
-        Assert.assertThat(response3.getCode(), CoreMatchers.equalTo(200));
+        MatcherAssert.assertThat(response3, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response3.getCode(), CoreMatchers.equalTo(200));
         final String body3 = response3.getBodyText();
-        Assert.assertThat(body3, CoreMatchers.notNullValue());
-        Assert.assertThat(body3.length(), CoreMatchers.equalTo(2048));
+        MatcherAssert.assertThat(body3, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(body3.length(), CoreMatchers.equalTo(2048));
     }
 
 }
\ No newline at end of file
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Reactive.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Reactive.java
index 02fd4f4..24cc072 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Reactive.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Reactive.java
@@ -52,7 +52,7 @@ import org.apache.hc.core5.http.nio.AsyncRequestProducer;
 import org.apache.hc.core5.http.nio.support.AsyncRequestBuilder;
 import org.apache.hc.core5.reactive.ReactiveResponseConsumer;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExternalResource;
@@ -141,11 +141,11 @@ public class TestHttp1Reactive extends AbstractHttpReactiveFundamentalsTest<Clos
             httpclient.execute(request, consumer, null);
 
             final Message<HttpResponse, Publisher<ByteBuffer>> response = consumer.getResponseFuture().get();
-            Assert.assertThat(response, CoreMatchers.notNullValue());
-            Assert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response.getHead().getCode(), CoreMatchers.equalTo(200));
             final String body = publisherToString(response.getBody());
-            Assert.assertThat(body, CoreMatchers.notNullValue());
-            Assert.assertThat(body.length(), CoreMatchers.equalTo(2048));
+            MatcherAssert.assertThat(body, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(body.length(), CoreMatchers.equalTo(2048));
         }
     }
 
@@ -172,12 +172,12 @@ public class TestHttp1Reactive extends AbstractHttpReactiveFundamentalsTest<Clos
         httpclient.execute(request1, consumer1, null);
 
         final Message<HttpResponse, Publisher<ByteBuffer>> response1 = consumer1.getResponseFuture().get();
-        Assert.assertThat(response1, CoreMatchers.notNullValue());
-        Assert.assertThat(response1.getHead(), CoreMatchers.notNullValue());
-        Assert.assertThat(response1.getHead().getCode(), CoreMatchers.equalTo(200));
+        MatcherAssert.assertThat(response1, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response1.getHead(), CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response1.getHead().getCode(), CoreMatchers.equalTo(200));
         final String body1 = publisherToString(response1.getBody());
-        Assert.assertThat(body1, CoreMatchers.notNullValue());
-        Assert.assertThat(body1.length(), CoreMatchers.equalTo(2048));
+        MatcherAssert.assertThat(body1, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(body1.length(), CoreMatchers.equalTo(2048));
 
 
         try (final CloseableHttpAsyncClient httpclient2 = HttpAsyncClients.custom()
@@ -191,11 +191,11 @@ public class TestHttp1Reactive extends AbstractHttpReactiveFundamentalsTest<Clos
             httpclient2.execute(request2, consumer2, null);
 
             final Message<HttpResponse, Publisher<ByteBuffer>> response2 = consumer2.getResponseFuture().get();
-            Assert.assertThat(response2, CoreMatchers.notNullValue());
-            Assert.assertThat(response2.getHead().getCode(), CoreMatchers.equalTo(200));
+            MatcherAssert.assertThat(response2, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(response2.getHead().getCode(), CoreMatchers.equalTo(200));
             final String body2 = publisherToString(response2.getBody());
-            Assert.assertThat(body2, CoreMatchers.notNullValue());
-            Assert.assertThat(body2.length(), CoreMatchers.equalTo(2048));
+            MatcherAssert.assertThat(body2, CoreMatchers.notNullValue());
+            MatcherAssert.assertThat(body2.length(), CoreMatchers.equalTo(2048));
         }
 
         final AsyncRequestProducer request3 = AsyncRequestBuilder.get(target + "/random/2048").build();
@@ -204,11 +204,11 @@ public class TestHttp1Reactive extends AbstractHttpReactiveFundamentalsTest<Clos
         httpclient.execute(request3, consumer3, null);
 
         final Message<HttpResponse, Publisher<ByteBuffer>> response3 = consumer3.getResponseFuture().get();
-        Assert.assertThat(response3, CoreMatchers.notNullValue());
-        Assert.assertThat(response3.getHead().getCode(), CoreMatchers.equalTo(200));
+        MatcherAssert.assertThat(response3, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response3.getHead().getCode(), CoreMatchers.equalTo(200));
         final String body3 = publisherToString(response3.getBody());
-        Assert.assertThat(body3, CoreMatchers.notNullValue());
-        Assert.assertThat(body3.length(), CoreMatchers.equalTo(2048));
+        MatcherAssert.assertThat(body3, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(body3.length(), CoreMatchers.equalTo(2048));
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1RequestReExecution.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1RequestReExecution.java
index c6d4b99..fac64cf 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1RequestReExecution.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1RequestReExecution.java
@@ -50,7 +50,7 @@ import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.util.TimeValue;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExternalResource;
@@ -150,8 +150,8 @@ public class TestHttp1RequestReExecution extends AbstractIntegrationTestBase<Clo
                         .setPath("/random/2048")
                         .build(), null);
         final SimpleHttpResponse response = future.get();
-        Assert.assertThat(response, CoreMatchers.notNullValue());
-        Assert.assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_SERVICE_UNAVAILABLE));
+        MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_SERVICE_UNAVAILABLE));
     }
 
     @Test
@@ -164,8 +164,8 @@ public class TestHttp1RequestReExecution extends AbstractIntegrationTestBase<Clo
                         .setPath("/random/2048")
                         .build(), null);
         final SimpleHttpResponse response = future.get();
-        Assert.assertThat(response, CoreMatchers.notNullValue());
-        Assert.assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+        MatcherAssert.assertThat(response, CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java
index 377d410..5c5c073 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java
@@ -58,7 +58,7 @@ import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -132,11 +132,11 @@ public class TestHttpAsyncMinimal extends AbstractHttpAsyncFundamentalsTest<Mini
             while (!queue.isEmpty()) {
                 final Future<Message<HttpResponse, byte[]>> future = queue.remove();
                 final Message<HttpResponse, byte[]> responseMessage = future.get();
-                Assert.assertThat(responseMessage, CoreMatchers.notNullValue());
+                MatcherAssert.assertThat(responseMessage, CoreMatchers.notNullValue());
                 final HttpResponse response = responseMessage.getHead();
-                Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+                MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
                 final byte[] b2 = responseMessage.getBody();
-                Assert.assertThat(b1, CoreMatchers.equalTo(b2));
+                MatcherAssert.assertThat(b1, CoreMatchers.equalTo(b2));
                 endpoint.releaseAndReuse();
             }
         } finally {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpMinimalReactive.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpMinimalReactive.java
index 7513496..5cbad43 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpMinimalReactive.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpMinimalReactive.java
@@ -58,7 +58,7 @@ import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -132,11 +132,11 @@ public class TestHttpMinimalReactive extends AbstractHttpReactiveFundamentalsTes
             while (!queue.isEmpty()) {
                 final Future<Message<HttpResponse, byte[]>> future = queue.remove();
                 final Message<HttpResponse, byte[]> responseMessage = future.get();
-                Assert.assertThat(responseMessage, CoreMatchers.notNullValue());
+                MatcherAssert.assertThat(responseMessage, CoreMatchers.notNullValue());
                 final HttpResponse response = responseMessage.getHead();
-                Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
+                MatcherAssert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
                 final byte[] b2 = responseMessage.getBody();
-                Assert.assertThat(b1, CoreMatchers.equalTo(b2));
+                MatcherAssert.assertThat(b1, CoreMatchers.equalTo(b2));
                 endpoint.releaseAndReuse();
             }
         } finally {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
index 1b0c24d..a579408 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
@@ -63,6 +63,7 @@ import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.net.URIBuilder;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -560,9 +561,9 @@ public class TestRedirects extends LocalServerTestBase {
             EntityUtils.consume(response.getEntity());
         }
 
-        Assert.assertThat(values.poll(), CoreMatchers.equalTo("gzip, x-gzip, deflate"));
-        Assert.assertThat(values.poll(), CoreMatchers.equalTo("gzip, x-gzip, deflate"));
-        Assert.assertThat(values.poll(), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(values.poll(), CoreMatchers.equalTo("gzip, x-gzip, deflate"));
+        MatcherAssert.assertThat(values.poll(), CoreMatchers.equalTo("gzip, x-gzip, deflate"));
+        MatcherAssert.assertThat(values.poll(), CoreMatchers.nullValue());
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestProtocolSupport.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestProtocolSupport.java
index 11c8315..0af8432 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestProtocolSupport.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestProtocolSupport.java
@@ -31,7 +31,7 @@ import org.apache.hc.core5.http.Method;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.net.URIAuthority;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
 /**
@@ -42,14 +42,14 @@ public class TestProtocolSupport {
     @Test
     public void testGetRequestUri() {
         final HttpRequest request = new BasicHttpRequest(Method.GET, "");
-        Assert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("/"));
+        MatcherAssert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("/"));
         request.setAuthority(new URIAuthority("testUser", "localhost", 8080));
-        Assert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("http://testUser@localhost:8080/"));
+        MatcherAssert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("http://testUser@localhost:8080/"));
         request.setScheme("https");
-        Assert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("https://testUser@localhost:8080/"));
+        MatcherAssert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("https://testUser@localhost:8080/"));
         request.setPath("blah");
-        Assert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("https://testUser@localhost:8080/blah"));
+        MatcherAssert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("https://testUser@localhost:8080/blah"));
         request.setPath("/blah/blah");
-        Assert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("https://testUser@localhost:8080/blah/blah"));
+        MatcherAssert.assertThat(ProtocolSupport.getRequestUri(request), CoreMatchers.equalTo("https://testUser@localhost:8080/blah/blah"));
     }
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java
index f9613de..ac61d4d 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java
@@ -37,6 +37,7 @@ import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.message.ParserCursor;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -55,7 +56,7 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("aaabbbbccc ");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
     }
 
     @Test
@@ -63,7 +64,7 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("aaabbbbccc, ");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
     }
 
     @Test
@@ -71,7 +72,7 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("aaabbbbccc");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
     }
 
     @Test
@@ -79,9 +80,9 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("aaabbbbccc==== ");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc===="));
-        Assert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(false));
-        Assert.assertThat(buffer.charAt(cursor.getPos()), CoreMatchers.equalTo(' '));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc===="));
+        MatcherAssert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(buffer.charAt(cursor.getPos()), CoreMatchers.equalTo(' '));
     }
 
     @Test
@@ -89,8 +90,8 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("aaabbbbccc=");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc="));
-        Assert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc="));
+        MatcherAssert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(true));
     }
 
     @Test
@@ -98,8 +99,8 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(16);
         buffer.append("aaabbbbccc======");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc======"));
-        Assert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc======"));
+        MatcherAssert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(true));
     }
 
     @Test
@@ -107,9 +108,9 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("aaabbbbccc====,");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc===="));
-        Assert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(false));
-        Assert.assertThat(buffer.charAt(cursor.getPos()), CoreMatchers.equalTo(','));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc===="));
+        MatcherAssert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(buffer.charAt(cursor.getPos()), CoreMatchers.equalTo(','));
     }
 
     @Test
@@ -117,9 +118,9 @@ public class TestAuthChallengeParser {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("aaabbbbccc=blah");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        Assert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
-        Assert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(false));
-        Assert.assertThat(buffer.charAt(cursor.getPos()), CoreMatchers.equalTo('='));
+        MatcherAssert.assertThat(parser.parseToken(buffer, cursor), CoreMatchers.equalTo("aaabbbbccc"));
+        MatcherAssert.assertThat(cursor.atEnd(), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(buffer.charAt(cursor.getPos()), CoreMatchers.equalTo('='));
     }
 
     @Test
@@ -136,7 +137,7 @@ public class TestAuthChallengeParser {
         final List<NameValuePair> params = challenge1.getParams();
         Assert.assertNotNull(params);
         Assert.assertEquals(1, params.size());
-        Assert.assertThat(params.get(0), NameValuePairMatcher.equals("realm", "blah"));
+        MatcherAssert.assertThat(params.get(0), NameValuePairMatcher.equals("realm", "blah"));
     }
 
     @Test
@@ -153,7 +154,7 @@ public class TestAuthChallengeParser {
         final List<NameValuePair> params = challenge1.getParams();
         Assert.assertNotNull(params);
         Assert.assertEquals(1, params.size());
-        Assert.assertThat(params.get(0), NameValuePairMatcher.equals("realm", "blah"));
+        MatcherAssert.assertThat(params.get(0), NameValuePairMatcher.equals("realm", "blah"));
     }
 
     @Test
@@ -193,9 +194,9 @@ public class TestAuthChallengeParser {
         final List<NameValuePair> params1 = challenge1.getParams();
         Assert.assertNotNull(params1);
         Assert.assertEquals(3, params1.size());
-        Assert.assertThat(params1.get(0), NameValuePairMatcher.equals("realm", "blah"));
-        Assert.assertThat(params1.get(1), NameValuePairMatcher.equals("param1", "this"));
-        Assert.assertThat(params1.get(2), NameValuePairMatcher.equals("param2", "that"));
+        MatcherAssert.assertThat(params1.get(0), NameValuePairMatcher.equals("realm", "blah"));
+        MatcherAssert.assertThat(params1.get(1), NameValuePairMatcher.equals("param1", "this"));
+        MatcherAssert.assertThat(params1.get(2), NameValuePairMatcher.equals("param2", "that"));
 
         final AuthChallenge challenge2 = challenges.get(1);
         Assert.assertEquals(StandardAuthScheme.BASIC, challenge2.getSchemeName());
@@ -203,10 +204,10 @@ public class TestAuthChallengeParser {
         final List<NameValuePair> params2 = challenge2.getParams();
         Assert.assertNotNull(params2);
         Assert.assertEquals(4, params2.size());
-        Assert.assertThat(params2.get(0), NameValuePairMatcher.equals("realm", "\"yada\""));
-        Assert.assertThat(params2.get(1), NameValuePairMatcher.equals("this", null));
-        Assert.assertThat(params2.get(2), NameValuePairMatcher.equals("that", ""));
-        Assert.assertThat(params2.get(3), NameValuePairMatcher.equals("this-and-that", null));
+        MatcherAssert.assertThat(params2.get(0), NameValuePairMatcher.equals("realm", "\"yada\""));
+        MatcherAssert.assertThat(params2.get(1), NameValuePairMatcher.equals("this", null));
+        MatcherAssert.assertThat(params2.get(2), NameValuePairMatcher.equals("that", ""));
+        MatcherAssert.assertThat(params2.get(3), NameValuePairMatcher.equals("this-and-that", null));
     }
 
     @Test
@@ -225,8 +226,8 @@ public class TestAuthChallengeParser {
         final List<NameValuePair> params1 = challenge1.getParams();
         Assert.assertNotNull(params1);
         Assert.assertEquals(2, params1.size());
-        Assert.assertThat(params1.get(0), NameValuePairMatcher.equals("realm", "blah"));
-        Assert.assertThat(params1.get(1), NameValuePairMatcher.equals("param1", "this, param2=that"));
+        MatcherAssert.assertThat(params1.get(0), NameValuePairMatcher.equals("realm", "blah"));
+        MatcherAssert.assertThat(params1.get(1), NameValuePairMatcher.equals("param1", "this, param2=that"));
 
         final AuthChallenge challenge2 = challenges.get(1);
         Assert.assertEquals(StandardAuthScheme.BASIC, challenge2.getSchemeName());
@@ -234,7 +235,7 @@ public class TestAuthChallengeParser {
         final List<NameValuePair> params2 = challenge2.getParams();
         Assert.assertNotNull(params2);
         Assert.assertEquals(1, params2.size());
-        Assert.assertThat(params2.get(0), NameValuePairMatcher.equals("realm", "\"yada,,,,\""));
+        MatcherAssert.assertThat(params2.get(0), NameValuePairMatcher.equals("realm", "\"yada,,,,\""));
     }
 
     @Test
@@ -306,8 +307,8 @@ public class TestAuthChallengeParser {
         final List<NameValuePair> params1 = challenge1.getParams();
         Assert.assertNotNull(params1);
         Assert.assertEquals(2, params1.size());
-        Assert.assertThat(params1.get(0), NameValuePairMatcher.equals("blah", null));
-        Assert.assertThat(params1.get(1), NameValuePairMatcher.equals("blah", null));
+        MatcherAssert.assertThat(params1.get(0), NameValuePairMatcher.equals("blah", null));
+        MatcherAssert.assertThat(params1.get(1), NameValuePairMatcher.equals("blah", null));
     }
 
     @Test
@@ -332,23 +333,23 @@ public class TestAuthChallengeParser {
         Assert.assertNotNull(challenges);
         Assert.assertEquals(4, challenges.size());
         final AuthChallenge challenge1 = challenges.get(0);
-        Assert.assertThat(challenge1.getSchemeName(), CoreMatchers.equalTo("scheme1"));
-        Assert.assertThat(challenge1.getValue(), CoreMatchers.equalTo("aaaa"));
-        Assert.assertThat(challenge1.getParams(), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(challenge1.getSchemeName(), CoreMatchers.equalTo("scheme1"));
+        MatcherAssert.assertThat(challenge1.getValue(), CoreMatchers.equalTo("aaaa"));
+        MatcherAssert.assertThat(challenge1.getParams(), CoreMatchers.nullValue());
         final AuthChallenge challenge2 = challenges.get(1);
-        Assert.assertThat(challenge2.getSchemeName(), CoreMatchers.equalTo("scheme2"));
-        Assert.assertThat(challenge2.getValue(), CoreMatchers.equalTo("aaaa=="));
-        Assert.assertThat(challenge2.getParams(), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(challenge2.getSchemeName(), CoreMatchers.equalTo("scheme2"));
+        MatcherAssert.assertThat(challenge2.getValue(), CoreMatchers.equalTo("aaaa=="));
+        MatcherAssert.assertThat(challenge2.getParams(), CoreMatchers.nullValue());
         final AuthChallenge challenge3 = challenges.get(2);
-        Assert.assertThat(challenge3.getSchemeName(), CoreMatchers.equalTo("scheme3"));
-        Assert.assertThat(challenge3.getValue(), CoreMatchers.nullValue());
-        Assert.assertThat(challenge3.getParams(), CoreMatchers.notNullValue());
-        Assert.assertThat(challenge3.getParams().size(), CoreMatchers.equalTo(1));
-        Assert.assertThat(challenge3.getParams().get(0), NameValuePairMatcher.equals("aaaa", "aaaa"));
+        MatcherAssert.assertThat(challenge3.getSchemeName(), CoreMatchers.equalTo("scheme3"));
+        MatcherAssert.assertThat(challenge3.getValue(), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(challenge3.getParams(), CoreMatchers.notNullValue());
+        MatcherAssert.assertThat(challenge3.getParams().size(), CoreMatchers.equalTo(1));
+        MatcherAssert.assertThat(challenge3.getParams().get(0), NameValuePairMatcher.equals("aaaa", "aaaa"));
         final AuthChallenge challenge4 = challenges.get(3);
-        Assert.assertThat(challenge4.getSchemeName(), CoreMatchers.equalTo("scheme4"));
-        Assert.assertThat(challenge4.getValue(), CoreMatchers.equalTo("aaaa="));
-        Assert.assertThat(challenge4.getParams(), CoreMatchers.nullValue());
+        MatcherAssert.assertThat(challenge4.getSchemeName(), CoreMatchers.equalTo("scheme4"));
+        MatcherAssert.assertThat(challenge4.getValue(), CoreMatchers.equalTo("aaaa="));
+        MatcherAssert.assertThat(challenge4.getParams(), CoreMatchers.nullValue());
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java
index 971ded0..fd24894 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java
@@ -109,7 +109,7 @@ public class TestHttpAuthenticator {
         response.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
         Assert.assertTrue(this.httpAuthenticator.isChallenged(
                 this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
-        Mockito.verifyZeroInteractions(this.authCache);
+        Mockito.verifyNoInteractions(this.authCache);
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java
index b359e0d..deaa5af 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java
@@ -36,7 +36,7 @@ import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.net.URIAuthority;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
 public class TestRoutingSupport {
@@ -45,11 +45,11 @@ public class TestRoutingSupport {
     public void testDetermineHost() throws Exception {
         final HttpRequest request1 = new BasicHttpRequest("GET", "/");
         final HttpHost host1 = RoutingSupport.determineHost(request1);
-        Assert.assertThat(host1, CoreMatchers.nullValue());
+        MatcherAssert.assertThat(host1, CoreMatchers.nullValue());
 
         final HttpRequest request2 = new BasicHttpRequest("GET", new URI("https://somehost:8443/"));
         final HttpHost host2 = RoutingSupport.determineHost(request2);
-        Assert.assertThat(host2, CoreMatchers.equalTo(new HttpHost("https", "somehost", 8443)));
+        MatcherAssert.assertThat(host2, CoreMatchers.equalTo(new HttpHost("https", "somehost", 8443)));
     }
 
     @Test(expected = ProtocolException.class)
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDistinguishedNameParser.java b/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDistinguishedNameParser.java
index b350885..4472405 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDistinguishedNameParser.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDistinguishedNameParser.java
@@ -32,7 +32,7 @@ import java.util.Arrays;
 import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.message.BasicNameValuePair;
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -50,7 +50,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseBasic() throws Exception {
-        Assert.assertThat(impl.parse("cn=blah, ou=yada, o=booh"),
+        MatcherAssert.assertThat(impl.parse("cn=blah, ou=yada, o=booh"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("cn", "blah"),
                         new BasicNameValuePair("ou", "yada"),
@@ -59,7 +59,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseRepeatedElements() throws Exception {
-        Assert.assertThat(impl.parse("cn=blah, cn=yada, cn=booh"),
+        MatcherAssert.assertThat(impl.parse("cn=blah, cn=yada, cn=booh"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("cn", "blah"),
                         new BasicNameValuePair("cn", "yada"),
@@ -68,7 +68,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseBlanks() throws Exception {
-        Assert.assertThat(impl.parse("c = pampa ,  cn  =    blah    , ou = blah , o = blah"),
+        MatcherAssert.assertThat(impl.parse("c = pampa ,  cn  =    blah    , ou = blah , o = blah"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("c", "pampa"),
                         new BasicNameValuePair("cn", "blah"),
@@ -78,7 +78,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseQuotes() throws Exception {
-        Assert.assertThat(impl.parse("cn=\"blah\", ou=yada, o=booh"),
+        MatcherAssert.assertThat(impl.parse("cn=\"blah\", ou=yada, o=booh"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("cn", "blah"),
                         new BasicNameValuePair("ou", "yada"),
@@ -87,7 +87,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseQuotes2() throws Exception {
-        Assert.assertThat(impl.parse("cn=\"blah  blah\", ou=yada, o=booh"),
+        MatcherAssert.assertThat(impl.parse("cn=\"blah  blah\", ou=yada, o=booh"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("cn", "blah  blah"),
                         new BasicNameValuePair("ou", "yada"),
@@ -96,7 +96,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseQuotes3() throws Exception {
-        Assert.assertThat(impl.parse("cn=\"blah, blah\", ou=yada, o=booh"),
+        MatcherAssert.assertThat(impl.parse("cn=\"blah, blah\", ou=yada, o=booh"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("cn", "blah, blah"),
                         new BasicNameValuePair("ou", "yada"),
@@ -105,7 +105,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseEscape() throws Exception {
-        Assert.assertThat(impl.parse("cn=blah\\, blah, ou=yada, o=booh"),
+        MatcherAssert.assertThat(impl.parse("cn=blah\\, blah, ou=yada, o=booh"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("cn", "blah, blah"),
                         new BasicNameValuePair("ou", "yada"),
@@ -114,7 +114,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseUnescapedEqual() throws Exception {
-        Assert.assertThat(impl.parse("c = cn=uuh, cn=blah, ou=yada, o=booh"),
+        MatcherAssert.assertThat(impl.parse("c = cn=uuh, cn=blah, ou=yada, o=booh"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("c", "cn=uuh"),
                         new BasicNameValuePair("cn", "blah"),
@@ -124,7 +124,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseInvalid() throws Exception {
-        Assert.assertThat(impl.parse("blah,blah"),
+        MatcherAssert.assertThat(impl.parse("blah,blah"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("blah", null),
                         new BasicNameValuePair("blah", null))));
@@ -132,7 +132,7 @@ public class TestDistinguishedNameParser {
 
     @Test
     public void testParseInvalid2() throws Exception {
-        Assert.assertThat(impl.parse("cn,o=blah"),
+        MatcherAssert.assertThat(impl.parse("cn,o=blah"),
                 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
                         new BasicNameValuePair("cn", null),
                         new BasicNameValuePair("o", "blah"))));
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TesDnsUtils.java b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TesDnsUtils.java
index 9c41c79..5684640 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TesDnsUtils.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TesDnsUtils.java
@@ -28,7 +28,7 @@
 package org.apache.hc.client5.http.utils;
 
 import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
 /**
@@ -38,14 +38,14 @@ public class TesDnsUtils {
 
     @Test
     public void testNormalize() {
-        Assert.assertThat(DnsUtils.normalize(null), CoreMatchers.equalTo(null));
-        Assert.assertThat(DnsUtils.normalize(""), CoreMatchers.equalTo(""));
-        Assert.assertThat(DnsUtils.normalize("blah"), CoreMatchers.equalTo("blah"));
-        Assert.assertThat(DnsUtils.normalize("BLAH"), CoreMatchers.equalTo("blah"));
-        Assert.assertThat(DnsUtils.normalize("blAh"), CoreMatchers.equalTo("blah"));
-        Assert.assertThat(DnsUtils.normalize("blaH"), CoreMatchers.equalTo("blah"));
-        Assert.assertThat(DnsUtils.normalize("blaH"), CoreMatchers.equalTo("blah"));
-        Assert.assertThat(DnsUtils.normalize("hac\u212A!!!"), CoreMatchers.equalTo("hac\u212A!!!"));
+        MatcherAssert.assertThat(DnsUtils.normalize(null), CoreMatchers.equalTo(null));
+        MatcherAssert.assertThat(DnsUtils.normalize(""), CoreMatchers.equalTo(""));
+        MatcherAssert.assertThat(DnsUtils.normalize("blah"), CoreMatchers.equalTo("blah"));
+        MatcherAssert.assertThat(DnsUtils.normalize("BLAH"), CoreMatchers.equalTo("blah"));
+        MatcherAssert.assertThat(DnsUtils.normalize("blAh"), CoreMatchers.equalTo("blah"));
+        MatcherAssert.assertThat(DnsUtils.normalize("blaH"), CoreMatchers.equalTo("blah"));
+        MatcherAssert.assertThat(DnsUtils.normalize("blaH"), CoreMatchers.equalTo("blah"));
+        MatcherAssert.assertThat(DnsUtils.normalize("hac\u212A!!!"), CoreMatchers.equalTo("hac\u212A!!!"));
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestDateUtils.java b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestDateUtils.java
index 4475fe0..da3e130 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestDateUtils.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestDateUtils.java
@@ -34,6 +34,7 @@ import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.HeaderGroup;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -125,35 +126,35 @@ public class TestDateUtils {
     public void testIsBefore() throws Exception {
         final HeaderGroup message1 = new HeaderGroup();
         final HeaderGroup message2 = new HeaderGroup();
-        Assert.assertThat(DateUtils.isBefore(null, null, HttpHeaders.DATE), CoreMatchers.equalTo(false));
-        Assert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isBefore(null, null, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "huh?"));
         message2.setHeader(new BasicHeader(HttpHeaders.DATE, "eh?"));
-        Assert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "huh?"));
         message2.setHeader(new BasicHeader(HttpHeaders.DATE, "Tuesday, 26-Dec-2017 00:00:00 GMT"));
-        Assert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "Wednesday, 25-Dec-2017 00:00:00 GMT"));
-        Assert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(true));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "Thursday, 27-Dec-2017 00:00:00 GMT"));
-        Assert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isBefore(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
     }
 
     @Test
     public void testIsAfter() throws Exception {
         final HeaderGroup message1 = new HeaderGroup();
         final HeaderGroup message2 = new HeaderGroup();
-        Assert.assertThat(DateUtils.isAfter(null, null, HttpHeaders.DATE), CoreMatchers.equalTo(false));
-        Assert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isAfter(null, null, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "huh?"));
         message2.setHeader(new BasicHeader(HttpHeaders.DATE, "eh?"));
-        Assert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "huh?"));
         message2.setHeader(new BasicHeader(HttpHeaders.DATE, "Tuesday, 26-Dec-2017 00:00:00 GMT"));
-        Assert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "Thursday, 27-Dec-2017 00:00:00 GMT"));
-        Assert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(true));
+        MatcherAssert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(true));
         message1.setHeader(new BasicHeader(HttpHeaders.DATE, "Wednesday, 25-Dec-2017 00:00:00 GMT"));
-        Assert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
+        MatcherAssert.assertThat(DateUtils.isAfter(message1, message2, HttpHeaders.DATE), CoreMatchers.equalTo(false));
     }
 }

[httpcomponents-client] 03/03: Updated test cases with exception asserts

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit e8b0ec602c2f54ec0da43f2003a2efbae071523b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon May 24 18:40:53 2021 +0200

    Updated test cases with exception asserts
---
 .../TestHttpByteArrayCacheEntrySerializer.java     | 55 +++++++++--------
 .../impl/cache/TestResponseProtocolCompliance.java |  6 +-
 .../async/AbstractHttpAsyncRedirectsTest.java      | 42 ++++++-------
 .../hc/client5/testing/fluent/TestFluent.java      |  5 +-
 .../testing/sync/TestBasicConnectionManager.java   |  5 +-
 .../testing/sync/TestClientRequestExecution.java   |  5 +-
 .../hc/client5/testing/sync/TestRedirects.java     | 45 +++++---------
 .../client5/testing/sync/TestSSLSocketFactory.java | 36 +++++++-----
 .../http/classic/methods/TestHttpTrace.java        |  6 +-
 .../hc/client5/http/cookie/TestCookieOrigin.java   | 24 ++++----
 .../hc/client5/http/entity/TestEntityBuilder.java  |  7 +--
 .../http/entity/mime/HttpRFC7578MultipartTest.java | 14 +++--
 .../impl/TestDefaultConnKeepAliveStrategy.java     |  5 +-
 .../http/impl/TestDefaultRedirectStrategy.java     | 15 +++--
 .../http/impl/auth/TestAuthChallengeParser.java    | 15 +++--
 .../client5/http/impl/auth/TestBasicAuthCache.java |  5 +-
 .../client5/http/impl/auth/TestDigestScheme.java   | 37 +++++++-----
 .../http/impl/auth/TestRequestAuthCache.java       | 10 ++--
 .../http/impl/classic/TestCloseableHttpClient.java | 38 +++++-------
 .../client5/http/impl/classic/TestConnectExec.java | 25 ++++----
 .../impl/classic/TestContentCompressionExec.java   |  5 +-
 .../classic/TestFutureRequestExecutionService.java | 20 +++----
 .../impl/classic/TestHttpRequestRetryExec.java     | 68 +++++++++-------------
 .../http/impl/classic/TestInternalExecRuntime.java | 15 +++--
 .../http/impl/classic/TestInternalHttpClient.java  |  5 +-
 .../http/impl/classic/TestMainClientExec.java      | 44 +++++---------
 .../http/impl/classic/TestProtocolExec.java        | 33 ++++-------
 .../http/impl/classic/TestRedirectExec.java        | 39 ++++++-------
 .../impl/cookie/TestBasicCookieAttribHandlers.java | 10 ++--
 .../impl/cookie/TestLaxCookieAttribHandlers.java   | 60 +++++++++++--------
 .../http/impl/cookie/TestRFC6265CookieSpec.java    | 10 ++--
 .../io/TestBasicHttpClientConnectionManager.java   | 15 +++--
 .../impl/io/TestHttpClientConnectionOperator.java  | 23 +++++---
 .../io/TestPoolingHttpClientConnectionManager.java | 10 ++--
 .../http/impl/routing/TestDefaultRoutePlanner.java |  5 +-
 .../http/impl/routing/TestRouteDirector.java       |  5 +-
 .../http/impl/routing/TestRoutingSupport.java      |  6 +-
 .../http/protocol/TestRequestAddCookies.java       | 10 ++--
 .../protocol/TestRequestClientConnControl.java     |  5 +-
 .../http/protocol/TestRequestDefaultHeaders.java   |  5 +-
 .../http/protocol/TestResponseProcessCookies.java  | 10 ++--
 41 files changed, 408 insertions(+), 395 deletions(-)

diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpByteArrayCacheEntrySerializer.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpByteArrayCacheEntrySerializer.java
index dacc3a9..bb21d36 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpByteArrayCacheEntrySerializer.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpByteArrayCacheEntrySerializer.java
@@ -27,6 +27,13 @@
 
 package org.apache.hc.client5.http.impl.cache;
 
+import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.HttpCacheStorageEntryTestTemplate;
+import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.httpCacheStorageEntryFromBytes;
+import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.makeTestFileObject;
+import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.readTestFileBytes;
+import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.testWithCache;
+import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.verifyHttpCacheEntryFromTestFile;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -45,17 +52,11 @@ import org.apache.hc.core5.http.impl.io.AbstractMessageWriter;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
 import org.apache.hc.core5.http.message.BasicHeader;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.makeTestFileObject;
-import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.httpCacheStorageEntryFromBytes;
-import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.readTestFileBytes;
-import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.testWithCache;
-import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.verifyHttpCacheEntryFromTestFile;
-import static org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializerTestUtils.HttpCacheStorageEntryTestTemplate;
-
 public class TestHttpByteArrayCacheEntrySerializer {
     private static final String SERIALIAZED_EXTENSION = ".httpbytes.serialized";
 
@@ -195,13 +196,14 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void testNullStorageKey() throws Exception {
         final HttpCacheStorageEntryTestTemplate cacheObjectValues = HttpCacheStorageEntryTestTemplate.makeDefault();
         cacheObjectValues.storageKey = null;
 
         final HttpCacheStorageEntry testEntry = cacheObjectValues.toEntry();
-        serializer.serialize(testEntry);
+        Assert.assertThrows(IllegalStateException.class, () ->
+                serializer.serialize(testEntry));
     }
 
     /**
@@ -294,11 +296,12 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = ResourceIOException.class)
+    @Test
     public void testInvalidCacheEntry() throws Exception {
         // This file is a JPEG not a cache entry, so should fail to deserialize
         final byte[] bytes = readTestFileBytes(TEST_CONTENT_FILE_NAME);
-        httpCacheStorageEntryFromBytes(serializer, bytes);
+        Assert.assertThrows(ResourceIOException.class, () ->
+                httpCacheStorageEntryFromBytes(serializer, bytes));
     }
 
     /**
@@ -306,11 +309,12 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = ResourceIOException.class)
+    @Test
     public void testMissingHeaderCacheEntry() throws Exception {
         // This file hand-edited to be missing a necessary header
         final byte[] bytes = readTestFileBytes(MISSING_HEADER_TEST_SERIALIZED_NAME);
-        httpCacheStorageEntryFromBytes(serializer, bytes);
+        Assert.assertThrows(ResourceIOException.class, () ->
+                httpCacheStorageEntryFromBytes(serializer, bytes));
     }
 
     /**
@@ -318,11 +322,12 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = ResourceIOException.class)
+    @Test
     public void testInvalidHeaderCacheEntry() throws Exception {
         // This file hand-edited to have an invalid header
         final byte[] bytes = readTestFileBytes(INVALID_HEADER_TEST_SERIALIZED_NAME);
-        httpCacheStorageEntryFromBytes(serializer, bytes);
+        Assert.assertThrows(ResourceIOException.class, () ->
+                httpCacheStorageEntryFromBytes(serializer, bytes));
     }
 
     /**
@@ -330,11 +335,12 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = ResourceIOException.class)
+    @Test
     public void testVariantMapMissingKeyCacheEntry() throws Exception {
         // This file hand-edited to be missing a VariantCache key
         final byte[] bytes = readTestFileBytes(VARIANTMAP_MISSING_KEY_TEST_SERIALIZED_NAME);
-        httpCacheStorageEntryFromBytes(serializer, bytes);
+        Assert.assertThrows(ResourceIOException.class, () ->
+                httpCacheStorageEntryFromBytes(serializer, bytes));
     }
 
     /**
@@ -342,11 +348,12 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = ResourceIOException.class)
+    @Test
     public void testVariantMapMissingValueCacheEntry() throws Exception {
         // This file hand-edited to be missing a VariantCache value
         final byte[] bytes = readTestFileBytes(VARIANTMAP_MISSING_VALUE_TEST_SERIALIZED_NAME);
-        httpCacheStorageEntryFromBytes(serializer, bytes);
+        Assert.assertThrows(ResourceIOException.class, () ->
+                httpCacheStorageEntryFromBytes(serializer, bytes));
     }
 
     /**
@@ -354,7 +361,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = ResourceIOException.class)
+    @Test
     public void testSerializeWithHTTPException() throws Exception {
         final AbstractMessageWriter<SimpleHttpResponse> throwyHttpWriter = Mockito.mock(AbstractMessageWriter.class);
         Mockito.
@@ -371,7 +378,8 @@ public class TestHttpByteArrayCacheEntrySerializer {
                 return throwyHttpWriter;
             }
         };
-        testSerializer.serialize(testEntry);
+        Assert.assertThrows(ResourceIOException.class, () ->
+                testSerializer.serialize(testEntry));
     }
 
     /**
@@ -379,7 +387,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
      *
      * @throws Exception is expected
      */
-    @Test(expected = ResourceIOException.class)
+    @Test
     public void testDeserializeWithIOException() throws Exception {
         final AbstractMessageParser<ClassicHttpResponse> throwyParser = Mockito.mock(AbstractMessageParser.class);
         Mockito.
@@ -393,6 +401,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
                 return throwyParser;
             }
         };
-        testSerializer.deserialize(new byte[0]);
+        Assert.assertThrows(ResourceIOException.class, () ->
+                testSerializer.deserialize(new byte[0]));
     }
 }
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
index b00d6d7..fce3197 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
@@ -36,6 +36,7 @@ import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.message.BasicHttpResponse;
 import org.apache.hc.core5.http.support.BasicRequestBuilder;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -61,14 +62,15 @@ public class TestResponseProtocolCompliance {
         return resp;
     }
 
-    @Test(expected=ClientProtocolException.class)
+    @Test
     public void throwsExceptionIfOriginReturnsPartialResponseWhenNotRequested() throws Exception {
         final HttpGet req = new HttpGet("http://foo.example.com/");
         final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
         final int nbytes = 128;
         final HttpResponse resp = makePartialResponse(nbytes);
 
-        impl.ensureProtocolCompliance(wrapper, req, resp);
+        Assert.assertThrows(ClientProtocolException.class, () ->
+                impl.ensureProtocolCompliance(wrapper, req, resp));
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
index a961e61..6f2907b 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
@@ -66,6 +66,8 @@ import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.testing.nio.H2TestServer;
 import org.apache.hc.core5.testing.reactive.ReactiveRandomProcessor;
 import org.apache.hc.core5.util.TimeValue;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -278,7 +280,7 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
         Assert.assertEquals(target, new HttpHost(request.getScheme(), request.getAuthority()));
     }
 
-    @Test(expected=ExecutionException.class)
+    @Test
     public void testMaxRedirectCheck() throws Exception {
         final HttpHost target = start(exchangeHandler -> new RedirectingAsyncDecorator(
                 exchangeHandler,
@@ -288,20 +290,18 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
         final RequestConfig config = RequestConfig.custom()
                 .setCircularRedirectsAllowed(true)
                 .setMaxRedirects(5).build();
-        try {
+        final ExecutionException exception = Assert.assertThrows(ExecutionException.class, () -> {
             final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
                     .setHttpHost(target)
                     .setPath("/circular-oldlocation/")
                     .setRequestConfig(config)
                     .build(), null);
             future.get();
-        } catch (final ExecutionException e) {
-            Assert.assertTrue(e.getCause() instanceof RedirectException);
-            throw e;
-        }
+        });
+        MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(RedirectException.class));
     }
 
-    @Test(expected=ExecutionException.class)
+    @Test
     public void testCircularRedirect() throws Exception {
         final HttpHost target = start(exchangeHandler -> new RedirectingAsyncDecorator(
                 exchangeHandler,
@@ -311,7 +311,7 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
         final RequestConfig config = RequestConfig.custom()
                 .setCircularRedirectsAllowed(false)
                 .build();
-        try {
+        final ExecutionException exception = Assert.assertThrows(ExecutionException.class, () -> {
             final Future<SimpleHttpResponse> future = httpclient.execute(
                     SimpleRequestBuilder.get()
                             .setHttpHost(target)
@@ -319,10 +319,8 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
                             .setRequestConfig(config)
                             .build(), null);
             future.get();
-        } catch (final ExecutionException e) {
-            Assert.assertTrue(e.getCause() instanceof CircularRedirectException);
-            throw e;
-        }
+        });
+        MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(CircularRedirectException.class));
     }
 
     @Test
@@ -431,7 +429,7 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
         Assert.assertEquals(target, new HttpHost(request.getScheme(), request.getAuthority()));
     }
 
-    @Test(expected=ExecutionException.class)
+    @Test
     public void testRejectBogusRedirectLocation() throws Exception {
         final HttpHost target = start(exchangeHandler -> new RedirectingAsyncDecorator(
                 exchangeHandler,
@@ -444,20 +442,18 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
                     return null;
                 }));
 
-        try {
+        final ExecutionException exception = Assert.assertThrows(ExecutionException.class, () -> {
             final Future<SimpleHttpResponse> future = httpclient.execute(
                     SimpleRequestBuilder.get()
                             .setHttpHost(target)
                             .setPath("/oldlocation/")
                             .build(), null);
             future.get();
-        } catch (final ExecutionException ex) {
-            Assert.assertTrue(ex.getCause() instanceof HttpException);
-            throw ex;
-        }
+        });
+        MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(HttpException.class));
     }
 
-    @Test(expected=ExecutionException.class)
+    @Test
     public void testRejectInvalidRedirectLocation() throws Exception {
         final HttpHost target = start(exchangeHandler -> new RedirectingAsyncDecorator(
                 exchangeHandler,
@@ -470,17 +466,15 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
                     return null;
                 }));
 
-        try {
+        final ExecutionException exception = Assert.assertThrows(ExecutionException.class, () -> {
             final Future<SimpleHttpResponse> future = httpclient.execute(
                     SimpleRequestBuilder.get()
                             .setHttpHost(target)
                             .setPath("/oldlocation/")
                             .build(), null);
             future.get();
-        } catch (final ExecutionException e) {
-            Assert.assertTrue(e.getCause() instanceof ProtocolException);
-            throw e;
-        }
+        });
+        MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(ProtocolException.class));
     }
 
     @Test
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
index 0b227b2..6a03046 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
@@ -90,11 +90,12 @@ public class TestFluent extends LocalServerTestBase {
         Assert.assertEquals("All is well", message);
     }
 
-    @Test(expected = ClientProtocolException.class)
+    @Test
     public void testGetRequestFailure() throws Exception {
         final HttpHost target = start();
         final String baseURL = "http://localhost:" + target.getPort();
-        Request.get(baseURL + "/boom").execute().returnContent().asString();
+        Assert.assertThrows(ClientProtocolException.class, () ->
+                Request.get(baseURL + "/boom").execute().returnContent().asString());
     }
 
     @Test
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
index a2ac6f8..65033af 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
@@ -48,7 +48,7 @@ public class TestBasicConnectionManager extends LocalServerTestBase {
         }
     }
 
-    @Test(expected=IllegalStateException.class)
+    @Test
     public void testConnectionStillInUse() throws Exception {
         this.clientBuilder.setConnectionManager(new BasicHttpClientConnectionManager());
 
@@ -56,7 +56,8 @@ public class TestBasicConnectionManager extends LocalServerTestBase {
         final HttpGet get1 = new HttpGet("/random/1024");
         this.httpclient.execute(target, get1);
         final HttpGet get2 = new HttpGet("/random/1024");
-        this.httpclient.execute(target, get2);
+        Assert.assertThrows(IllegalStateException.class, () ->
+                this.httpclient.execute(target, get2));
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
index 21d1ae4..d6f2bc2 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
@@ -166,7 +166,7 @@ public class TestClientRequestExecution extends LocalServerTestBase {
         Assert.assertEquals(1, myheaders.length);
     }
 
-    @Test(expected=IOException.class)
+    @Test
     public void testNonRepeatableEntity() throws Exception {
         this.server.registerHandler("*", new SimpleService());
 
@@ -213,7 +213,8 @@ public class TestClientRequestExecution extends LocalServerTestBase {
                 new ByteArrayInputStream(
                         new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                         -1, null));
-        this.httpclient.execute(target, httppost, context);
+        Assert.assertThrows(IOException.class, () ->
+                this.httpclient.execute(target, httppost, context));
     }
 
     @Test
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
index a579408..7712a7f 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
@@ -292,7 +292,7 @@ public class TestRedirects extends LocalServerTestBase {
         }
     }
 
-    @Test(expected = ClientProtocolException.class)
+    @Test
     public void testMaxRedirectCheck() throws Exception {
         final HttpHost target = start(null, requestHandler -> new RedirectingDecorator(
                 requestHandler,
@@ -306,15 +306,12 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/circular-oldlocation/123");
         httpget.setConfig(config);
-        try {
-            this.httpclient.execute(target, httpget);
-        } catch (final ClientProtocolException e) {
-            Assert.assertTrue(e.getCause() instanceof RedirectException);
-            throw e;
-        }
+        final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
+                this.httpclient.execute(target, httpget));
+        Assert.assertTrue(exception.getCause() instanceof RedirectException);
     }
 
-    @Test(expected = ClientProtocolException.class)
+    @Test
     public void testCircularRedirect() throws Exception {
         final HttpHost target = start(null, requestHandler -> new RedirectingDecorator(
                 requestHandler,
@@ -327,12 +324,9 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/circular-oldlocation/123");
         httpget.setConfig(config);
-        try {
-            this.httpclient.execute(target, httpget);
-        } catch (final ClientProtocolException e) {
-            Assert.assertTrue(e.getCause() instanceof CircularRedirectException);
-            throw e;
-        }
+        final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
+                this.httpclient.execute(target, httpget));
+        Assert.assertTrue(exception.getCause() instanceof CircularRedirectException);
     }
 
     @Test
@@ -415,7 +409,7 @@ public class TestRedirects extends LocalServerTestBase {
 
     }
 
-    @Test(expected = ClientProtocolException.class)
+    @Test
     public void testRejectBogusRedirectLocation() throws Exception {
         final HttpHost target = start(null, requestHandler -> new RedirectingDecorator(
                 requestHandler,
@@ -430,16 +424,12 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation");
 
-        try {
-            this.httpclient.execute(target, httpget);
-        } catch (final ClientProtocolException ex) {
-            final Throwable cause = ex.getCause();
-            Assert.assertTrue(cause instanceof HttpException);
-            throw ex;
-        }
+        final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
+                this.httpclient.execute(target, httpget));
+        MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(HttpException.class));
     }
 
-    @Test(expected = ClientProtocolException.class)
+    @Test
     public void testRejectInvalidRedirectLocation() throws Exception {
         final HttpHost target = start(null, requestHandler -> new RedirectingDecorator(
                 requestHandler,
@@ -454,12 +444,9 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation");
 
-        try {
-            this.httpclient.execute(target, httpget);
-        } catch (final ClientProtocolException e) {
-            Assert.assertTrue(e.getCause() instanceof ProtocolException);
-            throw e;
-        }
+        final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
+                this.httpclient.execute(target, httpget));
+        MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(ProtocolException.class));
     }
 
     @Test
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java
index 31b32b0..396f5f9 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java
@@ -55,6 +55,8 @@ import org.apache.hc.core5.io.CloseMode;
 import org.apache.hc.core5.ssl.SSLContexts;
 import org.apache.hc.core5.ssl.TrustStrategy;
 import org.apache.hc.core5.util.TimeValue;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
@@ -181,7 +183,7 @@ public class TestSSLSocketFactory {
         }
     }
 
-    @Test(expected = IOException.class)
+    @Test
     public void testClientAuthSSLFailure() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
@@ -208,12 +210,13 @@ public class TestSSLSocketFactory {
 
                 Assert.assertNotNull(sslsession);
                 Assert.assertTrue(hostVerifier.isFired());
-                sslSocket.getInputStream().read();
+                Assert.assertThrows(IOException.class, () ->
+                        sslSocket.getInputStream().read());
             }
         }
     }
 
-    @Test(expected = SSLException.class)
+    @Test
     public void testSSLTrustVerification() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
@@ -232,10 +235,12 @@ public class TestSSLSocketFactory {
         try (final Socket socket = socketFactory.createSocket(context)) {
             final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
             final HttpHost target = new HttpHost("https", "localhost", this.server.getLocalPort());
-            try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(TimeValue.ZERO_MILLISECONDS, socket, target, remoteAddress,
-                    null, context)) {
-                // empty for now
-            }
+            Assert.assertThrows(SSLException.class, () -> {
+                try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(
+                        TimeValue.ZERO_MILLISECONDS, socket, target, remoteAddress, null, context)) {
+                    // empty for now
+                }
+            });
         }
     }
 
@@ -284,7 +289,7 @@ public class TestSSLSocketFactory {
         }
     }
 
-    @Test(expected = IOException.class)
+    @Test
     public void testSSLDisabledByDefault() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
@@ -300,7 +305,9 @@ public class TestSSLSocketFactory {
         try (final Socket socket = socketFactory.createSocket(context)) {
             final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
             final HttpHost target = new HttpHost("https", "localhost", this.server.getLocalPort());
-            socketFactory.connectSocket(TimeValue.ZERO_MILLISECONDS, socket, target, remoteAddress, null, context);
+            Assert.assertThrows(IOException.class, () ->
+                    socketFactory.connectSocket(
+                            TimeValue.ZERO_MILLISECONDS, socket, target, remoteAddress, null, context));
         }
     }
 
@@ -324,12 +331,11 @@ public class TestSSLSocketFactory {
                 "SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5"
         };
         for (final String cipherSuite : weakCiphersSuites) {
-            try {
-                testWeakCipherDisabledByDefault(cipherSuite);
-                Assert.fail("IOException expected");
-            } catch (final Exception e) {
-                Assert.assertTrue(e instanceof IOException || e instanceof IllegalArgumentException);
-            }
+            final Exception exception = Assert.assertThrows(Exception.class, () ->
+                    testWeakCipherDisabledByDefault(cipherSuite));
+            MatcherAssert.assertThat(exception, CoreMatchers.anyOf(
+                    CoreMatchers.instanceOf(IOException.class),
+                    CoreMatchers.instanceOf(IllegalArgumentException.class)));
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/classic/methods/TestHttpTrace.java b/httpclient5/src/test/java/org/apache/hc/client5/http/classic/methods/TestHttpTrace.java
index 27089d2..4cc58f9 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/classic/methods/TestHttpTrace.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/classic/methods/TestHttpTrace.java
@@ -27,14 +27,16 @@
 
 package org.apache.hc.client5.http.classic.methods;
 
+import org.junit.Assert;
 import org.junit.Test;
 
 public class TestHttpTrace {
 
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void testHttpTraceSetEntity() {
         final HttpTrace httpTrace = new HttpTrace("/path");
-        httpTrace.setEntity(null);
+        Assert.assertThrows(IllegalStateException.class, () ->
+            httpTrace.setEntity(null));
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/cookie/TestCookieOrigin.java b/httpclient5/src/test/java/org/apache/hc/client5/http/cookie/TestCookieOrigin.java
index ad32d1b..a9646af 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/cookie/TestCookieOrigin.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/cookie/TestCookieOrigin.java
@@ -44,28 +44,28 @@ public class TestCookieOrigin {
         Assert.assertFalse(origin.isSecure());
     }
 
-    @SuppressWarnings("unused")
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testNullHost() {
-        new CookieOrigin(null, 80, "/", false);
+        Assert.assertThrows(NullPointerException.class, () ->
+                new CookieOrigin(null, 80, "/", false));
     }
 
-    @SuppressWarnings("unused")
-    @Test(expected=IllegalArgumentException.class)
+    @Test
     public void testEmptyHost() {
-        new CookieOrigin("   ", 80, "/", false);
+        Assert.assertThrows(IllegalArgumentException.class, () ->
+            new CookieOrigin("   ", 80, "/", false));
     }
 
-    @SuppressWarnings("unused")
-    @Test(expected=IllegalArgumentException.class)
+    @Test
     public void testNegativePort() {
-        new CookieOrigin("www.apache.org", -80, "/", false);
+        Assert.assertThrows(IllegalArgumentException.class, () ->
+                new CookieOrigin("www.apache.org", -80, "/", false));
     }
 
-    @SuppressWarnings("unused")
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testNullPath() {
-        new CookieOrigin("www.apache.org", 80, null, false);
+        Assert.assertThrows(NullPointerException.class, () ->
+                new CookieOrigin("www.apache.org", 80, null, false));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestEntityBuilder.java b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestEntityBuilder.java
index 9158afc..72ad25c 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestEntityBuilder.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestEntityBuilder.java
@@ -39,11 +39,10 @@ import org.mockito.Mockito;
 
 public class TestEntityBuilder {
 
-    @Test(expected=IllegalStateException.class)
+    @Test
     public void testBuildEmptyEntity() throws Exception {
-        final HttpEntity entity = EntityBuilder.create().build();
-        Assert.assertNotNull(entity);
-        entity.getContent();
+        Assert.assertThrows(IllegalStateException.class, () ->
+                EntityBuilder.create().build());
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578MultipartTest.java b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578MultipartTest.java
index 64108f1..3b98cab 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578MultipartTest.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578MultipartTest.java
@@ -27,20 +27,22 @@
 
 package org.apache.hc.client5.http.entity.mime;
 
+import static org.junit.Assert.assertEquals;
+
 import org.apache.commons.codec.DecoderException;
+import org.junit.Assert;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-
 public class HttpRFC7578MultipartTest {
 
-    @Test(expected = DecoderException.class)
-    public void testPercentDecodingWithTooShortMessage() throws DecoderException {
-        new HttpRFC7578Multipart.PercentCodec().decode("%".getBytes());
+    @Test
+    public void testPercentDecodingWithTooShortMessage() throws Exception {
+        Assert.assertThrows(DecoderException.class, () ->
+                new HttpRFC7578Multipart.PercentCodec().decode("%".getBytes()));
     }
 
     @Test
-    public void testPercentDecodingWithValidMessages() throws DecoderException {
+    public void testPercentDecodingWithValidMessages() throws Exception {
         final HttpRFC7578Multipart.PercentCodec codec = new HttpRFC7578Multipart.PercentCodec();
         final String[][] tests = new String[][] {
                 {"test", "test"},
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java
index 22db279..4364d1a 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java
@@ -43,11 +43,12 @@ import org.junit.Test;
  */
 public class TestDefaultConnKeepAliveStrategy {
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testIllegalResponseArg() throws Exception {
         final HttpContext context = new BasicHttpContext(null);
         final ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
-        keepAliveStrat.getKeepAliveDuration(null, context);
+        Assert.assertThrows(NullPointerException.class, () ->
+                keepAliveStrat.getKeepAliveDuration(null, context));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultRedirectStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultRedirectStrategy.java
index 06a6a94..d07b295 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultRedirectStrategy.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultRedirectStrategy.java
@@ -135,23 +135,25 @@ public class TestDefaultRedirectStrategy {
         Assert.assertEquals(URI.create("http://localhost/stuff"), uri);
     }
 
-    @Test(expected=HttpException.class)
+    @Test
     public void testGetLocationUriMissingHeader() throws Exception {
         final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
         final HttpClientContext context = HttpClientContext.create();
         final HttpGet httpget = new HttpGet("http://localhost/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
-        redirectStrategy.getLocationURI(httpget, response, context);
+        Assert.assertThrows(HttpException.class, () ->
+                redirectStrategy.getLocationURI(httpget, response, context));
     }
 
-    @Test(expected=ProtocolException.class)
+    @Test
     public void testGetLocationUriInvalidLocation() throws Exception {
         final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
         final HttpClientContext context = HttpClientContext.create();
         final HttpGet httpget = new HttpGet("http://localhost/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
         response.addHeader("Location", "http://localhost/not valid");
-        redirectStrategy.getLocationURI(httpget, response, context);
+        Assert.assertThrows(ProtocolException.class, () ->
+                redirectStrategy.getLocationURI(httpget, response, context));
     }
 
     @Test
@@ -229,10 +231,11 @@ public class TestDefaultRedirectStrategy {
                 redirectStrategy.createLocationURI("http://BlahBlah").toASCIIString());
     }
 
-    @Test(expected=ProtocolException.class)
+    @Test
     public void testCreateLocationURIInvalid() throws Exception {
         final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
-        redirectStrategy.createLocationURI(":::::::");
+        Assert.assertThrows(ProtocolException.class, () ->
+                redirectStrategy.createLocationURI(":::::::"));
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java
index ac61d4d..60dee1a 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestAuthChallengeParser.java
@@ -253,28 +253,31 @@ public class TestAuthChallengeParser {
         Assert.assertNull(challenge1.getParams());
     }
 
-    @Test(expected = ParseException.class)
+    @Test
     public void testParseMalformedAuthChallenge1() throws Exception {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("This , ");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        parser.parse(ChallengeType.TARGET, buffer, cursor);
+        Assert.assertThrows(ParseException.class, () ->
+                parser.parse(ChallengeType.TARGET, buffer, cursor));
     }
 
-    @Test(expected = ParseException.class)
+    @Test
     public void testParseMalformedAuthChallenge2() throws Exception {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("This = that");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        parser.parse(ChallengeType.TARGET, buffer, cursor);
+        Assert.assertThrows(ParseException.class, () ->
+                parser.parse(ChallengeType.TARGET, buffer, cursor));
     }
 
-    @Test(expected = ParseException.class)
+    @Test
     public void testParseMalformedAuthChallenge3() throws Exception {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("blah blah blah");
         final ParserCursor cursor = new ParserCursor(0, buffer.length());
-        parser.parse(ChallengeType.TARGET, buffer, cursor);
+        Assert.assertThrows(ParseException.class, () ->
+                parser.parse(ChallengeType.TARGET, buffer, cursor));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicAuthCache.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicAuthCache.java
index d1ebfe7..b57fa6d 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicAuthCache.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicAuthCache.java
@@ -51,11 +51,12 @@ public class TestBasicAuthCache {
         Assert.assertNull(cache.get(new HttpHost("localhost", 80)));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void testNullKey() throws Exception {
         final BasicAuthCache cache = new BasicAuthCache();
         final AuthScheme authScheme = new BasicScheme();
-        cache.put(null, authScheme);
+        Assert.assertThrows(NullPointerException.class, () ->
+                cache.put(null, authScheme));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestDigestScheme.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestDigestScheme.java
index 9fafcc2..7a402d7 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestDigestScheme.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestDigestScheme.java
@@ -39,12 +39,12 @@ import java.util.Map;
 
 import org.apache.hc.client5.http.auth.AuthChallenge;
 import org.apache.hc.client5.http.auth.AuthScheme;
-import org.apache.hc.client5.http.auth.StandardAuthScheme;
 import org.apache.hc.client5.http.auth.AuthScope;
 import org.apache.hc.client5.http.auth.AuthenticationException;
 import org.apache.hc.client5.http.auth.ChallengeType;
 import org.apache.hc.client5.http.auth.Credentials;
 import org.apache.hc.client5.http.auth.MalformedChallengeException;
+import org.apache.hc.client5.http.auth.StandardAuthScheme;
 import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ContentType;
@@ -76,18 +76,20 @@ public class TestDigestScheme {
         return authChallenges.get(0);
     }
 
-    @Test(expected=MalformedChallengeException.class)
+    @Test
     public void testDigestAuthenticationEmptyChallenge1() throws Exception {
         final AuthChallenge authChallenge = parse(StandardAuthScheme.DIGEST);
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge, null);
+        Assert.assertThrows(MalformedChallengeException.class, () ->
+                authscheme.processChallenge(authChallenge, null));
     }
 
-    @Test(expected=MalformedChallengeException.class)
+    @Test
     public void testDigestAuthenticationEmptyChallenge2() throws Exception {
         final AuthChallenge authChallenge = parse(StandardAuthScheme.DIGEST + " ");
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge, null);
+        Assert.assertThrows(MalformedChallengeException.class, () ->
+                authscheme.processChallenge(authChallenge, null));
     }
 
     @Test
@@ -224,7 +226,7 @@ public class TestDigestScheme {
         Assert.assertEquals("a847f58f5fef0bc087bcb9c3eb30e042", table.get("response"));
     }
 
-    @Test(expected=AuthenticationException.class)
+    @Test
     public void testDigestAuthenticationNoRealm() throws Exception {
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final HttpHost host = new HttpHost("somehost", 80);
@@ -239,10 +241,11 @@ public class TestDigestScheme {
         authscheme.processChallenge(authChallenge, null);
 
         Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
-        authscheme.generateAuthResponse(host, request, null);
+        Assert.assertThrows(AuthenticationException.class, () ->
+                authscheme.generateAuthResponse(host, request, null));
     }
 
-    @Test(expected=AuthenticationException.class)
+    @Test
     public void testDigestAuthenticationNoNonce() throws Exception {
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final HttpHost host = new HttpHost("somehost", 80);
@@ -257,7 +260,8 @@ public class TestDigestScheme {
         authscheme.processChallenge(authChallenge, null);
 
         Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
-        authscheme.generateAuthResponse(host, request, null);
+        Assert.assertThrows(AuthenticationException.class, () ->
+                authscheme.generateAuthResponse(host, request, null));
     }
 
     /**
@@ -359,7 +363,7 @@ public class TestDigestScheme {
     /**
      * Test digest authentication with unknown qop value
      */
-    @Test(expected=AuthenticationException.class)
+    @Test
     public void testDigestAuthenticationMD5SessUnknownQop() throws Exception {
         // Example using Digest auth with MD5-sess
 
@@ -388,13 +392,14 @@ public class TestDigestScheme {
         authscheme.processChallenge(authChallenge, null);
 
         Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
-        authscheme.generateAuthResponse(host, request, null);
+        Assert.assertThrows(AuthenticationException.class, () ->
+                authscheme.generateAuthResponse(host, request, null));
     }
 
     /**
      * Test digest authentication with unknown qop value
      */
-    @Test(expected=AuthenticationException.class)
+    @Test
     public void testDigestAuthenticationUnknownAlgo() throws Exception {
         // Example using Digest auth with MD5-sess
 
@@ -423,7 +428,8 @@ public class TestDigestScheme {
         authscheme.processChallenge(authChallenge, null);
 
         Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
-        authscheme.generateAuthResponse(host, request, null);
+        Assert.assertThrows(AuthenticationException.class, () ->
+                authscheme.generateAuthResponse(host, request, null));
     }
 
     @Test
@@ -689,7 +695,7 @@ public class TestDigestScheme {
         authscheme.generateAuthResponse(host, request, null);
     }
 
-    @Test(expected=AuthenticationException.class)
+    @Test
     public void testDigestAuthenticationQopIntOnlyNonRepeatableEntity() throws Exception {
         final ClassicHttpRequest request = new BasicClassicHttpRequest("Post", "/");
         request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1, ContentType.DEFAULT_TEXT));
@@ -706,7 +712,8 @@ public class TestDigestScheme {
         authscheme.processChallenge(authChallenge, null);
 
         Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
-        authscheme.generateAuthResponse(host, request, null);
+        Assert.assertThrows(AuthenticationException.class, () ->
+                authscheme.generateAuthResponse(host, request, null));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestRequestAuthCache.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestRequestAuthCache.java
index 29b784a..88eb72e 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestRequestAuthCache.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestRequestAuthCache.java
@@ -71,18 +71,20 @@ public class TestRequestAuthCache {
         this.credProvider.setCredentials(this.authscope2, this.creds2);
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testRequestParameterCheck() throws Exception {
         final HttpClientContext context = HttpClientContext.create();
         final HttpRequestInterceptor interceptor = new RequestAuthCache();
-        interceptor.process(null, null, context);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(null, null, context));
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testContextParameterCheck() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpRequestInterceptor interceptor = new RequestAuthCache();
-        interceptor.process(request, null, null);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(request, null, null));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java
index 0b0b5c5..c0261df 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java
@@ -130,7 +130,7 @@ public class TestCloseableHttpClient {
         Mockito.verify(content).close();
     }
 
-    @Test(expected=IOException.class)
+    @Test
     public void testExecuteRequestHandleResponseIOException() throws Exception {
         final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
 
@@ -141,19 +141,16 @@ public class TestCloseableHttpClient {
 
         Mockito.when(handler.handleResponse(response)).thenThrow(new IOException());
 
-        try {
-            client.execute(httpget, handler);
-        } catch (final IOException ex) {
-            Mockito.verify(client).doExecute(
-                    Mockito.eq(new HttpHost("https", "somehost", 444)),
-                    Mockito.same(httpget),
-                    (HttpContext) Mockito.isNull());
-            Mockito.verify(originResponse).close();
-            throw ex;
-        }
+        final IOException exception = Assert.assertThrows(IOException.class, () ->
+            client.execute(httpget, handler));
+        Mockito.verify(client).doExecute(
+                Mockito.eq(new HttpHost("https", "somehost", 444)),
+                Mockito.same(httpget),
+                (HttpContext) Mockito.isNull());
+        Mockito.verify(originResponse).close();
     }
 
-    @Test(expected=RuntimeException.class)
+    @Test
     public void testExecuteRequestHandleResponseHttpException() throws Exception {
         final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
 
@@ -164,16 +161,13 @@ public class TestCloseableHttpClient {
 
         Mockito.when(handler.handleResponse(response)).thenThrow(new RuntimeException());
 
-        try {
-            client.execute(httpget, handler);
-        } catch (final RuntimeException ex) {
-            Mockito.verify(client).doExecute(
-                    Mockito.eq(new HttpHost("https", "somehost", 444)),
-                    Mockito.same(httpget),
-                    (HttpContext) Mockito.isNull());
-            Mockito.verify(response).close();
-            throw ex;
-        }
+        Assert.assertThrows(RuntimeException.class, () ->
+                client.execute(httpget, handler));
+        Mockito.verify(client).doExecute(
+                Mockito.eq(new HttpHost("https", "somehost", 444)),
+                Mockito.same(httpget),
+                (HttpContext) Mockito.isNull());
+        Mockito.verify(originResponse).close();
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java
index 0505aa8..1fde3b6 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java
@@ -181,7 +181,7 @@ public class TestConnectExec {
         Assert.assertEquals("foo:80", connect.getRequestUri());
     }
 
-    @Test(expected = HttpException.class)
+    @Test
     public void testEstablishRouteViaProxyTunnelUnexpectedResponse() throws Exception {
         final HttpRoute route = new HttpRoute(target, null, proxy, true);
         final HttpClientContext context = new HttpClientContext();
@@ -197,10 +197,11 @@ public class TestConnectExec {
                 Mockito.any())).thenReturn(response);
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
-        exec.execute(request, scope, execChain);
+        Assert.assertThrows(HttpException.class, () ->
+                exec.execute(request, scope, execChain));
     }
 
-    @Test(expected = HttpException.class)
+    @Test
     public void testEstablishRouteViaProxyTunnelFailure() throws Exception {
         final HttpRoute route = new HttpRoute(target, null, proxy, true);
         final HttpClientContext context = new HttpClientContext();
@@ -217,14 +218,11 @@ public class TestConnectExec {
                 Mockito.any())).thenReturn(response);
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
-        try {
-            exec.execute(request, scope, execChain);
-        } catch (final TunnelRefusedException ex) {
-            Assert.assertEquals("Ka-boom", ex.getResponseMessage());
-            Mockito.verify(execRuntime).disconnectEndpoint();
-            Mockito.verify(execRuntime).discardEndpoint();
-            throw ex;
-        }
+        final TunnelRefusedException exception = Assert.assertThrows(TunnelRefusedException.class, () ->
+                exec.execute(request, scope, execChain));
+        Assert.assertEquals("Ka-boom", exception.getResponseMessage());
+        Mockito.verify(execRuntime).disconnectEndpoint();
+        Mockito.verify(execRuntime).discardEndpoint();
     }
 
     @Test
@@ -310,7 +308,7 @@ public class TestConnectExec {
         Mockito.verify(execRuntime).disconnectEndpoint();
     }
 
-    @Test(expected = HttpException.class)
+    @Test
     public void testEstablishRouteViaProxyTunnelMultipleHops() throws Exception {
         final HttpHost proxy1 = new HttpHost("this", 8888);
         final HttpHost proxy2 = new HttpHost("that", 8888);
@@ -324,7 +322,8 @@ public class TestConnectExec {
         Mockito.when(execRuntime.isEndpointConnected()).thenAnswer(connectionState.isConnectedAnswer());
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
-        exec.execute(request, scope, execChain);
+        Assert.assertThrows(HttpException.class, () ->
+                exec.execute(request, scope, execChain));
     }
 
     static class ConnectionState {
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java
index ff045da..048f5ed 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java
@@ -184,7 +184,7 @@ public class TestContentCompressionExec {
         Assert.assertTrue(entity instanceof StringEntity);
     }
 
-    @Test(expected=HttpException.class)
+    @Test
     public void testUnknownContentEncoding() throws Exception {
         final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
@@ -195,7 +195,8 @@ public class TestContentCompressionExec {
 
         Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
 
-        impl.execute(request, scope, execChain);
+        Assert.assertThrows(HttpException.class, () ->
+                impl.execute(request, scope, execChain));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestFutureRequestExecutionService.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestFutureRequestExecutionService.java
index 61d6b4b..c6962f2 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestFutureRequestExecutionService.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestFutureRequestExecutionService.java
@@ -50,12 +50,11 @@ import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
 import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
 import org.apache.hc.core5.http.io.HttpClientResponseHandler;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 @SuppressWarnings("boxing") // test code
 public class TestFutureRequestExecutionService {
@@ -66,9 +65,6 @@ public class TestFutureRequestExecutionService {
 
     private final AtomicBoolean blocked = new AtomicBoolean(false);
 
-    @Rule
-    public final ExpectedException thrown = ExpectedException.none();
-
     @Before
     public void before() throws Exception {
         this.localServer = ServerBootstrap.bootstrap()
@@ -111,24 +107,22 @@ public class TestFutureRequestExecutionService {
 
     @Test
     public void shouldCancel() throws InterruptedException, ExecutionException {
-        thrown.expect(CoreMatchers.anyOf(
-                CoreMatchers.instanceOf(CancellationException.class),
-                CoreMatchers.instanceOf(ExecutionException.class)));
-
         final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
             new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
         task.cancel(true);
-        task.get();
+        final Exception exception = Assert.assertThrows(Exception.class, task::get);
+        MatcherAssert.assertThat(exception, CoreMatchers.anyOf(
+                CoreMatchers.instanceOf(CancellationException.class),
+                CoreMatchers.instanceOf(ExecutionException.class)));
     }
 
     @Test
     public void shouldTimeout() throws InterruptedException, ExecutionException, TimeoutException {
-        thrown.expect(TimeoutException.class);
-
         blocked.set(true);
         final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
             new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
-        task.get(10, TimeUnit.MILLISECONDS);
+        Assert.assertThrows(TimeoutException.class, () ->
+                task.get(10, TimeUnit.MILLISECONDS));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
index 805a341..9343e9e 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
@@ -168,7 +168,7 @@ public class TestHttpRequestRetryExec {
         Mockito.verify(response, Mockito.times(1)).close();
     }
 
-    @Test(expected = RuntimeException.class)
+    @Test
     public void testStrategyRuntimeException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final ClassicHttpRequest request = new HttpGet("/test");
@@ -183,12 +183,9 @@ public class TestHttpRequestRetryExec {
                 Mockito.anyInt(),
                 Mockito.any());
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        try {
-            retryExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(response).close();
-            throw ex;
-        }
+        Assert.assertThrows(RuntimeException.class, () ->
+                retryExec.execute(request, scope, chain));
+        Mockito.verify(response).close();
     }
 
     @Test
@@ -213,7 +210,7 @@ public class TestHttpRequestRetryExec {
         Mockito.verify(response, Mockito.times(0)).close();
     }
 
-    @Test(expected = IOException.class)
+    @Test
     public void testFundamentals2() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpGet originalRequest = new HttpGet("/test");
@@ -240,18 +237,15 @@ public class TestHttpRequestRetryExec {
                 Mockito.any())).thenReturn(Boolean.TRUE);
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context);
         final ClassicHttpRequest request = ClassicRequestBuilder.copy(originalRequest).build();
-        try {
-            retryExec.execute(request, scope, chain);
-        } catch (final IOException ex) {
-            Mockito.verify(chain, Mockito.times(2)).proceed(
-                    Mockito.any(),
-                    Mockito.same(scope));
-            throw ex;
-        }
+        Assert.assertThrows(IOException.class, () ->
+                retryExec.execute(request, scope, chain));
+        Mockito.verify(chain, Mockito.times(2)).proceed(
+                Mockito.any(),
+                Mockito.same(scope));
     }
 
 
-    @Test(expected = IOException.class)
+    @Test
     public void testAbortedRequest() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpGet originalRequest = new HttpGet("/test");
@@ -264,23 +258,19 @@ public class TestHttpRequestRetryExec {
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context);
         final ClassicHttpRequest request = ClassicRequestBuilder.copy(originalRequest).build();
-        try {
-            retryExec.execute(request, scope, chain);
-        } catch (final IOException ex) {
-            Mockito.verify(chain, Mockito.times(1)).proceed(
-                    Mockito.same(request),
-                    Mockito.same(scope));
-            Mockito.verify(retryStrategy, Mockito.never()).retryRequest(
-                    Mockito.any(),
-                    Mockito.any(),
-                    Mockito.anyInt(),
-                    Mockito.any());
-
-            throw ex;
-        }
+        Assert.assertThrows(IOException.class, () ->
+                retryExec.execute(request, scope, chain));
+        Mockito.verify(chain, Mockito.times(1)).proceed(
+                Mockito.same(request),
+                Mockito.same(scope));
+        Mockito.verify(retryStrategy, Mockito.never()).retryRequest(
+                Mockito.any(),
+                Mockito.any(),
+                Mockito.anyInt(),
+                Mockito.any());
     }
 
-    @Test(expected = IOException.class)
+    @Test
     public void testNonRepeatableRequest() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpPost originalRequest = new HttpPost("/test");
@@ -299,15 +289,11 @@ public class TestHttpRequestRetryExec {
                 });
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context);
         final ClassicHttpRequest request = ClassicRequestBuilder.copy(originalRequest).build();
-        try {
-            retryExec.execute(request, scope, chain);
-        } catch (final IOException ex) {
-            Mockito.verify(chain, Mockito.times(1)).proceed(
-                    Mockito.same(request),
-                    Mockito.same(scope));
-
-            throw ex;
-        }
+        Assert.assertThrows(IOException.class, () ->
+                retryExec.execute(request, scope, chain));
+        Mockito.verify(chain, Mockito.times(1)).proceed(
+                Mockito.same(request),
+                Mockito.same(scope));
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java
index dc2483b..c57e378 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java
@@ -105,7 +105,7 @@ public class TestInternalExecRuntime {
         Mockito.verify(cancellableDependency, Mockito.times(2)).setDependency(Mockito.any());
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void testAcquireEndpointAlreadyAcquired() throws Exception {
         final HttpClientContext context = HttpClientContext.create();
 
@@ -118,10 +118,11 @@ public class TestInternalExecRuntime {
         Assert.assertTrue(execRuntime.isEndpointAcquired());
         Assert.assertSame(connectionEndpoint, execRuntime.ensureValid());
 
-        execRuntime.acquireEndpoint("some-id", route, null, context);
+        Assert.assertThrows(IllegalStateException.class, () ->
+                execRuntime.acquireEndpoint("some-id", route, null, context));
     }
 
-    @Test(expected = ConnectionRequestTimeoutException.class)
+    @Test
     public void testAcquireEndpointLeaseRequestTimeout() throws Exception {
         final HttpClientContext context = HttpClientContext.create();
 
@@ -129,10 +130,11 @@ public class TestInternalExecRuntime {
                 .thenReturn(leaseRequest);
         Mockito.when(leaseRequest.get(Mockito.any())).thenThrow(new TimeoutException("timeout"));
 
-        execRuntime.acquireEndpoint("some-id", route, null, context);
+        Assert.assertThrows(ConnectionRequestTimeoutException.class, () ->
+                execRuntime.acquireEndpoint("some-id", route, null, context));
     }
 
-    @Test(expected = RequestFailedException.class)
+    @Test
     public void testAcquireEndpointLeaseRequestFailure() throws Exception {
         final HttpClientContext context = HttpClientContext.create();
 
@@ -140,7 +142,8 @@ public class TestInternalExecRuntime {
                 .thenReturn(leaseRequest);
         Mockito.when(leaseRequest.get(Mockito.any())).thenThrow(new ExecutionException(new IllegalStateException()));
 
-        execRuntime.acquireEndpoint("some-id", route, null, context);
+        Assert.assertThrows(RequestFailedException.class, () ->
+                execRuntime.acquireEndpoint("some-id", route, null, context));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java
index fc09cf2..146af1f 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java
@@ -111,7 +111,7 @@ public class TestInternalHttpClient {
                 Mockito.any());
     }
 
-    @Test(expected=ClientProtocolException.class)
+    @Test
     public void testExecuteHttpException() throws Exception {
         final HttpGet httpget = new HttpGet("http://somehost/stuff");
         final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
@@ -124,7 +124,8 @@ public class TestInternalHttpClient {
                 Mockito.any(),
                 Mockito.any())).thenThrow(new HttpException());
 
-        client.execute(httpget);
+        Assert.assertThrows(ClientProtocolException.class, () ->
+                client.execute(httpget));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java
index d35e938..574e125 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java
@@ -237,7 +237,7 @@ public class TestMainClientExec {
         Mockito.verify(endpoint).discardEndpoint();
     }
 
-    @Test(expected=InterruptedIOException.class)
+    @Test
     public void testExecConnectionShutDown() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpClientContext context = new HttpClientContext();
@@ -249,15 +249,12 @@ public class TestMainClientExec {
                 Mockito.any())).thenThrow(new ConnectionShutdownException());
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (final Exception ex) {
-            Mockito.verify(endpoint).discardEndpoint();
-            throw ex;
-        }
+        Assert.assertThrows(InterruptedIOException.class, () ->
+                mainClientExec.execute(request, scope, null));
+        Mockito.verify(endpoint).discardEndpoint();
     }
 
-    @Test(expected=RuntimeException.class)
+    @Test
     public void testExecRuntimeException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpClientContext context = new HttpClientContext();
@@ -269,15 +266,12 @@ public class TestMainClientExec {
                 Mockito.any())).thenThrow(new RuntimeException("Ka-boom"));
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (final Exception ex) {
-            Mockito.verify(endpoint).discardEndpoint();
-            throw ex;
-        }
+        Assert.assertThrows(RuntimeException.class, () ->
+                mainClientExec.execute(request, scope, null));
+        Mockito.verify(endpoint).discardEndpoint();
     }
 
-    @Test(expected=HttpException.class)
+    @Test
     public void testExecHttpException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpClientContext context = new HttpClientContext();
@@ -289,15 +283,12 @@ public class TestMainClientExec {
                 Mockito.any())).thenThrow(new HttpException("Ka-boom"));
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (final Exception ex) {
-            Mockito.verify(endpoint).discardEndpoint();
-            throw ex;
-        }
+        Assert.assertThrows(HttpException.class, () ->
+                mainClientExec.execute(request, scope, null));
+        Mockito.verify(endpoint).discardEndpoint();
     }
 
-    @Test(expected=IOException.class)
+    @Test
     public void testExecIOException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpClientContext context = new HttpClientContext();
@@ -309,12 +300,9 @@ public class TestMainClientExec {
                 Mockito.any())).thenThrow(new IOException("Ka-boom"));
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (final Exception ex) {
-            Mockito.verify(endpoint).discardEndpoint();
-            throw ex;
-        }
+        Assert.assertThrows(IOException.class, () ->
+                mainClientExec.execute(request, scope, null));
+        Mockito.verify(endpoint).discardEndpoint();
     }
 
     static class ConnectionState {
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java
index 7de03b3..9f0fb6f 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java
@@ -139,7 +139,7 @@ public class TestProtocolExec {
         Assert.assertEquals("somefella", creds.getUserPrincipal().getName());
     }
 
-    @Test(expected = HttpException.class)
+    @Test
     public void testPostProcessHttpException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final ClassicHttpRequest request = new HttpGet("/test");
@@ -153,15 +153,12 @@ public class TestProtocolExec {
         Mockito.doThrow(new HttpException("Ooopsie")).when(httpProcessor).process(
                 Mockito.same(response), Mockito.isNull(), Mockito.any());
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
-        try {
-            protocolExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(execRuntime).discardEndpoint();
-            throw ex;
-        }
+        Assert.assertThrows(HttpException.class, () ->
+                protocolExec.execute(request, scope, chain));
+        Mockito.verify(execRuntime).discardEndpoint();
     }
 
-    @Test(expected = IOException.class)
+    @Test
     public void testPostProcessIOException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final ClassicHttpRequest request = new HttpGet("/test");
@@ -174,15 +171,12 @@ public class TestProtocolExec {
         Mockito.doThrow(new IOException("Ooopsie")).when(httpProcessor).process(
                 Mockito.same(response), Mockito.isNull(), Mockito.any());
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
-        try {
-            protocolExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(execRuntime).discardEndpoint();
-            throw ex;
-        }
+        Assert.assertThrows(IOException.class, () ->
+                protocolExec.execute(request, scope, chain));
+        Mockito.verify(execRuntime).discardEndpoint();
     }
 
-    @Test(expected = RuntimeException.class)
+    @Test
     public void testPostProcessRuntimeException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final ClassicHttpRequest request = new HttpGet("/test");
@@ -195,12 +189,9 @@ public class TestProtocolExec {
         Mockito.doThrow(new RuntimeException("Ooopsie")).when(httpProcessor).process(
                 Mockito.same(response), Mockito.isNull(), Mockito.any());
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
-        try {
-            protocolExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(execRuntime).discardEndpoint();
-            throw ex;
-        }
+        Assert.assertThrows(RuntimeException.class, () ->
+                protocolExec.execute(request, scope, chain));
+        Mockito.verify(execRuntime).discardEndpoint();
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java
index d8dbcbf..339eb1d 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java
@@ -135,7 +135,7 @@ public class TestRedirectExec {
         Mockito.verify(inStream2, Mockito.never()).close();
     }
 
-    @Test(expected = RedirectException.class)
+    @Test
     public void testMaxRedirect() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpGet request = new HttpGet("/test");
@@ -153,10 +153,11 @@ public class TestRedirectExec {
         Mockito.when(chain.proceed(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(response1);
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        redirectExec.execute(request, scope, chain);
+        Assert.assertThrows(RedirectException.class, () ->
+                redirectExec.execute(request, scope, chain));
     }
 
-    @Test(expected = HttpException.class)
+    @Test
     public void testRelativeRedirect() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpGet request = new HttpGet("/test");
@@ -170,7 +171,8 @@ public class TestRedirectExec {
                 ArgumentMatchers.any())).thenReturn(response1);
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        redirectExec.execute(request, scope, chain);
+        Assert.assertThrows(HttpException.class, () ->
+                redirectExec.execute(request, scope, chain));
     }
 
     @Test
@@ -260,7 +262,7 @@ public class TestRedirectExec {
         Assert.assertEquals(Arrays.asList(uri1, uri2, uri1), uris.getAll());
     }
 
-    @Test(expected=CircularRedirectException.class)
+    @Test
     public void testGetLocationUriDisallowCircularRedirects() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpClientContext context = HttpClientContext.create();
@@ -294,10 +296,11 @@ public class TestRedirectExec {
                 ArgumentMatchers.any())).thenReturn(response3);
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        redirectExec.execute(request, scope, chain);
+        Assert.assertThrows(CircularRedirectException.class, () ->
+                redirectExec.execute(request, scope, chain));
     }
 
-    @Test(expected = RuntimeException.class)
+    @Test
     public void testRedirectRuntimeException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpGet request = new HttpGet("/test");
@@ -315,15 +318,12 @@ public class TestRedirectExec {
                 ArgumentMatchers.<HttpClientContext>any());
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        try {
-            redirectExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(response1).close();
-            throw ex;
-        }
+        Assert.assertThrows(RuntimeException.class, () ->
+                redirectExec.execute(request, scope, chain));
+        Mockito.verify(response1).close();
     }
 
-    @Test(expected = ProtocolException.class)
+    @Test
     public void testRedirectProtocolException() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpGet request = new HttpGet("/test");
@@ -346,13 +346,10 @@ public class TestRedirectExec {
                 ArgumentMatchers.<HttpClientContext>any());
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
-        try {
-            redirectExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(inStream1, Mockito.times(2)).close();
-            Mockito.verify(response1).close();
-            throw ex;
-        }
+        Assert.assertThrows(ProtocolException.class, () ->
+                redirectExec.execute(request, scope, chain));
+        Mockito.verify(inStream1, Mockito.times(2)).close();
+        Mockito.verify(response1).close();
     }
 
     private static class HttpRequestMatcher implements ArgumentMatcher<ClassicHttpRequest> {
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java
index e78e1c4..80b3bc4 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java
@@ -53,18 +53,20 @@ public class TestBasicCookieAttribHandlers {
         Assert.assertEquals("www.somedomain.com", cookie.getDomain());
     }
 
-    @Test(expected=MalformedCookieException.class)
+    @Test
     public void testBasicDomainParseInvalid1() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new BasicDomainHandler();
-        h.parse(cookie, "");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, ""));
     }
 
-    @Test(expected=MalformedCookieException.class)
+    @Test
     public void testBasicDomainParseInvalid2() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new BasicDomainHandler();
-        h.parse(cookie, null);
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, null));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
index b120b61..0a9d8e0 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
@@ -88,11 +88,12 @@ public class TestLaxCookieAttribHandlers {
         }
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testExpiryGarbage() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, ";;blah,blah;yada  ");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, ";;blah,blah;yada  "));
     }
 
     @Test
@@ -123,32 +124,36 @@ public class TestLaxCookieAttribHandlers {
         Assert.assertNull(cookie.getExpiryDate());
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidTime1() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "1:0:122 8 dec 1980");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "1:0:122 8 dec 1980"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidTime2() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "24:00:00 8 dec 1980");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "24:00:00 8 dec 1980"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidTime3() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "23:60:00 8 dec 1980");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "23:60:00 8 dec 1980"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidTime4() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "23:00:60 8 dec 1980");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "23:00:60 8 dec 1980"));
     }
 
     @Test
@@ -171,25 +176,28 @@ public class TestLaxCookieAttribHandlers {
         Assert.assertEquals(0, c.get(Calendar.MILLISECOND));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidDayOfMonth1() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "12:00:00 888 mar 1880");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "12:00:00 888 mar 1880"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidDayOfMonth2() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "12:00:00 0 mar 1880");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "12:00:00 0 mar 1880"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidDayOfMonth3() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "12:00:00 32 mar 1880");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "12:00:00 32 mar 1880"));
     }
 
     @Test
@@ -212,11 +220,12 @@ public class TestLaxCookieAttribHandlers {
         Assert.assertEquals(0, c.get(Calendar.MILLISECOND));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidMonth() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "1:00:00 8 dek 80");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "1:00:00 8 dek 80"));
     }
 
     @Test
@@ -239,25 +248,28 @@ public class TestLaxCookieAttribHandlers {
         Assert.assertEquals(0, c.get(Calendar.MILLISECOND));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidYearTooShort() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "1:00:00 8 dec 8");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "1:00:00 8 dec 8"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidYearTooLong() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "1:00:00 8 dec 88888");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "1:00:00 8 dec 88888"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseExpiryInvalidYearTooLongAgo() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");
         final CookieAttributeHandler h = new LaxExpiresHandler();
-        h.parse(cookie, "1:00:00 8 dec 1600");
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                h.parse(cookie, "1:00:00 8 dec 1600"));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestRFC6265CookieSpec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestRFC6265CookieSpec.java
index 210d7a7..822392f 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestRFC6265CookieSpec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestRFC6265CookieSpec.java
@@ -85,13 +85,14 @@ public class TestRFC6265CookieSpec {
         Assert.assertEquals("stuff", cookie.getAttribute("this"));
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseCookieWrongHeader() throws Exception {
         final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
 
         final Header header = new BasicHeader("Set-Cookie2", "blah");
         final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
-        cookiespec.parse(header, origin);
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                cookiespec.parse(header, origin));
     }
 
     @Test
@@ -114,13 +115,14 @@ public class TestRFC6265CookieSpec {
         Assert.assertEquals(0, cookies.size());
     }
 
-    @Test(expected = MalformedCookieException.class)
+    @Test
     public void testParseCookieMissingValue2() throws Exception {
         final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
 
         final Header header = new BasicHeader("Set-Cookie", "blah;");
         final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
-        cookiespec.parse(header, origin);
+        Assert.assertThrows(MalformedCookieException.class, () ->
+                cookiespec.parse(header, origin));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java
index c4f2e32..65f11ea 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java
@@ -227,15 +227,17 @@ public class TestBasicHttpClientConnectionManager {
         Mockito.verify(connFactory, Mockito.times(2)).createConnection(Mockito.any());
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testReleaseInvalidArg() throws Exception {
-        mgr.release(null, null, TimeValue.NEG_ONE_MILLISECOND);
+        Assert.assertThrows(NullPointerException.class, () ->
+                mgr.release(null, null, TimeValue.NEG_ONE_MILLISECOND));
     }
 
-    @Test(expected=IllegalStateException.class)
+    @Test
     public void testReleaseAnotherConnection() throws Exception {
         final ConnectionEndpoint wrongCon = Mockito.mock(ConnectionEndpoint.class);
-        mgr.release(wrongCon, null, TimeValue.NEG_ONE_MILLISECOND);
+        Assert.assertThrows(IllegalStateException.class, () ->
+                mgr.release(wrongCon, null, TimeValue.NEG_ONE_MILLISECOND));
     }
 
     @Test
@@ -328,7 +330,7 @@ public class TestBasicHttpClientConnectionManager {
         Mockito.verify(conn).close(CloseMode.GRACEFUL);
     }
 
-    @Test(expected=IllegalStateException.class)
+    @Test
     public void testAlreadyLeased() throws Exception {
         final HttpHost target = new HttpHost("somehost", 80);
         final HttpRoute route = new HttpRoute(target);
@@ -341,7 +343,8 @@ public class TestBasicHttpClientConnectionManager {
         mgr.release(endpoint1, null, TimeValue.ofMilliseconds(100));
 
         mgr.getConnection(route, null);
-        mgr.getConnection(route, null);
+        Assert.assertThrows(IllegalStateException.class, () ->
+                mgr.getConnection(route, null));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java
index 5a43d41..34bb77a 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java
@@ -48,6 +48,7 @@ import org.apache.hc.core5.http.io.SocketConfig;
 import org.apache.hc.core5.http.protocol.BasicHttpContext;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.TimeValue;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -123,7 +124,7 @@ public class TestHttpClientConnectionOperator {
         Mockito.verify(conn, Mockito.times(2)).bind(socket);
     }
 
-    @Test(expected=ConnectTimeoutException.class)
+    @Test
     public void testConnectTimeout() throws Exception {
         final HttpContext context = new BasicHttpContext();
         final HttpHost host = new HttpHost("somehost");
@@ -142,10 +143,12 @@ public class TestHttpClientConnectionOperator {
                 Mockito.any(),
                 Mockito.any())).thenThrow(new SocketTimeoutException());
 
-        connectionOperator.connect(conn, host, null, TimeValue.ofMilliseconds(1000), SocketConfig.DEFAULT, context);
+        Assert.assertThrows(ConnectTimeoutException.class, () ->
+                connectionOperator.connect(
+                        conn, host, null, TimeValue.ofMilliseconds(1000), SocketConfig.DEFAULT, context));
     }
 
-    @Test(expected=HttpHostConnectException.class)
+    @Test
     public void testConnectFailure() throws Exception {
         final HttpContext context = new BasicHttpContext();
         final HttpHost host = new HttpHost("somehost");
@@ -164,7 +167,9 @@ public class TestHttpClientConnectionOperator {
                 Mockito.any(),
                 Mockito.any())).thenThrow(new ConnectException());
 
-        connectionOperator.connect(conn, host, null, TimeValue.ofMilliseconds(1000), SocketConfig.DEFAULT, context);
+        Assert.assertThrows(HttpHostConnectException.class, () ->
+                connectionOperator.connect(
+                        conn, host, null, TimeValue.ofMilliseconds(1000), SocketConfig.DEFAULT, context));
     }
 
     @Test
@@ -260,22 +265,24 @@ public class TestHttpClientConnectionOperator {
         Mockito.verify(conn).bind(socket);
     }
 
-    @Test(expected=UnsupportedSchemeException.class)
+    @Test
     public void testUpgradeUpsupportedScheme() throws Exception {
         final HttpContext context = new BasicHttpContext();
         final HttpHost host = new HttpHost("httpsssss", "somehost", -1);
         Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
 
-        connectionOperator.upgrade(conn, host, context);
+        Assert.assertThrows(UnsupportedSchemeException.class, () ->
+                connectionOperator.upgrade(conn, host, context));
     }
 
-    @Test(expected=UnsupportedSchemeException.class)
+    @Test
     public void testUpgradeNonLayeringScheme() throws Exception {
         final HttpContext context = new BasicHttpContext();
         final HttpHost host = new HttpHost("http", "somehost", -1);
         Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
 
-        connectionOperator.upgrade(conn, host, context);
+        Assert.assertThrows(UnsupportedSchemeException.class, () ->
+                connectionOperator.upgrade(conn, host, context));
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java
index 341376a..83bb9d3 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java
@@ -151,7 +151,7 @@ public class TestPoolingHttpClientConnectionManager {
         Mockito.verify(pool).release(entry, false);
     }
 
-    @Test(expected= ExecutionException.class)
+    @Test
     public void testLeaseFutureCancelled() throws Exception {
         final HttpHost target = new HttpHost("localhost", 80);
         final HttpRoute route = new HttpRoute(target);
@@ -169,10 +169,11 @@ public class TestPoolingHttpClientConnectionManager {
                 .thenReturn(future);
 
         final LeaseRequest connRequest1 = mgr.lease("some-id", route, null);
-        connRequest1.get(Timeout.ofSeconds(1));
+        Assert.assertThrows(ExecutionException.class, () ->
+                connRequest1.get(Timeout.ofSeconds(1)));
     }
 
-    @Test(expected=TimeoutException.class)
+    @Test
     public void testLeaseFutureTimeout() throws Exception {
         final HttpHost target = new HttpHost("localhost", 80);
         final HttpRoute route = new HttpRoute(target);
@@ -186,7 +187,8 @@ public class TestPoolingHttpClientConnectionManager {
                 .thenReturn(future);
 
         final LeaseRequest connRequest1 = mgr.lease("some-id", route, null);
-        connRequest1.get(Timeout.ofSeconds(1));
+        Assert.assertThrows(TimeoutException.class, () ->
+                connRequest1.get(Timeout.ofSeconds(1)));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestDefaultRoutePlanner.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestDefaultRoutePlanner.java
index d7feda1..c6274fe 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestDefaultRoutePlanner.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestDefaultRoutePlanner.java
@@ -97,10 +97,11 @@ public class TestDefaultRoutePlanner {
         Mockito.verify(schemePortResolver, Mockito.never()).resolve(Mockito.any());
     }
 
-    @Test(expected= ProtocolException.class)
+    @Test
     public void testNullTarget() throws Exception {
         final HttpContext context = new BasicHttpContext();
-        routePlanner.determineRoute(null, context);
+        Assert.assertThrows(ProtocolException.class, () ->
+                routePlanner.determineRoute(null, context));
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java
index 1630142..83a298c 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java
@@ -81,11 +81,12 @@ public class TestRouteDirector {
         }
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testIllegal() {
         final HttpRouteDirector rowdy = new BasicRouteDirector();
         final HttpRoute route = new HttpRoute(TARGET1);
-        rowdy.nextStep(null, route);
+        Assert.assertThrows(NullPointerException.class, () ->
+                rowdy.nextStep(null, route));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java
index deaa5af..f0d122b 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRoutingSupport.java
@@ -37,6 +37,7 @@ import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.net.URIAuthority;
 import org.hamcrest.CoreMatchers;
 import org.hamcrest.MatcherAssert;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class TestRoutingSupport {
@@ -52,11 +53,12 @@ public class TestRoutingSupport {
         MatcherAssert.assertThat(host2, CoreMatchers.equalTo(new HttpHost("https", "somehost", 8443)));
     }
 
-    @Test(expected = ProtocolException.class)
+    @Test
     public void testDetermineHostMissingScheme() throws Exception {
         final HttpRequest request1 = new BasicHttpRequest("GET", "/");
         request1.setAuthority(new URIAuthority("host"));
-        RoutingSupport.determineHost(request1);
+        Assert.assertThrows(ProtocolException.class, () ->
+                RoutingSupport.determineHost(request1));
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java
index a86d19d..59388fa 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java
@@ -84,18 +84,20 @@ public class TestRequestAddCookies {
             .build();
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testRequestParameterCheck() throws Exception {
         final HttpClientContext context = HttpClientContext.create();
         final HttpRequestInterceptor interceptor = new RequestAddCookies();
-        interceptor.process(null, null, context);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(null, null, context));
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testContextParameterCheck() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpRequestInterceptor interceptor = new RequestAddCookies();
-        interceptor.process(request, null, null);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(request, null, null));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java
index 40086d9..cf9ac85 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java
@@ -41,11 +41,12 @@ import org.junit.Test;
 
 public class TestRequestClientConnControl {
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testRequestParameterCheck() throws Exception {
         final HttpClientContext context = HttpClientContext.create();
         final HttpRequestInterceptor interceptor = new RequestClientConnControl();
-        interceptor.process(null, null, context);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(null, null, context));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java
index b34a59f..1f1c18e 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java
@@ -41,11 +41,12 @@ import org.junit.Test;
 
 public class TestRequestDefaultHeaders {
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testRequestParameterCheck() throws Exception {
         final HttpContext context = new BasicHttpContext();
         final HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
-        interceptor.process(null, null, context);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(null, null, context));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java
index b34e3d7..65d0d92 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java
@@ -54,18 +54,20 @@ public class TestResponseProcessCookies {
         this.cookieStore = new BasicCookieStore();
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testResponseParameterCheck() throws Exception {
         final HttpClientContext context = HttpClientContext.create();
         final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
-        interceptor.process(null, null, context);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(null, null, context));
     }
 
-    @Test(expected=NullPointerException.class)
+    @Test
     public void testContextParameterCheck() throws Exception {
         final HttpResponse response = new BasicHttpResponse(200, "OK");
         final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
-        interceptor.process(response, null, null);
+        Assert.assertThrows(NullPointerException.class, () ->
+                interceptor.process(response, null, null));
     }
 
     @Test

[httpcomponents-client] 01/03: Upgraded JUnit to version 4.13

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 1c171e1446ad528c8cd951d488cc14d4cb8ceae1
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon May 24 16:48:45 2021 +0200

    Upgraded JUnit to version 4.13
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 788a993..9f7a8d2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,7 +69,7 @@
     <ehcache.version>3.4.0</ehcache.version>
     <memcached.version>2.12.3</memcached.version>
     <slf4j.version>1.7.25</slf4j.version>
-    <junit.version>4.12</junit.version>
+    <junit.version>4.13</junit.version>
     <easymock.version>3.6</easymock.version>
     <mockito.version>3.10.0</mockito.version>
     <jna.version>5.2.0</jna.version>