Dependabot broke my build...

This commit is contained in:
Harald Kuhr 2020-10-13 19:16:58 +02:00
parent f9871b73a3
commit 107da17ca9
12 changed files with 175 additions and 150 deletions

View File

@ -35,6 +35,8 @@ import org.junit.Test;
import java.awt.image.*;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
public class DiscreteAlphaIndexColorModelTest {
@ -162,7 +164,7 @@ public class DiscreteAlphaIndexColorModelTest {
assertEquals(2, sampleModel.getHeight());
assertTrue(colorModel.isCompatibleSampleModel(sampleModel));
assertThat(sampleModel, CoreMatchers.is(PixelInterleavedSampleModel.class));
assertThat(sampleModel, instanceOf(PixelInterleavedSampleModel.class));
assertThat(sampleModel.getDataType(), CoreMatchers.equalTo(DataBuffer.TYPE_BYTE));
}
@ -180,7 +182,7 @@ public class DiscreteAlphaIndexColorModelTest {
assertEquals(2, sampleModel.getHeight());
assertTrue(colorModel.isCompatibleSampleModel(sampleModel));
assertThat(sampleModel, CoreMatchers.is(PixelInterleavedSampleModel.class));
assertThat(sampleModel, instanceOf(PixelInterleavedSampleModel.class));
assertThat(sampleModel.getDataType(), CoreMatchers.equalTo(DataBuffer.TYPE_USHORT));
}

View File

@ -42,6 +42,7 @@ import javax.imageio.spi.ImageWriterSpi;
import java.util.List;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@ -31,6 +31,7 @@
package com.twelvemonkeys.imageio.util;
import com.twelvemonkeys.imageio.color.ColorSpaces;
import org.junit.Test;
import javax.imageio.ImageTypeSpecifier;
@ -39,7 +40,8 @@ import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.PixelInterleavedSampleModel;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
public class UInt32ImageTypeSpecifierTest {
@ -55,13 +57,13 @@ public class UInt32ImageTypeSpecifierTest {
assertEquals(1, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertThat(spec.getColorModel(), instanceOf(ComponentColorModel.class));
assertFalse(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(1, spec.getColorModel().getNumComponents());
assertEquals(1, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertThat(spec.getSampleModel(), instanceOf(PixelInterleavedSampleModel.class));
assertEquals(1, spec.getSampleModel().getNumBands());
assertEquals(1, spec.getSampleModel().getNumDataElements());
}
@ -74,13 +76,13 @@ public class UInt32ImageTypeSpecifierTest {
assertEquals(32, spec.getBitsPerBand(0));
assertEquals(32, spec.getBitsPerBand(1));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertThat(spec.getColorModel(), instanceOf(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(2, spec.getColorModel().getNumComponents());
assertEquals(1, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertThat(spec.getSampleModel(), instanceOf(PixelInterleavedSampleModel.class));
assertEquals(2, spec.getSampleModel().getNumBands());
assertEquals(2, spec.getSampleModel().getNumDataElements());
}
@ -95,13 +97,13 @@ public class UInt32ImageTypeSpecifierTest {
assertEquals(32, spec.getBitsPerBand(1));
assertEquals(32, spec.getBitsPerBand(2));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertThat(spec.getColorModel(), instanceOf(ComponentColorModel.class));
assertFalse(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(3, spec.getColorModel().getNumComponents());
assertEquals(3, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertThat(spec.getSampleModel(), instanceOf(PixelInterleavedSampleModel.class));
assertEquals(3, spec.getSampleModel().getNumBands());
assertEquals(3, spec.getSampleModel().getNumDataElements());
}
@ -116,13 +118,13 @@ public class UInt32ImageTypeSpecifierTest {
assertEquals(32, spec.getBitsPerBand(2));
assertEquals(32, spec.getBitsPerBand(3));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertThat(spec.getColorModel(), instanceOf(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(4, spec.getColorModel().getNumComponents());
assertEquals(3, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertThat(spec.getSampleModel(), instanceOf(PixelInterleavedSampleModel.class));
assertEquals(4, spec.getSampleModel().getNumBands());
assertEquals(4, spec.getSampleModel().getNumDataElements());
}
@ -137,13 +139,13 @@ public class UInt32ImageTypeSpecifierTest {
assertEquals(32, spec.getBitsPerBand(2));
assertEquals(32, spec.getBitsPerBand(3));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertThat(spec.getColorModel(), instanceOf(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertTrue(spec.getColorModel().isAlphaPremultiplied());
assertEquals(4, spec.getColorModel().getNumComponents());
assertEquals(3, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertThat(spec.getSampleModel(), instanceOf(PixelInterleavedSampleModel.class));
assertEquals(4, spec.getSampleModel().getNumBands());
assertEquals(4, spec.getSampleModel().getNumDataElements());
}
@ -159,13 +161,13 @@ public class UInt32ImageTypeSpecifierTest {
assertEquals(32, spec.getBitsPerBand(2));
assertEquals(32, spec.getBitsPerBand(3));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertThat(spec.getColorModel(), instanceOf(ComponentColorModel.class));
assertFalse(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(4, spec.getColorModel().getNumComponents());
assertEquals(4, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertThat(spec.getSampleModel(), instanceOf(PixelInterleavedSampleModel.class));
assertEquals(4, spec.getSampleModel().getNumBands());
assertEquals(4, spec.getSampleModel().getNumDataElements());
}
@ -181,13 +183,13 @@ public class UInt32ImageTypeSpecifierTest {
assertEquals(32, spec.getBitsPerBand(3));
assertEquals(32, spec.getBitsPerBand(4));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertThat(spec.getColorModel(), instanceOf(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(5, spec.getColorModel().getNumComponents());
assertEquals(4, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertThat(spec.getSampleModel(), instanceOf(PixelInterleavedSampleModel.class));
assertEquals(5, spec.getSampleModel().getNumBands());
assertEquals(5, spec.getSampleModel().getNumDataElements());
}

View File

@ -32,6 +32,7 @@ package com.twelvemonkeys.imageio.plugins.jpeg;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
import com.twelvemonkeys.lang.StringUtil;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Test;
import org.mockito.internal.matchers.GreaterThan;
@ -60,6 +61,7 @@ import java.util.List;
import java.util.*;
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeNoException;
import static org.junit.Assume.assumeNotNull;

View File

@ -34,6 +34,7 @@ import com.twelvemonkeys.imageio.metadata.jpeg.JPEG;
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegment;
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegmentUtil;
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
import org.junit.Test;
import org.mockito.internal.matchers.LessOrEqual;
@ -46,7 +47,9 @@ import java.io.IOException;
import java.net.URL;
import java.util.List;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
/**
* JPEGSegmentImageInputStreamTest

View File

@ -35,6 +35,7 @@ import com.twelvemonkeys.imageio.metadata.Directory;
import com.twelvemonkeys.imageio.metadata.MetadataReaderAbstractTest;
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
import org.junit.Test;
import javax.imageio.ImageIO;
@ -44,6 +45,7 @@ import java.io.IOException;
import java.io.InputStream;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@ -32,14 +32,15 @@ package com.twelvemonkeys.imageio.metadata.iptc;
import com.twelvemonkeys.imageio.metadata.Directory;
import com.twelvemonkeys.imageio.metadata.MetadataReaderAbstractTest;
import org.junit.Test;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.io.InputStream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/**
* IPTCReaderTest

View File

@ -37,6 +37,7 @@ import com.twelvemonkeys.imageio.metadata.MetadataReaderAbstractTest;
import com.twelvemonkeys.imageio.metadata.exif.EXIF;
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
import org.junit.Test;
import javax.imageio.ImageIO;
@ -46,6 +47,7 @@ import java.io.IOException;
import java.io.InputStream;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@ -34,6 +34,7 @@ import com.twelvemonkeys.imageio.metadata.CompoundDirectory;
import com.twelvemonkeys.imageio.metadata.Directory;
import com.twelvemonkeys.imageio.metadata.Entry;
import com.twelvemonkeys.imageio.metadata.MetadataReaderAbstractTest;
import org.junit.Test;
import javax.imageio.ImageIO;
@ -46,7 +47,9 @@ import java.util.HashMap;
import java.util.Iterator;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* XMPReaderTest

View File

@ -32,6 +32,7 @@ package com.twelvemonkeys.imageio.plugins.tiff;
import com.twelvemonkeys.imageio.color.ColorSpaces;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
import org.junit.Test;
import javax.imageio.IIOException;
@ -52,9 +53,10 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.junit.internal.matchers.StringContains.containsString;
import static org.mockito.AdditionalMatchers.and;
import static org.mockito.Matchers.contains;
import static org.mockito.Matchers.eq;
@ -873,7 +875,7 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
try {
IIOMetadata streamMetadata = reader.getStreamMetadata();
assertNotNull(streamMetadata);
assertThat(streamMetadata, is(TIFFStreamMetadata.class));
assertThat(streamMetadata, instanceOf(TIFFStreamMetadata.class));
}
catch (Exception e) {
failBecause(String.format("Image %s could not be read: %s", data.getInput(), e), e);

View File

@ -44,7 +44,8 @@ import static com.twelvemonkeys.imageio.plugins.tiff.TIFFMedataFormat.SUN_NATIVE
import static com.twelvemonkeys.imageio.plugins.tiff.TIFFStreamMetadata.SUN_NATIVE_STREAM_METADATA_FORMAT_NAME;
import static java.nio.ByteOrder.BIG_ENDIAN;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
@ -163,11 +164,11 @@ public class TIFFStreamMetadataTest {
public void testGetAsTreeNative() {
Node root = new TIFFStreamMetadata().getAsTree(SUN_NATIVE_STREAM_METADATA_FORMAT_NAME);
assertNotNull(root);
assertThat(root, is(IIOMetadataNode.class));
assertThat(root, instanceOf(IIOMetadataNode.class));
assertEquals(SUN_NATIVE_STREAM_METADATA_FORMAT_NAME, root.getNodeName());
NodeList childNodes = root.getChildNodes();
assertEquals(1, childNodes.getLength());
assertThat(childNodes.item(0), is(IIOMetadataNode.class));
assertThat(childNodes.item(0), instanceOf(IIOMetadataNode.class));
IIOMetadataNode byteOrder = (IIOMetadataNode) childNodes.item(0);
assertEquals("ByteOrder", byteOrder.getNodeName());
assertEquals("BIG_ENDIAN", byteOrder.getAttribute("value"));
@ -177,11 +178,11 @@ public class TIFFStreamMetadataTest {
public void testGetAsTreeNativeII() {
Node root = new TIFFStreamMetadata(LITTLE_ENDIAN).getAsTree(SUN_NATIVE_STREAM_METADATA_FORMAT_NAME);
assertNotNull(root);
assertThat(root, is(IIOMetadataNode.class));
assertThat(root, instanceOf(IIOMetadataNode.class));
assertEquals(SUN_NATIVE_STREAM_METADATA_FORMAT_NAME, root.getNodeName());
NodeList childNodes = root.getChildNodes();
assertEquals(1, childNodes.getLength());
assertThat(childNodes.item(0), is(IIOMetadataNode.class));
assertThat(childNodes.item(0), instanceOf(IIOMetadataNode.class));
IIOMetadataNode byteOrder = (IIOMetadataNode) childNodes.item(0);
assertEquals("ByteOrder", byteOrder.getNodeName());
assertEquals("LITTLE_ENDIAN", byteOrder.getAttribute("value"));

View File

@ -31,6 +31,7 @@
package com.twelvemonkeys.servlet.cache;
import com.twelvemonkeys.net.HTTPUtil;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@ -46,6 +47,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.*;
import static org.junit.Assert.*;
@ -62,11 +64,10 @@ public class HTTPCacheTest {
@Rule
public final TestName name = new TestName();
// TODO: Replace with rule: TemporaryFolder
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
private File getTempRoot() {
private File createTempRoot() throws IOException {
return temporaryFolder.newFolder("cache-test");
}
@ -139,9 +140,11 @@ public class HTTPCacheTest {
}
@Test
public void testCreateNegativeValues() {
public void testCreateNegativeValues() throws IOException {
File tempRoot = createTempRoot();
try {
new HTTPCache(getTempRoot(), -1, 0, 10, true);
new HTTPCache(tempRoot, -1, 0, 10, true);
fail("Expected creation failure");
}
catch (IllegalArgumentException expected) {
@ -151,7 +154,7 @@ public class HTTPCacheTest {
}
try {
new HTTPCache(getTempRoot(), 1000, -1, 10, false);
new HTTPCache(tempRoot, 1000, -1, 10, false);
fail("Expected creation failure");
}
catch (IllegalArgumentException expected) {
@ -161,7 +164,7 @@ public class HTTPCacheTest {
}
try {
new HTTPCache(getTempRoot(), 1000, 128, -1, true);
new HTTPCache(tempRoot, 1000, 128, -1, true);
fail("Expected creation failure");
}
catch (IllegalArgumentException expected) {
@ -172,23 +175,23 @@ public class HTTPCacheTest {
}
@Test
public void testCreate() {
new HTTPCache(getTempRoot(), 500, 0, 10, true);
public void testCreate() throws IOException {
new HTTPCache(createTempRoot(), 500, 0, 10, true);
}
@SuppressWarnings("deprecation")
@Test
public void testCreateServletContext() {
public void testCreateServletContext() throws IOException {
ServletContext mockContext = mock(ServletContext.class);
// Currently context is used for tempdir and logging
when(mockContext.getAttribute(eq("javax.servlet.context.tempdir"))).thenReturn(getTempRoot());
when(mockContext.getAttribute(eq("javax.servlet.context.tempdir"))).thenReturn(createTempRoot());
new HTTPCache("cache", mockContext, 500, 0, 10, true);
}
@Test
public void testCacheableRequest() throws IOException, CacheException {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -198,7 +201,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(value)).when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -208,8 +211,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -223,10 +226,10 @@ public class HTTPCacheTest {
@Test
public void testCacheableRequestWithParameters() throws IOException, CacheException {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
Map<String, List<String>> parameters = new HashMap<String, List<String>>();
Map<String, List<String>> parameters = new HashMap<>();
parameters.put("foo", Collections.singletonList("bar"));
parameters.put("params", Arrays.asList("une", "due", "tres"));
CacheRequest request = configureRequest(mock(CacheRequest.class), "GET", createRequestURI(), parameters, null);
@ -235,7 +238,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class, "MY-RESOLVER-1");
doAnswer(new ResolveAnswer(value)).when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -245,8 +248,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -256,7 +259,8 @@ public class HTTPCacheTest {
@Test
public void testCacheablePersistentRepeatedRequest() throws IOException, CacheException {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
File tempRoot = createTempRoot();
HTTPCache cache = new HTTPCache(tempRoot, 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -265,7 +269,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class, "MY-RESOLVER-2");
doAnswer(new ResolveAnswer(value)).when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -275,8 +279,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -288,13 +292,13 @@ public class HTTPCacheTest {
when(response.getOutputStream()).thenReturn(result);
// Test request again, make sure resolve is executed exactly once
HTTPCache cache2 = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache2 = new HTTPCache(tempRoot, 60000, 1024 * 1024, 10, true);
cache2.doCached(request, response, resolver);
// Test that second response is equal to first
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -304,7 +308,7 @@ public class HTTPCacheTest {
@Test
public void testCacheableRepeatedRequest() throws IOException, CacheException {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -313,7 +317,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class, "MY-RESOLVER-3");
doAnswer(new ResolveAnswer(value)).when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -323,8 +327,8 @@ public class HTTPCacheTest {
// Verify that reponse is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -342,8 +346,8 @@ public class HTTPCacheTest {
// Test that second response is equal to first
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -353,7 +357,7 @@ public class HTTPCacheTest {
@Test
public void testNonCacheableRequestHeader() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), "GET", createRequestURI(), null, Collections.singletonMap("Cache-Control", Collections.singletonList("no-store")));
@ -362,7 +366,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(value)).when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -373,8 +377,8 @@ public class HTTPCacheTest {
// TODO: How do we know that the response was NOT cached?
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -384,7 +388,7 @@ public class HTTPCacheTest {
@Test
public void testNonCacheableRequestHeaderRepeated() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
String requestURI = createRequestURI();
// Custom setup
@ -395,7 +399,7 @@ public class HTTPCacheTest {
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(value)).when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -405,8 +409,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -428,8 +432,8 @@ public class HTTPCacheTest {
// Verify that second response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -439,7 +443,7 @@ public class HTTPCacheTest {
@Test
public void testNonCacheableResponseHeader() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -448,7 +452,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, Collections.singletonMap("Cache-Control", Collections.singletonList("no-cache"))))
@ -459,8 +463,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -471,7 +475,7 @@ public class HTTPCacheTest {
@Test
public void testNonCacheableResponseHeaderRepeated() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -480,7 +484,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, Collections.singletonMap("Cache-Control", Collections.singletonList("no-store"))))
@ -491,8 +495,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -516,8 +520,8 @@ public class HTTPCacheTest {
// Verify that reponse is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -529,7 +533,7 @@ public class HTTPCacheTest {
// Test non-cacheable response
@Test
public void testNonCacheableResponse() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -538,7 +542,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, value, null))
@ -549,8 +553,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -561,7 +565,7 @@ public class HTTPCacheTest {
// Test non-cacheable response
@Test
public void testNonCacheableResponseRepeated() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -570,7 +574,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, value, null))
@ -581,8 +585,8 @@ public class HTTPCacheTest {
// Verify that reponse is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -604,8 +608,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
// Verify new resolve
verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@ -617,10 +621,10 @@ public class HTTPCacheTest {
// Test that request headers are forwarded to resolver...
@Test
public void testRequestHeadersForwarded() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
final Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>();
headers.put("Cache-Control", Arrays.asList("no-cache"));
final Map<String, List<String>> headers = new LinkedHashMap<>();
headers.put("Cache-Control", Collections.singletonList("no-cache"));
headers.put("X-Custom", Arrays.asList("FOO", "BAR"));
// Custom setup
@ -629,7 +633,7 @@ public class HTTPCacheTest {
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Throwable {
public Void answer(InvocationOnMock invocation) {
CacheRequest req = (CacheRequest) invocation.getArguments()[0];
Map<String, List<String>> reqHeaders = req.getHeaders();
@ -657,7 +661,7 @@ public class HTTPCacheTest {
// Test that response headers are preserved
@Test
public void testCacheablePreserveResponseHeaders() throws IOException, CacheException {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -666,7 +670,7 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
final byte[] value = "foobar".getBytes("UTF-8");
final byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new Answer<Void>() {
@ -689,8 +693,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).setHeader(eq("Date"), anyString());
@ -710,7 +714,7 @@ public class HTTPCacheTest {
// Test Vary
@Test
public void testVaryMissingRequestHeader() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -719,13 +723,13 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
byte[] value = "foobar".getBytes("UTF-8");
byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Arrays.asList("x-foo/bar"));
headers.put("Vary", Arrays.asList("X-Foo"));
headers.put("X-Foo", Arrays.asList("foobar"));
headers.put("X-Other", Arrays.asList("don't care"));
HashMap<String, List<String>> headers = new HashMap<>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Collections.singletonList("x-foo/bar"));
headers.put("Vary", Collections.singletonList("X-Foo"));
headers.put("X-Foo", Collections.singletonList("foobar"));
headers.put("X-Other", Collections.singletonList("don't care"));
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, headers))
@ -736,8 +740,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -760,8 +764,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -773,7 +777,7 @@ public class HTTPCacheTest {
@Test
public void testVaryMissingRequestHeaderRepeated() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
String requestURI = createRequestURI();
@ -783,12 +787,12 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
byte[] value = "foobar".getBytes("UTF-8");
byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Arrays.asList("x-foo/bar"));
headers.put("Vary", Arrays.asList("X-Foo"));
headers.put("X-Other", Arrays.asList("don't care"));
HashMap<String, List<String>> headers = new HashMap<>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Collections.singletonList("x-foo/bar"));
headers.put("Vary", Collections.singletonList("X-Foo"));
headers.put("X-Other", Collections.singletonList("don't care"));
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, headers))
@ -799,8 +803,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -826,8 +830,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -840,7 +844,7 @@ public class HTTPCacheTest {
@Test
public void testVarySameResourceIsCached() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), "GET", createRequestURI(), null, Collections.singletonMap("X-Foo", Collections.singletonList("foobar value")));
@ -850,12 +854,12 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
byte[] value = "foobar".getBytes("UTF-8");
byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Arrays.asList("x-foo/bar"));
headers.put("Vary", Arrays.asList("X-Foo"));
headers.put("X-Other", Arrays.asList("don't care"));
HashMap<String, List<String>> headers = new HashMap<>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Collections.singletonList("x-foo/bar"));
headers.put("Vary", Collections.singletonList("X-Foo"));
headers.put("X-Other", Collections.singletonList("don't care"));
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, headers))
@ -866,8 +870,8 @@ public class HTTPCacheTest {
// Verify that reponse is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -887,8 +891,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -900,7 +904,7 @@ public class HTTPCacheTest {
@Test
public void testVaryDifferentResources() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
String requestURI = createRequestURI();
@ -910,12 +914,12 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
byte[] value = "foobar".getBytes("UTF-8");
byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Arrays.asList("x-foo/bar"));
headers.put("Vary", Arrays.asList("X-Foo"));
headers.put("X-Other", Arrays.asList("don't care"));
HashMap<String, List<String>> headers = new HashMap<>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Collections.singletonList("x-foo/bar"));
headers.put("Vary", Collections.singletonList("X-Foo"));
headers.put("X-Other", Collections.singletonList("don't care"));
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, headers))
@ -926,8 +930,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -943,7 +947,7 @@ public class HTTPCacheTest {
// Reconfigure
when(response.getOutputStream()).thenReturn(result);
headers.put("Cache-Control", Arrays.asList("no-store"));
headers.put("Cache-Control", Collections.singletonList("no-store"));
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, headers))
.when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -956,8 +960,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -970,7 +974,7 @@ public class HTTPCacheTest {
@Test
public void testVaryStarNonCached() throws Exception {
HTTPCache cache = new HTTPCache(getTempRoot(), 60000, 1024 * 1024, 10, true);
HTTPCache cache = new HTTPCache(createTempRoot(), 60000, 1024 * 1024, 10, true);
// Custom setup
CacheRequest request = configureRequest(mock(CacheRequest.class), createRequestURI());
@ -979,11 +983,11 @@ public class HTTPCacheTest {
CacheResponse response = mock(CacheResponse.class);
when(response.getOutputStream()).thenReturn(result);
byte[] value = "foobar".getBytes("UTF-8");
byte[] value = "foobar".getBytes(StandardCharsets.UTF_8);
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Arrays.asList("x-foo/bar"));
headers.put("Vary", Arrays.asList("*"));
HashMap<String, List<String>> headers = new HashMap<>();
headers.put(HTTPCache.HEADER_CONTENT_TYPE, Collections.singletonList("x-foo/bar"));
headers.put("Vary", Collections.singletonList("*"));
ResponseResolver resolver = mock(ResponseResolver.class);
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, headers))
@ -994,8 +998,8 @@ public class HTTPCacheTest {
// Verify that reponse is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();
@ -1010,7 +1014,7 @@ public class HTTPCacheTest {
// Reconfigure
when(response.getOutputStream()).thenReturn(result);
headers.put("Cache-Control", Arrays.asList("no-store"));
headers.put("Cache-Control", Collections.singletonList("no-store"));
doAnswer(new ResolveAnswer(HttpServletResponse.SC_OK, value, headers))
.when(resolver).resolve(any(CacheRequest.class), any(CacheResponse.class));
@ -1021,8 +1025,8 @@ public class HTTPCacheTest {
// Verify that response is ok
assertEquals(value.length, result.size());
assertEquals(new String(value, "UTF-8"), new String(result.toByteArray(), "UTF-8"));
assertTrue(Arrays.equals(value, result.toByteArray()));
assertEquals(new String(value, StandardCharsets.UTF_8), new String(result.toByteArray(), StandardCharsets.UTF_8));
assertArrayEquals(value, result.toByteArray());
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response, atLeastOnce()).getOutputStream();