📄 testvalidationutilities.java
字号:
package net.sf.irunninglog.validation;
import java.util.ArrayList;
import net.sf.irunninglog.junit.FooBean;
import net.sf.irunninglog.util.ConstantValues;
import net.sf.irunninglog.util.DTO;
public class TestValidationUtilities extends ValidationTestCase {
private static final String [] METHOD_NAMES =
new String [] {"executeRequiredFieldValidation",
"executeMaxLengthValidation",
"executeMinLengthValidation",
"executeBooleanValidation",
"executeDecimalValidation",
"executeDateValidation",
"executeEmailValidation",
"executeValidValuesValidation",
"executeMinValueValidation",
"executeMaxValueValidation",
"executeTimeValidation"};
private static final Object [][] VALID_METHOD_PARAMS =
new Object [][]{
new Object[] {new DTO(VALID_CLASS_ID), STRING_FOO, new ArrayList()}
};
private static final Object [][] ILLEGAL_ARG_METHOD_PARAMS =
new Object [][] {
new Object [] {null, null, null},
new Object [] {new DTO(), null, null},
new Object [] {null, INVALID_FIELD_NAME, null},
new Object [] {null, null, new ArrayList()},
new Object [] {new DTO(), INVALID_FIELD_NAME, null},
new Object [] {null, INVALID_FIELD_NAME, new ArrayList()},
new Object [] {new DTO(), null, new ArrayList()},
new Object [] {new DTO(), " ", new ArrayList()}
};
private static final Object [][] MISSING_RESOURCE_METHOD_PARAMS =
new Object [][] {
new Object [] {new DTO(), INVALID_FIELD_NAME, new ArrayList()},
new Object [] {new DTO(INVALID_CLASS_ID), INVALID_FIELD_NAME, new ArrayList()}
};
public TestValidationUtilities(String name) {
super(name);
}
public void setUp() {
super.setUp();
}
public void testGetValueAsString() {
try{
ValidationUtilities.getValueAsString(null, null);
failTest();
}catch (IllegalArgumentException ex) {
assertTrue(true);
}
try{
ValidationUtilities.getValueAsString(ConstantValues.STRING_BLANK, null);
failTest();
}catch (IllegalArgumentException ex) {
assertTrue(true);
}
try{
ValidationUtilities.getValueAsString(STRING_FOO, null);
failTest();
}catch (IllegalArgumentException ex) {
assertTrue(true);
}
assertNull(ValidationUtilities.getValueAsString(STRING_FOO, ""));
assertNull(ValidationUtilities.getValueAsString(new Object(), STRING_FOO));
FooBean foo = new FooBean();
assertEquals(STRING_FOO, ValidationUtilities.getValueAsString(foo, FOO_PROPERTY_NAME));
assertNull(ValidationUtilities.getValueAsString(foo, STRING_FOO));
}
protected String[] getAllMethodNames() {
return METHOD_NAMES;
}
protected Object[][] getIllegalArgumentMethodParameters() {
return ILLEGAL_ARG_METHOD_PARAMS;
}
protected Object[][] getMissingResourceMethodParameters() {
return MISSING_RESOURCE_METHOD_PARAMS;
}
protected Object[][] getValidMethodParameters() {
return VALID_METHOD_PARAMS;
}
protected Class getClassForTesting() {
return ValidationUtilities.class;
}
protected String getRequiredFieldValidationMethodName() {
return METHOD_NAMES[0];
}
protected String getMaxLengthValidationMethodName() {
return METHOD_NAMES[1];
}
protected String getMinLengthValidationMethodName() {
return METHOD_NAMES[2];
}
protected String getBooleanValidationMethodName() {
return METHOD_NAMES[3];
}
protected String getDecimalValidationMethodName() {
return METHOD_NAMES[4];
}
protected String getDateValidationMethodName() {
return METHOD_NAMES[5];
}
protected String getEmailValidationMethodName() {
return METHOD_NAMES[6];
}
protected String getValidValueValidationMethodName() {
return METHOD_NAMES[7];
}
protected String getMinValueValidationMethodName() {
return METHOD_NAMES[8];
}
protected String getMaxValueValidationMethodName() {
return METHOD_NAMES[9];
}
protected String getTimeValidationMethodName() {
return METHOD_NAMES[10];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -