@Test public void shouldSupportPostfixFormat() throws Exception { resolver.setMessageCodeFormatter(Format.POSTFIX_ERROR_CODE); String[] codes = resolver.resolveMessageCodes("errorCode", "objectName"); assertThat(codes, is(equalTo(new String[] { "objectName.errorCode", "errorCode" }))); }
@Test public void shouldSupportFieldPostfixFormat() throws Exception { resolver.setMessageCodeFormatter(Format.POSTFIX_ERROR_CODE); String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field", TestBean.class); assertThat(codes, is(equalTo(new String[] { "objectName.field.errorCode", "field.errorCode", "org.springframework.tests.sample.beans.TestBean.errorCode", "errorCode" }))); }
@Test public void shouldSupportCustomFormat() throws Exception { resolver.setMessageCodeFormatter(new MessageCodeFormatter() { @Override public String format(String errorCode, String objectName, String field) { return DefaultMessageCodesResolver.Format.toDelimitedString( "CUSTOM-" + errorCode, objectName, field); } }); String[] codes = resolver.resolveMessageCodes("errorCode", "objectName"); assertThat(codes, is(equalTo(new String[] { "CUSTOM-errorCode.objectName", "CUSTOM-errorCode" }))); }
/** * {@inheritDoc} */ @Override public String format(String errorCode, String objectName, String field) { return Format.toDelimitedString(objectName, field); }