MessageAccessorImpl extends ApplicationObjectSupport implements
                                                                 MessageAccessor { @Override public String getMessage(String code, Object[] args) { return getMessageSourceAccessor().getMessage(code, args); }  @Override String getMessage(String code, Object[] args); @Override String getMessage(MessageSourceResolvable resolvable);  }
@Test public void testGetMessage01() throws Exception { String[] args = { "test1" }; String result = messageAccessor.getMessage("errors.alphaNumericString", args); assertEquals("test1には半角英数字で入力してください.", result); }
@Test public void testGetMessage02() throws Exception { String result = messageAccessor.getMessage("errors.alphaNumericString", null); assertEquals("{0}には半角英数字で入力してください.", result); }
@Test public void testGetMessage03() throws Exception { try { messageAccessor.getMessage("test", null); fail(); } catch (NoSuchMessageException e) { } }
@Test public void testGetMessage04() throws Exception { try { messageAccessor.getMessage("", null); fail(); } catch (NoSuchMessageException e) { } }
@Test public void testGetMessage05() throws Exception { try { messageAccessor.getMessage(null, null); fail(); } catch (NoSuchMessageException e) { } }
@Test public void testGetMessage06() throws Exception { MessageSourceResolvable resolvable = null; try { messageAccessor.getMessage(resolvable); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { } }
@Test public void testGetMessage07() throws Exception { ValidationTargetDummyBean validationTargetDummy = new ValidationTargetDummyBean(); validationTargetDummy.setHoge(null); Errors errors = new BindException(validationTargetDummy, "dummy"); ValidationUtils.rejectIfEmpty(errors, "hoge", "errors.noKey", new Object[] { "テスト" }, "デフォルトメッセージです"); List<FieldError> fieldErrors = errors.getFieldErrors(); assertEquals(1, fieldErrors.size()); String result = messageAccessor.getMessage(fieldErrors.get(0)); assertEquals("デフォルトメッセージです", result); }
@Test public void testGetMessage08() throws Exception { ValidationTargetDummyBean validationTargetDummy = new ValidationTargetDummyBean(); validationTargetDummy.setHoge(null); Errors errors = new BindException(validationTargetDummy, "dummy"); ValidationUtils.rejectIfEmpty(errors, "hoge", "errors.required", new Object[] { "テスト" }, "デフォルトメッセージです"); List<FieldError> fieldErrors = errors.getFieldErrors(); assertEquals(1, fieldErrors.size()); String result = messageAccessor.getMessage(fieldErrors.get(0)); assertEquals("テストは入力必須項目です.", result); }
@Test public void testGetMessage09() throws Exception { ValidationTargetDummyBean validationTargetDummy = new ValidationTargetDummyBean(); validationTargetDummy.setHoge(null); Errors errors = new BindException(validationTargetDummy, "dummy"); ValidationUtils.rejectIfEmpty(errors, "hoge", "errors.noKey", new Object[] { "テスト" }); List<FieldError> fieldErrors = errors.getFieldErrors(); assertEquals(1, fieldErrors.size()); try { messageAccessor.getMessage(fieldErrors.get(0)); fail("NoSuchMessageExceptionが発生しませんでした。"); } catch (NoSuchMessageException e) { } }