Messages { public String get(String key, Object... params) { if (request != null) { final Enumeration<Locale> locales = request.getLocales(); while (locales.hasMoreElements()) { final String message = get(key, locales.nextElement(), params); if (message != null) { return message; } } } return get(key, Locale.ENGLISH, params); }  String get(String key, Object... params); String get(String key, Locale locale, Object... params);  }
@Test public void testMessages() { assertTrue(messages.get("NoViewEngine", "MyView").contains("'MyView'")); assertTrue(messages.get("VoidControllerNoView", "foo()").contains("'foo()'")); assertTrue(messages.get("UnableValidateCsrf", "foo").contains("'foo'")); assertTrue(messages.get("CsrfFailed", "some reason").contains("some reason")); }
@Test public void testGet() { assertNull(messages.get("Blabla", Locale.US, new Object[] {})); }
@Test public void testGet2() throws Exception { HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class); Field field = messages.getClass().getDeclaredField("request"); field.setAccessible(true); field.set(messages, request); ArrayList<Locale> locales = new ArrayList<>(); locales.add(Locale.FRENCH); locales.add(Locale.ENGLISH); expect(request.getLocales()).andReturn(Collections.enumeration(locales)); replay(request); assertEquals("Validation of CSRF failed due to {0}", messages.get("CsrfFailed", new Object[] {})); verify(request); }