MessagesImpl implements Messages { @Override public String getWithDefault(String key, String defaultMessage, Context context, Optional<Result> result, Object... params) { Optional<String> language = lang.getLanguage(context, result); return getWithDefault(key, defaultMessage, language, params); } @Inject  MessagesImpl(NinjaProperties ninjaProperties,
                        Lang lang); @Override Optional<String> get(String key,
                      Context context,
                      Optional<Result> result,
                      Object... parameter); @Override Optional<String> get(String key, Optional<String> language, Object... params); @Override Map<Object, Object> getAll(Context context, Optional<Result> result); @Override Map<Object, Object> getAll(Optional<String> language); @Override String getWithDefault(String key,
                                 String defaultMessage,
                                 Context context,
                                 Optional<Result> result,
                                 Object... params); @Override String getWithDefault(String key,
                                 String defaultMessage,
                                 Optional<String> language,
                                 Object... params);  }
@Test public void testGetWithDefaultAndLanguage() { when(ninjaProperties.getStringArray(NinjaConstant.applicationLanguages)) .thenReturn(new String[] { "en", "de", "fr-FR" }); Lang lang = new LangImpl(ninjaProperties); Messages messages = new MessagesImpl(ninjaProperties, lang); assertEquals("this is the placeholder: test_parameter", messages.getWithDefault("message_with_placeholder", "default value", Optional.of("en-US"), "test_parameter")); assertEquals("c'est le placeholder: test_parameter", messages.getWithDefault("message_with_placeholder", "default value", Optional.of("fr-FR"), "test_parameter")); assertEquals("c'est le message default: test_parameter", messages.getWithDefault("i_do_not_exist", "c''est le message default: {0}", Optional.of("fr-FR"), "test_parameter")); }
@Test public void testGetWithContextAndResultAndParameters() { when(ninjaProperties.getStringArray(NinjaConstant.applicationLanguages)) .thenReturn(new String[] { "en", "de", "fr-FR" }); Lang lang = new LangImpl(ninjaProperties); Messages messages = new MessagesImpl(ninjaProperties, lang); result = Results.ok(); when(context.getAcceptLanguage()).thenReturn("en-US"); assertEquals("this is the placeholder: test_parameter", messages.getWithDefault("message_with_placeholder", "default value", context, Optional.of(result), "test_parameter")); when(context.getAcceptLanguage()).thenReturn("fr-FR"); assertEquals("c'est le placeholder: test_parameter", messages.getWithDefault("message_with_placeholder", "default value", context, Optional.of(result), "test_parameter")); when(context.getAcceptLanguage()).thenReturn("fr-FR"); assertEquals("c'est le message default: test_parameter", messages.getWithDefault("i_do_not_exist", "c''est le message default: {0}", context, Optional.of(result), "test_parameter")); }