### Question:
FileBasedPasswordProvider implements Supplier<String> { @Override public String get() { try (final Stream<String> fileStream = Files.lines(passwordFile)) { return fileStream .findFirst() .orElseThrow( () -> new TlsConfigurationException( String.format( "Unable to read keystore password from %s", passwordFile.toString()))); } catch (final IOException e) { throw new TlsConfigurationException( String.format("Unable to read keystore password file %s", passwordFile.toString()), e); } } FileBasedPasswordProvider(final Path passwordFile); @Override String get();  }### Answer:
@Test public void passwordCanBeReadFromFile() throws IOException { final Path passwordFile = folder.newFile().toPath(); Files.write(passwordFile, List.of("line1", "line2")); final String password = new FileBasedPasswordProvider(passwordFile).get(); Assertions.assertThat(password).isEqualTo("line1"); }
@Test public void exceptionRaisedFromReadingEmptyFile() throws IOException { final Path passwordFile = folder.newFile().toPath(); Files.write(passwordFile, new byte[0]); Assertions.assertThatExceptionOfType(TlsConfigurationException.class) .isThrownBy( () -> { new FileBasedPasswordProvider(passwordFile).get(); }) .withMessageContaining("Unable to read keystore password from"); }
@Test public void exceptionRaisedFromReadingNonExistingFile() throws IOException { Assertions.assertThatExceptionOfType(TlsConfigurationException.class) .isThrownBy( () -> { new FileBasedPasswordProvider(Path.of("/tmp/invalid_file.txt")).get(); }) .withMessageContaining("Unable to read keystore password file"); }