Java 类org.springframework.validation.DefaultMessageCodesResolver.Format 实例源码

项目:spring4-understanding    文件:DefaultMessageCodesResolverTests.java   
@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" })));
}
项目:spring4-understanding    文件:DefaultMessageCodesResolverTests.java   
@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" })));
}
项目:spring4-understanding    文件:DefaultMessageCodesResolverTests.java   
@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" })));
}
项目:class-guard    文件:DefaultMessageCodesResolverTests.java   
@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" })));
}
项目:class-guard    文件:DefaultMessageCodesResolverTests.java   
@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" })));
}
项目:class-guard    文件:DefaultMessageCodesResolverTests.java   
@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" })));
}
项目:sinavi-jfw    文件:MessageCodesFormat.java   
/**
 * {@inheritDoc}
 */
@Override
public String format(String errorCode, String objectName, String field) {
    return Format.toDelimitedString(objectName, field);
}