private Config mockConfigMessages() { PropertyResourceBundle bundle = mock(PropertyResourceBundle.class); when(bundle.handleGetObject("Feedback.validated-mail-text")).thenReturn(validationMessage); when(bundle.handleGetObject("Feedback.mail-title")).thenReturn(title); Config config = mock(Config.class); when(config.getMessages(any(Locale.class))).thenReturn(bundle); return config; }
/** * Returns the message string with the specified key from the "properties" file in the package * containing the class with the specified name. */ protected static final String getString(String className, String key) { PropertyResourceBundle bundle = null; try { InputStream stream = Class.forName(className).getResourceAsStream("properties"); bundle = new PropertyResourceBundle(stream); } catch (Throwable e) { throw new RuntimeException(e); // Chain the exception. } return (String) bundle.handleGetObject(key); }
protected Object handleGetObject(String key) { for (String name : bundleNames) { PropertyResourceBundle bundle = getPropertyResourceBundle(name); if (bundle != null) { Object value = bundle.handleGetObject(key); if (value != null) { return value; } } } return null; }
protected Object handleGetObject(String key) { String result = (String) bundle.handleGetObject(key); try { // We do not buffer the encoded result since the RWT.NLS mechanism // creates and buffers the completely initialized nls instance. So each // entry should only be read once. if (result != null) { result = new String(result.getBytes("ISO-8859-1"), "UTF-8"); } } catch (UnsupportedEncodingException uee) { // ignore } return result; }