⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testrunnerbo.java

📁 A Java web application, based on Struts and Hibernate, that serves as an online running log. Users m
💻 JAVA
字号:
package net.sf.irunninglog.businessobject;

import java.util.Calendar;
import java.util.Date;

import net.sf.irunninglog.canonical.Runner;
import net.sf.irunninglog.util.ConstantValues;
import net.sf.irunninglog.util.DTO;

public class TestRunnerBO extends HasRunnerIdBOTestCase {

    protected static final String V_NAME_1 = "11111111112222222222";
    protected static final String V_NAME_2 = "111111111122222222223333333333"
                                             + "111111111122222222223333333333"
                                             + "111111111122222222223333333333"
                                             + "1111111111";
    protected static final String I_NAME_1 = V_NAME_2 + "1";
    protected static final String V_EMAIL_1 = "allan_e_lewis@yahoo.com";
    protected static final String V_EMAIL_2 = "111111111122222222223333333333"
                                              + "111111111122222222223333333333"
                                              + "111111111122222222223333333333"
                                              + "1@test.com";
    protected static final String I_EMAIL_1 = "abcdefgh";
    protected static final String I_EMAIL_2 = "abcdefgh@";
    protected static final String I_EMAIL_3 = "abcdefgh@csac";
    protected static final String I_EMAIL_4 = "abcdefgh@csac.";
    protected static final String I_EMAIL_5 = V_EMAIL_2 + "s";
    protected static final String V_DOB_1 = "3/1/05";
    protected static final String V_DOB_2 = "03/01/2005";
    protected static final String I_DOB_1 = "03/01";
    protected static final String I_DOB_2 = "03";
    protected static final String I_DOB_3 = "03/01/";
    protected static final String V_GENDER_1 = "Male";
    protected static final String V_GENDER_2 = "Female";
    protected static final String I_GENDER_1 = "male";
    protected static final String I_GENDER_2 = "female";

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

    public void testDefaultValues() {
        super.testDefaultValues();

        executeDefaultValuesTests(Runner.FIELD_NAME, null);
        executeDefaultValuesTests(Runner.FIELD_EMAIL, null);
        executeDefaultValuesTests(Runner.FIELD_GENDER, null);
        executeDefaultValuesTests(Runner.FIELD_DATE_OF_BIRTH, null);
        executeDefaultValuesTests(Runner.FIELD_AGE, null);
    }

    public void testFields() {
        super.testFields();

        executeStringFieldTests(Runner.FIELD_NAME);
        executeStringFieldTests(Runner.FIELD_EMAIL);
        executeStringFieldTests(Runner.FIELD_GENDER);
        executeDateFieldTests(Runner.FIELD_DATE_OF_BIRTH);

        RunnerBO runner = (RunnerBO) bo;
        Calendar cal = Calendar.getInstance();

        runner.setDateOfBirth(null);
        assertNull(runner.getAge());

        runner.setDateOfBirth(cal.getTime());
        assertEquals(0, Integer.parseInt(runner.getAge()));

        cal.add(Calendar.MONTH, -11);
        runner.setDateOfBirth(cal.getTime());
        assertEquals(0, Integer.parseInt(runner.getAge()));

        cal.add(Calendar.YEAR, -2);
        runner.setDateOfBirth(cal.getTime());
        assertEquals(2, Integer.parseInt(runner.getAge()));

        cal = Calendar.getInstance();
        cal.add(Calendar.YEAR, -10);
        runner.setDateOfBirth(cal.getTime());
        assertEquals(10, Integer.parseInt(runner.getAge()));
    }

    public void testGetValues() {
        super.testGetValues();
    }

    public void testGetValuesInternal() {
        super.testGetValuesInternal();
    }

    public void testPrimaryKey() {
        super.testPrimaryKey();

        DTO key = null;
        bo.setPrimaryKey(key);
        assertNull(bo.getPrimaryKey());

        key = getNewDTO();
        bo.setPrimaryKey(key);
        assertNull(bo.getPrimaryKey());

        key.setValue(Runner.FIELD_RUNNER_ID, V_RUNNER_ID_1);
        bo.setPrimaryKey(key);
        assertEquals(V_RUNNER_ID_1, bo.getPrimaryKey());
    }

    public void testSetValues() {
        super.testSetValues();

        executeSetValuesTests(Runner.FIELD_NAME,
                              new String [] {V_NAME_1, V_NAME_2},
                              new String [] {null, ConstantValues.STRING_BLANK, I_NAME_1});

        executeSetValuesTests(Runner.FIELD_EMAIL,
                              new String [] {null, ConstantValues.STRING_BLANK, V_EMAIL_1, V_EMAIL_2},
                              new String [] {I_EMAIL_1, I_EMAIL_2, I_EMAIL_3, I_EMAIL_4, I_EMAIL_5});

        executeSetValuesTests(Runner.FIELD_DATE_OF_BIRTH,
                              new String [] {null, ConstantValues.STRING_BLANK, V_DOB_1, V_DOB_2},
                              new String [] {I_DOB_1, I_DOB_2, I_DOB_3, STRING_FOO});

        executeSetValuesTests(Runner.FIELD_GENDER,
                              new String [] {null, ConstantValues.STRING_BLANK, V_GENDER_1, V_GENDER_2},
                              new String [] {STRING_FOO, I_GENDER_2, I_GENDER_2});
    }

    public void testSetValuesInternal() {
        super.testSetValuesInternal();

        executeSetValuesInternalTests(Runner.FIELD_NAME,
                                      String.class,
                                      new String [] {null, ConstantValues.STRING_BLANK, V_NAME_1, V_NAME_2, I_NAME_1},
                                      new String [] {});

        executeSetValuesInternalTests(Runner.FIELD_EMAIL,
                                      String.class,
                                      new String [] {null, ConstantValues.STRING_BLANK, V_EMAIL_1, V_EMAIL_2, I_EMAIL_1, I_EMAIL_2, I_EMAIL_3, I_EMAIL_4, I_EMAIL_5},
                                      new String [] {});

        executeSetValuesInternalTests(Runner.FIELD_DATE_OF_BIRTH,
                                      Date.class,
                                      new String [] {null, ConstantValues.STRING_BLANK, V_DOB_1, V_DOB_2},
                                      new String [] {STRING_FOO, I_DOB_1, I_DOB_2, I_DOB_3});

        executeSetValuesInternalTests(Runner.FIELD_GENDER,
                                      String.class,
                                      new String [] {null, ConstantValues.STRING_BLANK, V_GENDER_1, V_GENDER_2, I_GENDER_1, I_GENDER_2},
                                      new String [] {});

    }

    public void testValidateValues() {
        super.testValidateValues();

        executeValidateValuesTests(Runner.FIELD_NAME,
                                   new String [] {V_NAME_1, V_NAME_2},
                                   new String [] {null, ConstantValues.STRING_BLANK, I_NAME_1});

        executeValidateValuesTests(Runner.FIELD_EMAIL,
                                   new String [] {null, ConstantValues.STRING_BLANK, V_EMAIL_1, V_EMAIL_2},
                                   new String [] {I_EMAIL_1, I_EMAIL_2, I_EMAIL_3, I_EMAIL_4, I_EMAIL_5});

        executeValidateValuesTests(Runner.FIELD_DATE_OF_BIRTH,
                                   new String [] {null, ConstantValues.STRING_BLANK, V_DOB_1, V_DOB_2},
                                   new String [] {I_DOB_1, I_DOB_2, I_DOB_3, STRING_FOO});

        executeValidateValuesTests(Runner.FIELD_GENDER,
                                   new String [] {null, ConstantValues.STRING_BLANK, V_GENDER_1, V_GENDER_2},
                                   new String [] {STRING_FOO, I_GENDER_2, I_GENDER_2});
    }

    protected String getBOType() {
        return Runner.CANONICAL_ID;
    }

    protected DTO getValidDTO() {
        DTO values = getNewDTO();
        values.setValue(Runner.FIELD_RUNNER_ID, V_RUNNER_ID_1);
        values.setValue(Runner.FIELD_NAME, V_NAME_1);
        return values;
    }

    protected String getDTOCanonicalId() {
        return Runner.CANONICAL_ID;
    }

}

⌨️ 快捷键说明

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