ConfigFileDelegationTokenUtils { public static String parseAndGetToken(ConfigFileReader.ConfigFile effectiveConfigFile) throws IOException { String delegationTokenFilePath = getDelegationTokenFilePath(effectiveConfigFile); if (StringUtils.isBlank(delegationTokenFilePath)) { return StringUtils.EMPTY; } StringBuilder tokenBuilder = new StringBuilder(); try (Stream<String> stream = Files.lines( Paths.get(FileUtils.expandUserHome(delegationTokenFilePath)), StandardCharsets.UTF_8)) { stream.forEach(s -> tokenBuilder.append(s)); } catch (IOException e) { LOG.warn("Exception in reading or parsing delegation token file", e); } return tokenBuilder.toString(); } private  ConfigFileDelegationTokenUtils(); static String parseAndGetToken(ConfigFileReader.ConfigFile effectiveConfigFile);  }
@Test public void loadDelegationTokenStringFromDelegationFileTest() throws IOException { PowerMockito.mockStatic(ConfigFileReader.class); ConfigFileReader.ConfigFile configFile = PowerMockito.mock(ConfigFileReader.ConfigFile.class); PowerMockito.when(configFile.get("delegation_token_file")) .thenReturn("src/test/resources/unit_test_delegation_token_file"); assertEquals( ConfigFileDelegationTokenUtils.parseAndGetToken(configFile), "testdelegationToken123456789"); }
@Test public void loadEmptyStringFromNonExistingDelegationTokenFileTest() throws IOException { PowerMockito.mockStatic(ConfigFileReader.class); ConfigFileReader.ConfigFile configFile = PowerMockito.mock(ConfigFileReader.ConfigFile.class); PowerMockito.when(configFile.get("delegation_token_file")) .thenReturn("src/test/resources/unit_test_delegation_file_does_not_exist"); assertEquals( ConfigFileDelegationTokenUtils.parseAndGetToken(configFile), StringUtils.EMPTY); }