Minor code cleanup

This commit is contained in:
strangelookingnerd 2024-06-27 10:49:05 +02:00 committed by Oleg Kalnichevski
parent 420910da4f
commit cc13243cd3
20 changed files with 5 additions and 52 deletions

View File

@ -32,10 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.Date;
import java.util.HashSet;
@ -249,15 +245,6 @@ class TestByteArrayCacheEntrySerializer {
assertFalse(ByteArrayCacheEntrySerializer.RestrictedObjectInputStream.isAllowedClassName(className));
}
private byte[] serializeProhibitedObject() throws IOException {
final BigDecimal bigDecimal = new BigDecimal("1000.00");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(bigDecimal);
}
return baos.toByteArray();
}
public void readWriteVerify(final HttpCacheStorageEntry writeEntry) throws Exception {
// write the entry
final byte[] bytes = impl.serialize(writeEntry);

View File

@ -436,9 +436,6 @@ class TestCachedResponseSuitabilityChecker {
void testSuitableForHEADIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethod() {
final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo");
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
final Header[] headers = {
};
entry = makeEntry(Method.GET, "/foo",
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
responseCacheControl = ResponseCacheControl.builder()

View File

@ -1279,7 +1279,7 @@ class TestCachingExecChain {
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
execute(req2);
final ClassicHttpResponse result = execute(req3);
execute(req3);
// Verify that the backend was called to revalidate the response, as per the new logic
Mockito.verify(mockExecChain, Mockito.times(5)).proceed(Mockito.any(), Mockito.any());

View File

@ -261,7 +261,7 @@ class TestHttpByteArrayCacheEntrySerializer {
"Cache-control: public, max-age=31536000\n" +
"\n" +
"Hello World";
final byte[] bytes2 = content1.getBytes(StandardCharsets.UTF_8);
final byte[] bytes2 = content2.getBytes(StandardCharsets.UTF_8);
final ResourceIOException exception2 = Assertions.assertThrows(ResourceIOException.class, () ->
httpCacheEntrySerializer.deserialize(bytes2));
Assertions.assertEquals("Invalid cache header format", exception2.getMessage());
@ -432,7 +432,7 @@ class TestHttpByteArrayCacheEntrySerializer {
final byte[] bytes2 = content2.getBytes(StandardCharsets.UTF_8);
final ResourceIOException exception2 = Assertions.assertThrows(ResourceIOException.class, () ->
httpCacheEntrySerializer.deserialize(bytes2));
Assertions.assertEquals("Unexpected content at the end of cache content", exception1.getMessage());
Assertions.assertEquals("Unexpected content at the end of cache content", exception2.getMessage());
}
static HeapResource load(final URL resource) throws IOException {

View File

@ -465,8 +465,6 @@ class TestProtocolRequirements {
@Test
void testNotModifiedOfNonCachedEntityShouldRevalidateWithUnconditionalGET() throws Exception {
final Instant now = Instant.now();
// load cache with cacheable entry
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();

View File

@ -39,7 +39,6 @@ import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
import org.apache.hc.client5.testing.extension.async.TestAsyncClient;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;

View File

@ -29,7 +29,6 @@ package org.apache.hc.client5.testing.sync;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Arrays;
@ -71,7 +70,6 @@ import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HeaderElements;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpResponse;

View File

@ -28,7 +28,6 @@
package org.apache.hc.client5.testing.sync;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -46,7 +45,6 @@ import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElements;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpResponse;

View File

@ -50,7 +50,6 @@ import org.apache.hc.client5.testing.extension.sync.TestClient;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.URIScheme;

View File

@ -32,9 +32,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;
import javax.net.ssl.HostnameVerifier;

View File

@ -28,7 +28,6 @@ package org.apache.hc.client5.testing.sync;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.CancellationException;

View File

@ -26,7 +26,6 @@
*/
package org.apache.hc.client5.testing.sync;
import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
@ -38,7 +37,6 @@ import org.apache.hc.client5.testing.extension.sync.TestClient;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpStatus;

View File

@ -26,8 +26,6 @@
*/
package org.apache.hc.client5.testing.sync;
import java.io.IOException;
import org.apache.hc.client5.http.UserTokenHandler;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
@ -38,7 +36,6 @@ import org.apache.hc.client5.testing.extension.sync.TestClient;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.URIScheme;

View File

@ -26,7 +26,6 @@
*/
package org.apache.hc.client5.http.examples;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.concurrent.Future;
@ -39,7 +38,6 @@ import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
import org.apache.hc.core5.function.Supplier;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.impl.routing.RequestRouter;

View File

@ -26,7 +26,6 @@
*/
package org.apache.hc.client5.http.examples;
import java.io.IOException;
import java.nio.CharBuffer;
import java.util.concurrent.Future;
@ -34,7 +33,6 @@ import org.apache.hc.client5.http.async.methods.AbstractCharResponseConsumer;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.message.BasicHttpRequest;

View File

@ -27,7 +27,6 @@
package org.apache.hc.client5.http.examples;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Future;
@ -43,7 +42,6 @@ import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.HttpResponse;

View File

@ -27,7 +27,6 @@
package org.apache.hc.client5.http.examples;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.hc.client5.http.classic.methods.HttpGet;
@ -38,7 +37,6 @@ import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.HttpStatus;

View File

@ -111,7 +111,7 @@ class TestHttpRequestRetryExec {
final HttpGet request = new HttpGet("/test");
final HttpClientContext context = HttpClientContext.create();
final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
Mockito.mock(ClassicHttpResponse.class);
Mockito.when(chain.proceed(
Mockito.same(request),

View File

@ -100,7 +100,7 @@ class TestMainClientExec {
Mockito.any())).thenReturn(response);
final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null);
mainClientExec.execute(request, scope, null);
Mockito.verify(httpProcessor).process(request, null, context);
Mockito.verify(execRuntime).execute(Mockito.eq("test"), Mockito.same(request), Mockito.any(), Mockito.any());

View File

@ -33,7 +33,6 @@ import java.time.Month;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.message.BasicHeader;
@ -50,11 +49,6 @@ class TestDateUtils {
return LocalDate.of(year, month, day).atStartOfDay(ZoneId.of("GMT")).toInstant();
}
private static Date createDate(final int year, final Month month, final int day) {
final Instant instant = createInstant(year, month, day);
return new Date(instant.toEpochMilli());
}
@Test
void testBasicDateParse() {
final Instant instant = createInstant(2005, Month.OCTOBER, 14);