MessageImpl implements Message { void validateMessageKeys() { Map<String, Set<String>> allLanguageKeys = Maps.newHashMap(); Set<String> allKeys = Sets.newHashSet(); messages.forEach((language, languageProperties) -> { Set<String> languageKeys = Sets.newHashSet(); languageProperties.forEach(properties -> languageKeys.addAll(properties.keys())); allKeys.addAll(languageKeys); allLanguageKeys.put(language, languageKeys); }); allLanguageKeys.forEach((language, keys) -> { if (!allKeys.equals(keys)) { Set<String> missingKeys = new HashSet<>(allKeys); missingKeys.removeAll(keys); throw new Error(format("message keys are missing for language, language={}, keys={}", language, missingKeys)); } }); }  void load(List<String> paths, String... languages); @Override String get(String key, String language);  }
@Test void validateMessageKeys() { Properties properties = new Properties(); properties.set("key4", "value4"); message.messages.get("zh").add(properties); assertThatThrownBy(() -> message.validateMessageKeys()) .isInstanceOf(Error.class) .hasMessageContaining("message keys are missing for language") .hasMessageContaining("language=en_US"); }