### Question:
DistributedFileSystemPathProvider { public Path newPath(Configuration configuration) { String randomString = randomStringFactory.newInstance(); if (isBlank(security.getDistributedFileSystemWorkingDirectory())) { Path parentDirectory = getTemporaryFolder(configuration, randomString); return new Path(parentDirectory, GCP_KEY_NAME); } else { Path parentDirectory = new Path(security.getDistributedFileSystemWorkingDirectory(), randomString); return new Path(parentDirectory, GCP_KEY_NAME); } } @Autowired  DistributedFileSystemPathProvider(GCPSecurity security, RandomStringFactory randomStringFactory); Path newPath(Configuration configuration);  }### Answer:
@Test public void newInstanceWithoutConfigurationSet() { String dfsDirectory = "hdfs:/test-dir/"; doReturn(randomString).when(randomStringFactory).newInstance(); doReturn(dfsDirectory).when(configuration).get("hive.exec.scratchdir"); Path directory = new DistributedFileSystemPathProvider(security, randomStringFactory).newPath(configuration); String baseDirectoryExpected = dfsDirectory + randomString; assertThat(directory, is(new Path(baseDirectoryExpected, DistributedFileSystemPathProvider.GCP_KEY_NAME))); }
@Test public void newInstanceWithConfigurationSet() { String providedDirectory = "hdfs:/test/directory"; doReturn(randomString).when(randomStringFactory).newInstance(); security.setDistributedFileSystemWorkingDirectory(providedDirectory); Path directory = new DistributedFileSystemPathProvider(security, randomStringFactory).newPath(configuration); assertThat(directory.toString(), is(providedDirectory + "/" + randomString + "/" + DistributedFileSystemPathProvider.GCP_KEY_NAME)); }
@Test public void newInstanceWithoutHiveConfScratchDir() { doReturn("").when(configuration).get("hive.exec.scratchdir"); doReturn(randomString).when(randomStringFactory).newInstance(); Path directory = new DistributedFileSystemPathProvider(security, randomStringFactory).newPath(configuration); String baseDirectoryExpected = DistributedFileSystemPathProvider.DEFAULT_HDFS_PREFIX + randomString; assertThat(directory, is(new Path(baseDirectoryExpected, DistributedFileSystemPathProvider.GCP_KEY_NAME))); }