📄 valuebeantestcase.java
字号:
package net.sf.irunninglog.servlet.formbean;
import java.lang.reflect.Method;
import net.sf.irunninglog.util.ConstantValues;
import net.sf.irunninglog.util.DTO;
public abstract class ValueBeanTestCase extends FormBeanTestCase {
protected ValueBean bean;
public ValueBeanTestCase(String name) {
super(name);
}
public void setUp() {
bean = newValueBean();
}
protected abstract ValueBean newValueBean();
protected abstract String getValueBeanType();
public void testGetValues() {
DTO values = bean.getValues();
assertNotNull(values);
assertEquals(getValueBeanType(), values.getCanonicalId());
}
public void testSetValues() {
try{
bean.setValues(null);
failTest();
} catch (NullPointerException ex) {
assertTrue(true);
}
bean.setValues(new DTO());
assertTrue(true);
}
public void testFields() { }
public void testReset() {
super.testReset();
}
public void testGetAsYesNo() {
assertEquals(ConstantValues.STRING_YES, bean.getAsYesNo("true"));
assertEquals(ConstantValues.STRING_YES, bean.getAsYesNo("TRUE"));
assertEquals(ConstantValues.STRING_YES, bean.getAsYesNo("T"));
assertEquals(ConstantValues.STRING_YES, bean.getAsYesNo("1"));
assertEquals(ConstantValues.STRING_YES, bean.getAsYesNo("trUE"));
assertEquals(ConstantValues.STRING_YES, bean.getAsYesNo("yes"));
assertEquals(ConstantValues.STRING_YES, bean.getAsYesNo("YeS"));
assertEquals(ConstantValues.STRING_NO, bean.getAsYesNo(null));
assertEquals(ConstantValues.STRING_NO, bean.getAsYesNo(ConstantValues.STRING_BLANK));
assertEquals(ConstantValues.STRING_NO, bean.getAsYesNo(STRING_FOO));
assertEquals(ConstantValues.STRING_NO, bean.getAsYesNo("false"));
assertEquals(ConstantValues.STRING_NO, bean.getAsYesNo("faLSe"));
assertEquals(ConstantValues.STRING_NO, bean.getAsYesNo("no"));
}
public void testGetValueOrBlank() {
assertEquals(ConstantValues.STRING_BLANK, bean.getValueOrBlank(null));
assertEquals(ConstantValues.STRING_BLANK, bean.getValueOrBlank(ConstantValues.STRING_BLANK));
assertEquals(ConstantValues.STRING_BLANK, bean.getValueOrBlank(" "));
assertEquals(STRING_FOO, bean.getValueOrBlank(STRING_FOO));
}
protected void doFieldTests(String fieldName) {
String firstLetter = fieldName.substring(0,1).toUpperCase();
String getterName = "get" + firstLetter + fieldName.substring(1, fieldName.length());
String setterName = "set" + firstLetter + fieldName.substring(1, fieldName.length());
String [] testVals = new String [] {null, ConstantValues.STRING_BLANK, " ", STRING_FOO};
try {
Method getter = bean.getClass().getMethod(getterName, null);
Method setter = bean.getClass().getMethod(setterName, new Class [] {String.class});
for (int i=0; i<testVals.length; i++) {
setter.invoke(bean, new Object [] {testVals[i]});
assertEquals(testVals[i], getter.invoke(bean, null));
}
} catch (Exception ex) {
LOG.error("Test Failed", ex);
failTest();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -