?? ovalvalidatortest.java
字號(hào):
package com.google.code.rsser.web.validator;import java.util.HashMap;import junit.framework.Assert;import org.junit.Before;import org.junit.Test;import org.springframework.validation.Errors;import org.springframework.validation.MapBindingResult;import org.springframework.validation.ValidationUtils;import net.sf.oval.Validator;import net.sf.oval.constraint.Length;public class OvalValidatorTest { class MyClass { @Length(min = 5, max = 10, profiles = { "one" }) protected int a; @Length(min = 5, max = 10, profiles = { "two" }) protected int b; public int getA() { return a; } public void setA(int a) { this.a = a; } public int getB() { return b; } public void setB(int b) { this.b = b; } } private OvalValidator ovalValidator; private Validator validator; @Before public void setUp() throws Exception { ovalValidator = new OvalValidator(); validator = new Validator(); ovalValidator.setValidator(validator); ovalValidator.afterPropertiesSet(); } @Test public void testA() throws Exception { MyClass obj = new MyClass(); obj.setA(11); obj.setB(11); Assert.assertEquals(1, getValidationErrorCount(obj, "one")); } @Test public void testB() throws Exception { MyClass obj = new MyClass(); obj.setA(11); obj.setB(11); Assert.assertEquals(1, getValidationErrorCount(obj, "two")); } @Test public void testBoth() throws Exception { MyClass obj = new MyClass(); obj.setA(11); obj.setB(11); Assert.assertEquals(2, getValidationErrorCount(obj, null)); } @SuppressWarnings("unchecked") protected int getValidationErrorCount(Object obj, String profile) { ovalValidator.setProfile(profile); Errors errors = new MapBindingResult(new HashMap(), "test"); ValidationUtils.invokeValidator(ovalValidator, obj, errors); return errors.getErrorCount(); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -