testvalidations.java

来自「A Java web application, based on Struts 」· Java 代码 · 共 155 行

JAVA
155
字号
package net.sf.irunninglog.validation;

import java.util.ArrayList;

import org.apache.commons.validator.Field;
import org.apache.commons.validator.ValidatorAction;

import net.sf.irunninglog.util.DTO;

public class TestValidations extends ValidationTestCase {

    private static final String [] METHOD_NAMES = {"validateRequired",
                                                  "validateMaxLength",
                                                  "validateMinLength",
                                                  "validateMaxValue",
                                                  "validateMinValue",
                                                  "validateBoolean",
                                                  "validateDate",
                                                  "validateDecimal",
                                                  "validateEmail",
                                                  "validateValidValues",
                                                  "validateTime"};

    private static final Object [][] VALID_METHOD_PARAMS =
        new Object [][]{
            new Object[] {new DTO(VALID_CLASS_ID),
                    ValidationUtilities.getNewValidatorAction(ValidationUtilities.ERROR_INVALID_EMAIL),
                    ValidationUtilities.getNewValidationField(VALID_FIELD_NAME),
                    new ArrayList()},
            new Object[] {new DTO(VALID_CLASS_ID),
                    ValidationUtilities.getNewValidatorAction(STRING_FOO),
                    ValidationUtilities.getNewValidationField(VALID_FIELD_NAME),
                    new ArrayList()},
            new Object[] {new DTO(VALID_CLASS_ID),
                    ValidationUtilities.getNewValidatorAction(null),
                    ValidationUtilities.getNewValidationField(VALID_FIELD_NAME),
                    new ArrayList()}
        };

    private static final Object [][] ILLEGAL_ARG_METHOD_PARAMS =
        new Object [][] {
            // DTO not null
            new Object [] {new DTO(), null, null, null},
            new Object [] {new DTO(), new ValidatorAction(), null, null},
            new Object [] {new DTO(), null, new Field(), null},
            new Object [] {new DTO(), null, null, new ArrayList()},
            new Object [] {new DTO(), new ValidatorAction(), new Field(), null},
            new Object [] {new DTO(), null, new Field(), new ArrayList()},
            new Object [] {new DTO(), new ValidatorAction(), null, new ArrayList()},
            // ValidatorAction not null
            new Object [] {null, new ValidatorAction(), null, null},
            new Object [] {new DTO(), new ValidatorAction(), null, null},
            new Object [] {null, new ValidatorAction(), new Field(), null},
            new Object [] {null, new ValidatorAction(), null, new ArrayList()},
            new Object [] {new DTO(), new ValidatorAction(), new Field(), null},
            new Object [] {new DTO(), new ValidatorAction(), null, new ArrayList()},
            new Object [] {null, new ValidatorAction(), new Field(), new ArrayList()},
            // Field not null
            new Object [] {null, null, new Field(), null},
            new Object [] {new DTO(), null, new Field(), null},
            new Object [] {null, new ValidatorAction(), new Field(), null},
            new Object [] {null, null, new Field(), new ArrayList()},
            new Object [] {new DTO(), new ValidatorAction(), new Field(), null},
            new Object [] {null, new ValidatorAction(), new Field(), new ArrayList()},
            new Object [] {new DTO(), null, new Field(), new ArrayList()},
            // List not null
            new Object [] {null, null, null, new ArrayList()},
            new Object [] {new DTO(), null, null, new ArrayList()},
            new Object [] {null, new ValidatorAction(), null, new ArrayList()},
            new Object [] {null, null, new Field(), new ArrayList()},
            new Object [] {new DTO(), new ValidatorAction(), null, new ArrayList()},
            new Object [] {new DTO(), null, new Field(), new ArrayList()},
            new Object [] {null, new ValidatorAction(), new Field(), new ArrayList()},
            // All null
            new Object [] {null, null, null, null}
        };

    private static Object [][] MISSING_RESOURCE_METHOD_PARAMS =
        new Object [][] {
            new Object [] {new DTO(), new ValidatorAction(), new Field(), new ArrayList()},
            new Object [] {new DTO(VALID_CLASS_ID), new ValidatorAction(), new Field(), new ArrayList()},
            new Object [] {new DTO(INVALID_CLASS_ID), new ValidatorAction(), new Field(), new ArrayList()},
            new Object [] {new DTO(INVALID_CLASS_ID), new ValidatorAction(), ValidationUtilities.getNewValidationField(INVALID_FIELD_NAME), new ArrayList()}
        };

    public TestValidations(String name) {
        super(name);
    }

    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 Validations.class;
    }

    protected String getMaxLengthValidationMethodName() {
        return "validateMaxLength";
    }

    protected String getRequiredFieldValidationMethodName() {
        return "validateRequired";
    }

    protected String getMinLengthValidationMethodName() {
        return "validateMinLength";
    }

    protected String getMaxValueValidationMethodName() {
        return "validateMaxValue";
    }

    protected String getMinValueValidationMethodName() {
        return "validateMinValue";
    }

    protected String getDateValidationMethodName() {
        return "validateDate";
    }

    protected String getEmailValidationMethodName() {
        return "validateEmail";
    }

    protected String getDecimalValidationMethodName() {
        return "validateDecimal";
    }

    protected String getBooleanValidationMethodName() {
        return "validateBoolean";
    }

    protected String getValidValueValidationMethodName() {
        return "validateValidValues";
    }

    protected String getTimeValidationMethodName() {
        return "validateTime";
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?