use of com.google.common.io.ByteStreams in project checkstyle by checkstyle.
the class PropertyCacheFileTest method testNonExistentResource.
@Test
public void testNonExistentResource() throws IOException {
final Configuration config = new DefaultConfiguration("myName");
final String filePath = File.createTempFile("junit", null, temporaryFolder).getPath();
final PropertyCacheFile cache = new PropertyCacheFile(config, filePath);
// create cache with one file
cache.load();
final String myFile = "myFile";
cache.put(myFile, 1);
final String hash = cache.get(PropertyCacheFile.CONFIG_HASH_KEY);
assertWithMessage("Config hash key should not be null").that(hash).isNotNull();
try (MockedStatic<ByteStreams> byteStream = mockStatic(ByteStreams.class)) {
byteStream.when(() -> ByteStreams.toByteArray(any(BufferedInputStream.class))).thenThrow(IOException.class);
// apply new external resource to clear cache
final Set<String> resources = new HashSet<>();
final String resource = getPath("InputPropertyCacheFile.header");
resources.add(resource);
cache.putExternalResources(resources);
assertWithMessage("Should return false in file is not in cache").that(cache.isInCache(myFile, 1)).isFalse();
assertWithMessage("Should return false in file is not in cache").that(cache.isInCache(resource, 1)).isFalse();
}
}
Aggregations