### Question:
EntropyInjector { @VisibleForTesting static Path resolveEntropy(Path path, EntropyInjectingFileSystem efs, boolean injectEntropy) throws IOException { final String entropyInjectionKey = efs.getEntropyInjectionKey(); if (entropyInjectionKey == null) { return path; } else { final URI originalUri = path.toUri(); final String checkpointPath = originalUri.getPath(); final int indexOfKey = checkpointPath.indexOf(entropyInjectionKey); if (indexOfKey == -1) { return path; } else { final StringBuilder buffer = new StringBuilder(checkpointPath.length()); buffer.append(checkpointPath, 0, indexOfKey); if (injectEntropy) { buffer.append(efs.generateEntropy()); } buffer.append(checkpointPath, indexOfKey + entropyInjectionKey.length(), checkpointPath.length()); final String rewrittenPath = buffer.toString(); try { return new Path(new URI( originalUri.getScheme(), originalUri.getAuthority(), rewrittenPath, originalUri.getQuery(), originalUri.getFragment()).normalize()); } catch (URISyntaxException e) { throw new IOException("URI format error while processing path for entropy injection", e); } } } } private  EntropyInjector(); static OutputStreamAndPath createEntropyAware(
			FileSystem fs,
			Path path,
			WriteMode writeMode); static Path removeEntropyMarkerIfPresent(FileSystem fs, Path path);  }### Answer:
@Test public void testEmptyPath() throws Exception { EntropyInjectingFileSystem efs = new TestEntropyInjectingFs("test", "ignored"); Path path = new Path("hdfs: assertEquals(path, EntropyInjector.resolveEntropy(path, efs, true)); assertEquals(path, EntropyInjector.resolveEntropy(path, efs, false)); }
@Test public void testFullUriNonMatching() throws Exception { EntropyInjectingFileSystem efs = new TestEntropyInjectingFs("_entropy_key_", "ignored"); Path path = new Path("s3: assertEquals(path, EntropyInjector.resolveEntropy(path, efs, true)); assertEquals(path, EntropyInjector.resolveEntropy(path, efs, false)); }
@Test public void testFullUriMatching() throws Exception { EntropyInjectingFileSystem efs = new TestEntropyInjectingFs("s0mek3y", "12345678"); Path path = new Path("s3: assertEquals(new Path("s3: assertEquals(new Path("s3: }
@Test public void testPathOnlyNonMatching() throws Exception { EntropyInjectingFileSystem efs = new TestEntropyInjectingFs("_entropy_key_", "ignored"); Path path = new Path("/path/file"); assertEquals(path, EntropyInjector.resolveEntropy(path, efs, true)); assertEquals(path, EntropyInjector.resolveEntropy(path, efs, false)); }
@Test public void testPathOnlyMatching() throws Exception { EntropyInjectingFileSystem efs = new TestEntropyInjectingFs("_entropy_key_", "xyzz"); Path path = new Path("/path/_entropy_key_/file"); assertEquals(new Path("/path/xyzz/file"), EntropyInjector.resolveEntropy(path, efs, true)); assertEquals(new Path("/path/file"), EntropyInjector.resolveEntropy(path, efs, false)); }
@Test public void testEntropyNotFullSegment() throws Exception { EntropyInjectingFileSystem efs = new TestEntropyInjectingFs("_entropy_key_", "pqr"); Path path = new Path("s3: assertEquals(new Path("s3: assertEquals(new Path("s3: }