From 82432f50d9c068d3bf71476915f757017f366ce4 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 24 May 2021 16:54:03 +0200 Subject: [PATCH] Removed references to deprecated Assert#assertThat --- ...tAbstractSerializingAsyncCacheStorage.java | 23 ++--- .../TestAbstractSerializingCacheStorage.java | 23 ++--- .../TestByteArrayCacheEntrySerializer.java | 4 +- .../impl/cache/TestCacheRevalidatorBase.java | 9 +- .../impl/cache/TestCacheUpdateHandler.java | 26 +++--- .../http/schedule/TestConcurrentCountMap.java | 6 +- .../AbstractHttpAsyncFundamentalsTest.java | 36 ++++---- .../AbstractHttpReactiveFundamentalsTest.java | 29 +++--- .../client5/testing/async/TestHttp1Async.java | 34 +++---- .../testing/async/TestHttp1Reactive.java | 36 ++++---- .../async/TestHttp1RequestReExecution.java | 10 +-- .../testing/async/TestHttpAsyncMinimal.java | 8 +- .../async/TestHttpMinimalReactive.java | 8 +- .../client5/testing/sync/TestRedirects.java | 7 +- .../http/impl/TestProtocolSupport.java | 12 +-- .../impl/auth/TestAuthChallengeParser.java | 89 ++++++++++--------- .../http/impl/auth/TestHttpAuthenticator.java | 2 +- .../http/impl/routing/TestRoutingSupport.java | 6 +- .../http/ssl/TestDistinguishedNameParser.java | 22 ++--- .../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 6dc2048f1..921ad6c13 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 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 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 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 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 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 db4c6904e..67473014a 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 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 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 2ea0e44b9..59d488173 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 787a022de..980149caa 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 26b441f21..fb8f9ddc3 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 3c07190c6..9781b0dee 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 446151ab8..d85b6dd09 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 extends AbstractIntegrationTestBase { @@ -71,11 +71,11 @@ public abstract class AbstractHttpAsyncFundamentalsTest(new BasicAsyncEntityConsumer()), HttpClientContext.create(), null); final Message 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> future = queue.remove(); final Message 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> 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> 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>> responseFuture = consumer.getResponseFuture(); final Message> 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>> 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 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 38b12b8e3..5d1eccdf2 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 future3 = httpclient.execute( @@ -193,11 +193,11 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest> 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> 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> 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> 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 c6d4b9955..fac64cfca 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> future = queue.remove(); final Message 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 751349682..5cbad4354 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> future = queue.remove(); final Message 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 1b0c24de3..a57940805 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 11c831584..0af8432f9 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 f9613debf..ac61d4d86 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 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 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 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 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 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 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 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 971ded001..fd2489446 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 b359e0d8e..deaa5af2c 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 b350885a6..4472405c3 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.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.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.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.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.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.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.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.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.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.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 9c41c79a6..568464029 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 4475fe06d..da3e130da 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)); } }