MessageImpl implements Message { String language(String path) { Matcher matcher = MESSAGE_PROPERTY_PATH_PATTERN.matcher(path); if (!matcher.matches()) throw new Error("property path must match 'path/name_language.properties' pattern, path=" + path); String languagePostfix = matcher.group(1); if (Strings.isBlank(languagePostfix)) return DEFAULT_LANGUAGE; return languagePostfix.substring(1); }  void load(List<String> paths, String... languages); @Override String get(String key, String language);  }
@Test void language() { assertThat(message.language("messages_en_US.properties")).isEqualTo("en_US"); assertThat(message.language("messages_en.properties")).isEqualTo("en"); assertThat(message.language("messages.properties")).isEqualTo(MessageImpl.DEFAULT_LANGUAGE); assertThatThrownBy(() -> message.language("invalid.message_E.properties")) .isInstanceOf(Error.class) .hasMessageContaining("property path must match 'path/name_language.properties' pattern"); }