DefaultValidatorFactoryEx extends DefaultValidatorFactory { @Override public Validator getValidator( String beanName, Object bean, Errors errors) { Validator validator = new CommonsValidatorEx(getValidatorResources(), beanName); SpringValidationErrors commonErrors = createSpringValidationErrors(); commonErrors.setErrors(errors); validator.setParameter(TERASOLUNA_ERRORS_KEY, commonErrors); validator.setParameter(Validator.BEAN_PARAM, bean); return validator; }  @Override Validator getValidator(
            String beanName, Object bean, Errors errors); static final String TERASOLUNA_ERRORS_KEY; }
@Test public void testGetValidator01() throws Exception { String beanName = null; Object bean = null; Errors errors = null; DefaultValidatorFactoryEx factory = new DefaultValidatorFactoryEx(); ValidatorResources resources = new ValidatorResources(); ReflectionTestUtils.setField(factory, "validatorResources", resources); Validator validator = null; validator = factory.getValidator(beanName, bean, errors); SpringValidationErrors resultErorrs = (SpringValidationErrors) validator .getParameterValue( "jp.terasoluna.fw.validation.ValidationErrors"); assertNull(resultErorrs.getErrors()); assertNull(validator.getParameterValue("java.lang.Object")); assertNull(validator.getFormName()); }
@Test public void testGetValidator02() throws Exception { String beanName = ""; Object bean = "bean"; Errors errors = new ErrorsImpl01(); DefaultValidatorFactoryEx factory = new DefaultValidatorFactoryEx(); ValidatorResources resources = new ValidatorResources(); ReflectionTestUtils.setField(factory, "validatorResources", resources); Validator validator = null; validator = factory.getValidator(beanName, bean, errors); SpringValidationErrors resultErorrs = (SpringValidationErrors) validator .getParameterValue( "jp.terasoluna.fw.validation.ValidationErrors"); assertSame(errors, resultErorrs.getErrors()); assertSame(bean, validator.getParameterValue("java.lang.Object")); assertEquals(beanName, validator.getFormName()); }
@Test public void testGetValidator03() throws Exception { String beanName = "beanName"; Object bean = "bean"; Errors errors = new ErrorsImpl01(); List<Object> list = new ArrayList<Object>(); list.add(0, new Object()); ReflectionTestUtils.setField(errors, "errors", list); DefaultValidatorFactoryEx factory = new DefaultValidatorFactoryEx(); ValidatorResources resources = new ValidatorResources(); ReflectionTestUtils.setField(factory, "validatorResources", resources); Validator validator = null; validator = factory.getValidator(beanName, bean, errors); SpringValidationErrors resultErorrs = (SpringValidationErrors) validator .getParameterValue( "jp.terasoluna.fw.validation.ValidationErrors"); assertSame(errors, resultErorrs.getErrors()); assertSame(bean, validator.getParameterValue("java.lang.Object")); assertEquals(beanName, validator.getFormName()); }
@Test public void testGetValidator04() throws Exception { String beanName = "beanName"; Object bean = "bean"; Errors errors = new ErrorsImpl01(); List<Object> list = new ArrayList<Object>(); list.add(0, new Object()); list.add(1, new Object()); list.add(2, new Object()); ReflectionTestUtils.setField(errors, "errors", list); DefaultValidatorFactoryEx factory = new DefaultValidatorFactoryEx(); ValidatorResources resources = new ValidatorResources(); ReflectionTestUtils.setField(factory, "validatorResources", resources); Validator validator = null; validator = factory.getValidator(beanName, bean, errors); SpringValidationErrors resultErorrs = (SpringValidationErrors) validator .getParameterValue( "jp.terasoluna.fw.validation.ValidationErrors"); assertSame(errors, resultErorrs.getErrors()); assertSame(bean, validator.getParameterValue("java.lang.Object")); assertEquals(beanName, validator.getFormName()); }