Removed references to deprecated Assert#assertThat

This commit is contained in:
Oleg Kalnichevski 2021-05-24 16:54:03 +02:00
parent 1c171e1446
commit 82432f50d9
21 changed files with 220 additions and 213 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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 {

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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());
}
}

View File

@ -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"));
}
}

View File

@ -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());
}
}

View File

@ -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

View File

@ -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)

View File

@ -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"))));

View File

@ -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!!!"));
}
}

View File

@ -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));
}
}