/** * Get the message from the bundle. * * @param key the key * @return the message */ @Override public String get(String key) { if (key == null) { return "??????"; } try { return getBundle().getString(key); } catch (MissingResourceException e) { return "???" + key + "???"; } }
/** * Iterate over the keys. */ @Override public Iterator<String> keys() { ResourceBundle bundle = this.getBundle(); if (bundle != null) { return IteratorUtils.asIterator(bundle.getKeys()); } return IteratorUtils.EMPTY_ITERATOR; } }
@Test public void testGetBundle() { // GIVEN final DefaultMessagesImpl defaultMessagesImpl = new DefaultMessagesImpl(UTF8_BUNDLE, Locale.JAPANESE); // WHEN final ResourceBundle resourceBundle = defaultMessagesImpl.getBundle(); // THEN assertEquals(UTF8_TEST_STRING, resourceBundle.getString("test.add")); }
assertThat(() -> defaultMessagesImpl.getBundle().getString("title"), throwsAnException(instanceOf(MissingResourceException.class)));