Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
strangelookingnerd committed Jun 27, 2024
1 parent 733299c commit 3213dac
Show file tree
Hide file tree
Showing 20 changed files with 5 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
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;
Expand Down Expand Up @@ -249,15 +245,6 @@ private static void assertIsAllowedClassNameFalse(final String className) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,6 @@ void testSuitableForGETIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyAReques
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ void testNoCacheFieldsRevalidation() throws Exception {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void testInvalidHeaderCacheEntry() {
"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());
Expand Down Expand Up @@ -432,7 +432,7 @@ void testDeserializeCacheEntryWithTrailingGarbage() {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ void test304GeneratedFromCacheOnWeakValidatorDoesNotIncludeOtherEntityHeaders()
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand Down Expand Up @@ -71,7 +70,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,7 +45,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import static org.hamcrest.MatcherAssert.assertThat;

import java.io.IOException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.CancellationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +37,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +36,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +38,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
*/
package org.apache.hc.client5.http.examples;

import java.io.IOException;
import java.nio.CharBuffer;
import java.util.concurrent.Future;

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +42,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.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.HttpResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +37,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.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void testRetrySleepOnIOException() throws Exception {
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void testFundamentals() throws Exception {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
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;
Expand All @@ -50,11 +49,6 @@ private static Instant createInstant(final int year, final Month month, final in
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);
Expand Down

0 comments on commit 3213dac

Please sign in to comment.