PropertyFileMessages implements Messages { @Override public String getMessage(final String key, final Object... arguments) { Validate.notEmpty(key, "Key can not be empty"); final String message = bundle.getString(key); return MessageFormat.format(message, arguments); } PropertyFileMessages(@NonNls final String baseName); @Override boolean hasMessage(final String key); @Override String getMessage(final String key, final Object... arguments);  }
@Test public void getMessageShouldThrowExceptionIfKeyIsNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Key can not be empty"); messages.getMessage(null); }
@Test public void getMessageShouldThrowExceptionIfKeyIsEmpty() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Key can not be empty"); messages.getMessage(" "); }
@Test public void getMessageShouldThrowExceptionIfKeyDontExist() { expectedException.expect(MissingResourceException.class); expectedException.expectMessage("Can't find resource for bundle java.util.PropertyResourceBundle, key nothing"); messages.getMessage("nothing"); }
@Test public void getMessageShouldReturnTheCorrectValue() { assertEquals("This is the first string", messages.getMessage("test.string1")); assertEquals("This is the second string", messages.getMessage("test.string2")); }
@Test public void getMessageShouldReplaceTheCorrectArguments() { assertEquals("Say hello to Nelly from Niles!", messages.getMessage("test.hello", "Nelly", "Niles")); assertEquals("Say hello to 3 from false!", messages.getMessage("test.hello", 3L, false)); }