### Question:
CacheStorageWriter { CachedLayer writeTarLayer(DescriptorDigest diffId, Blob compressedBlob) throws IOException { Files.createDirectories(cacheStorageFiles.getLocalDirectory()); Files.createDirectories(cacheStorageFiles.getTemporaryDirectory()); try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) { Path temporaryLayerDirectory = tempDirectoryProvider.newDirectory(cacheStorageFiles.getTemporaryDirectory()); Path temporaryLayerFile = cacheStorageFiles.getTemporaryLayerFile(temporaryLayerDirectory); BlobDescriptor layerBlobDescriptor; try (OutputStream fileOutputStream = new BufferedOutputStream(Files.newOutputStream(temporaryLayerFile))) { layerBlobDescriptor = compressedBlob.writeTo(fileOutputStream); } String fileName = layerBlobDescriptor.getDigest().getHash(); Path digestLayerFile = temporaryLayerDirectory.resolve(fileName); moveIfDoesNotExist(temporaryLayerFile, digestLayerFile); Path destination = cacheStorageFiles.getLocalDirectory().resolve(diffId.getHash()); moveIfDoesNotExist(temporaryLayerDirectory, destination); return CachedLayer.builder() .setLayerDigest(layerBlobDescriptor.getDigest()) .setLayerDiffId(diffId) .setLayerSize(layerBlobDescriptor.getSize()) .setLayerBlob(Blobs.from(destination.resolve(fileName))) .build(); } } CacheStorageWriter(CacheStorageFiles cacheStorageFiles);   }### Answer:
@Test public void testWriteTarLayer() throws IOException { Blob uncompressedLayerBlob = Blobs.from("uncompressedLayerBlob"); DescriptorDigest diffId = getDigest(uncompressedLayerBlob).getDigest(); CachedLayer cachedLayer = cacheStorageWriter.writeTarLayer(diffId, compress(uncompressedLayerBlob)); BlobDescriptor layerBlobDescriptor = getDigest(compress(uncompressedLayerBlob)); Assert.assertEquals(layerBlobDescriptor.getDigest(), cachedLayer.getDigest()); Assert.assertEquals(diffId, cachedLayer.getDiffId()); Assert.assertEquals(layerBlobDescriptor.getSize(), cachedLayer.getSize()); Assert.assertArrayEquals( Blobs.writeToByteArray(uncompressedLayerBlob), Blobs.writeToByteArray(decompress(cachedLayer.getBlob()))); Assert.assertTrue( Files.exists( cacheStorageFiles .getLocalDirectory() .resolve(cachedLayer.getDiffId().getHash()) .resolve(cachedLayer.getDigest().getHash()))); }