MessageImpl implements Message { @Override public String get(String key, String language) { return getMessage(key, language).orElseThrow(() -> new Error("can not find message, key=" + key)); }  void load(List<String> paths, String... languages); @Override String get(String key, String language);  }
@Test void get() { assertThat(message.get("key1", "zh")).isEqualTo("value1"); assertThat(message.get("key1", "en")).isEqualTo("value1"); assertThat(message.get("key1", "en_US")).isEqualTo("value1"); assertThat(message.get("key2", "zh")).isEqualTo("value2"); assertThat(message.get("key2", "en")).isEqualTo("en_value2"); assertThat(message.get("key2", "en_US")).isEqualTo("en_value2"); assertThat(message.get("key3", "zh")).isEqualTo("value3"); assertThat(message.get("key3", "en")).isEqualTo("en_value3"); assertThat(message.get("key3", "en_US")).isEqualTo("en_US_value3"); }
@Test void getWithNotDefinedLanguage() { assertThatThrownBy(() -> message.get("key1", "es_GT")) .isInstanceOf(Error.class) .hasMessageContaining("language is not defined"); }
@Test void getWithNotExistedKey() { assertThatThrownBy(() -> message.get("notExistedKey", "zh")) .isInstanceOf(Error.class) .hasMessageContaining("can not find message"); }