### Question:
RpcAuthFileValidator { public static String validate( final CommandLine commandLine, final String filename, final String type) { final File authfile = new File(filename); if (!authfile.exists()) { throw new ParameterException( commandLine, "The specified RPC " + type + " authentication credential file '" + filename + "' does not exist"); } final TomlParseResult tomlParseResult; try { tomlParseResult = TomlConfigFileParser.loadConfigurationFromFile(filename); } catch (IOException e) { throw new ParameterException( commandLine, "An error occurred while opening the specified RPC " + type + " authentication configuration file."); } catch (Exception e) { throw new ParameterException( commandLine, "Invalid RPC " + type + " authentication credentials file: " + e.getMessage()); } if (tomlParseResult.hasErrors()) { throw new ParameterException( commandLine, "An error occurred while parsing the specified RPC authentication configuration file."); } if (!verifyAllUsersHavePassword(tomlParseResult)) { throw new ParameterException(commandLine, "RPC user specified without password."); } if (!verifyAllEntriesHaveValues(tomlParseResult)) { throw new ParameterException( commandLine, "RPC authentication configuration file contains invalid values."); } return filename; }  static String validate(
      final CommandLine commandLine, final String filename, final String type);  }### Answer:
@Test public void shouldPassWhenCorrectTOML() { assertThatCode( () -> RpcAuthFileValidator.validate(commandLine, getFilePath(CORRECT_TOML), "HTTP")) .doesNotThrowAnyException(); }
@Test public void shouldFailWhenInvalidTOML() { assertThatThrownBy( () -> RpcAuthFileValidator.validate(commandLine, getFilePath(INVALID_TOML), "HTTP")) .isInstanceOf(ParameterException.class) .hasMessageContaining("Invalid TOML configuration"); }
@Test public void shouldFailWhenMissingTOML() { assertThatThrownBy( () -> RpcAuthFileValidator.validate(commandLine, "thisshouldntexist", "HTTP")) .isInstanceOf(ParameterException.class) .hasMessage( "The specified RPC HTTP authentication credential file 'thisshouldntexist' does not exist"); }
@Test public void shouldFailWhenMissingPassword() { assertThatThrownBy( () -> RpcAuthFileValidator.validate(commandLine, getFilePath(NO_PASSWORD_TOML), "HTTP")) .isInstanceOf(ParameterException.class) .hasMessage("RPC user specified without password."); }
@Test public void shouldFailWhenInvalidGroupsKeyValue() { assertThatThrownBy( () -> RpcAuthFileValidator.validate( commandLine, getFilePath(INVALID_GROUPS_VALUE_TOML), "HTTP")) .isInstanceOf(ParameterException.class) .hasMessage("RPC authentication configuration file contains invalid values."); }
@Test public void shouldFailWhenInvalidPermissionsKeyValue() { assertThatThrownBy( () -> RpcAuthFileValidator.validate( commandLine, getFilePath(INVALID_PERMISSIONS_VALUE_TOML), "HTTP")) .isInstanceOf(ParameterException.class) .hasMessage("RPC authentication configuration file contains invalid values."); }
@Test public void shouldFailWhenInvalidEmptyPrivacyPublicKeyValue() { assertThatThrownBy( () -> RpcAuthFileValidator.validate( commandLine, getFilePath(INVALID_PRIVACY_PUBLIC_KEY_VALUE_TOML), "HTTP")) .isInstanceOf(ParameterException.class) .hasMessage("RPC authentication configuration file contains invalid values."); }
@Test public void shouldFailWhenDuplicateUser() { assertThatThrownBy( () -> RpcAuthFileValidator.validate( commandLine, getFilePath(DUPLICATE_USER_TOML), "HTTP")) .isInstanceOf(ParameterException.class) .hasMessageContaining("Invalid TOML configuration"); }