ValidationErrors { String message(String error, Map<String, String> arguments) { if (arguments == null) return error; var builder = new StringBuilder(error); for (Map.Entry<String, String> entry : arguments.entrySet()) { String var = "{" + entry.getKey() + "}"; int index = builder.indexOf(var); if (index >= 0) { builder.replace(index, index + var.length(), entry.getValue()); } } return builder.toString(); }  void add(String field, String error, Map<String, String> arguments); boolean hasError(); public Map<String, String> errors; }
@Test void message() { assertThat(errors.message("{value} must not larger than {max}", Map.of("value", "1", "max", "0"))) .isEqualTo("1 must not larger than 0"); assertThat(errors.message("{value}", Map.of())) .isEqualTo("{value}"); assertThat(errors.message("{value", Map.of("value", "1"))) .isEqualTo("{value"); assertThat(errors.message("{value}", Map.of("value", "1", "max", "100"))) .isEqualTo("1"); }