### Question:
Locations { public static Location getLocationFromAbsolutePath(LocationFactory locationFactory, String absolutePath) { URI homeURI = locationFactory.getHomeLocation().toURI(); try { String path = URI.create("/").resolve(absolutePath.replaceAll("/+", "/")).normalize().getPath(); URI uri = new URI(homeURI.getScheme(), homeURI.getAuthority(), path, null, null); return locationFactory.create(uri); } catch (URISyntaxException e) { throw Throwables.propagate(e); } } private  Locations(); static InputSupplier<? extends SeekableInputStream> newInputSupplier(final FileSystem fs, final Path path); static InputSupplier<? extends SeekableInputStream> newInputSupplier(final Location location); static R processLocations(Location startLocation, boolean recursive,
                                       Processor<LocationStatus, R> processor); static File linkOrCopy(Location location, File targetPath); static void unpack(Location archive, File targetDir); static OutputSupplier<? extends OutputStream> newOutputSupplier(final Location location); static boolean isRoot(Location location); @Nullable static Location getParent(Location location); static Location getLocationFromAbsolutePath(LocationFactory locationFactory, String absolutePath); static void mkdirsIfNotExists(Location location); static void deleteQuietly(Location location); static void deleteQuietly(Location location, boolean recursive); static void deleteContent(Location location); static Location toLocation(File file); static Location toLocation(java.nio.file.Path path); static final Comparator<Location> LOCATION_COMPARATOR; }### Answer:
@Test public void absolutePathTests() { Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs: LocationFactory locationFactory = new FileContextLocationFactory(conf, TEST_BASE_PATH); Location location1 = locationFactory.create(TEST_PATH); Location location2 = Locations.getLocationFromAbsolutePath(locationFactory, location1.toURI().getPath()); Assert.assertEquals(location1.toURI(), location2.toURI()); conf = new Configuration(); conf.set("fs.defaultFS", "file: locationFactory = new FileContextLocationFactory(conf, TEST_BASE_PATH); location1 = locationFactory.create(TEST_PATH); location2 = Locations.getLocationFromAbsolutePath(locationFactory, location1.toURI().getPath()); Assert.assertEquals(location1.toURI(), location2.toURI()); locationFactory = new LocalLocationFactory(new File(TEST_BASE_PATH)); location1 = locationFactory.create(TEST_PATH); location2 = Locations.getLocationFromAbsolutePath(locationFactory, location1.toURI().getPath()); Assert.assertEquals(location1.toURI(), location2.toURI()); }