?? propertytest.java
字號:
package piytest;
import junit.framework.*;
import java.awt.Color;
import piy.Property;
import piytest.support.GenericPropertyHolder;
/**
* Test set for the Property class.
* @author David Vivash
* @version 1.0, 26/04/01
*/
public class PropertyTest extends TestCase
{
private GenericPropertyHolder holder;
public PropertyTest(String name) {
super(name);
}
public static Test suite() {
return new TestSuite(PropertyTest.class);
}
public void setUp()
{
holder = new GenericPropertyHolder();
}
/**
* Check that setting a property value is reflected in the underlying
* property holder class.
*/
public void testSetValue() {
Property stringProperty = new Property(holder, "StringValue", String.class);
stringProperty.setValue("NewValue"); //set value indirectly through the property
assert(holder.getStringValue().equals("NewValue"));
Color colorValue = new Color(100,200,100);
Property colorProperty = new Property(holder, "ColorValue", Color.class);
colorProperty.setValue(colorValue); //set value indirectly through the property
assert(holder.getColorValue() == colorValue);
}
/**
* Check that the property get method returns the same value as that stored
* in the underlying property holder.
*/
public void testGetValue() {
Property stringProperty = new Property(holder, "StringValue", String.class);
holder.setStringValue("NewValue"); //set value directly through the holder
assert(((String)stringProperty.getValue()).equals("NewValue"));
Color colorValue = new Color(100,200,100);
Property colorProperty = new Property(holder, "ColorValue", Color.class);
holder.setColorValue(colorValue); //set value directly through the holder
assert(colorProperty.getValue() == colorValue);
}
/**
* Combines the set and get methods of a property to ensure that they
* work correctly together.
*/
public void testSetGetValue() {
Property stringProperty = new Property(holder, "StringValue", String.class);
stringProperty.setValue("NewValue");
assert(((String)stringProperty.getValue()).equals("NewValue"));
Color colorValue = new Color(100,200,100);
Property colorProperty = new Property(holder, "ColorValue", Color.class);
colorProperty.setValue(colorValue);
assert(colorProperty.getValue() == colorValue);
}
/**
* Makes sure that setting primitive values through their bound properties
* (inside their relevant wrapper classes) results in the primitive value
* in the holder being set correctly.
*/
public void testPrimitiveSetValue() {
Property booleanProperty = new Property(holder, "BooleanValue", boolean.class);
holder.setBooleanValue(false); //first set to false directly
booleanProperty.setValue(new Boolean(true)); //now set to true indirectly
assert(holder.getBooleanValue() == true);
Property intProperty = new Property(holder, "IntValue", int.class);
holder.setIntValue(27); //first set to some value directly
intProperty.setValue(new Integer(719)); //now set indirectly
assert(holder.getIntValue() == 719);
}
/**
* Makes sure that getting primitive values through their bound properties
* (inside their relevant wrapper classes) results in the primitive value
* in the holder being got correctly.
*/
public void testPrimitiveGetValue() {
Property booleanProperty = new Property(holder, "BooleanValue", boolean.class);
holder.setBooleanValue(true); //set primitive value directly
Boolean valueSet = (Boolean)booleanProperty.getValue();
assert(valueSet.booleanValue() == true);
Property intProperty = new Property(holder, "IntValue", int.class);
holder.setIntValue(9908); //first set to some value directly
Integer intSet = (Integer)intProperty.getValue();
assert(intSet.intValue() == 9908);
}
/**
* Makes sure that setting then getting primitive values through their bound properties
* (inside their relevant wrapper classes) results in the primitive value
* in the holder being got correctly.
*/
public void testPrimitiveSetGet() {
Property booleanProperty = new Property(holder, "BooleanValue", boolean.class);
holder.setBooleanValue(false); //set primitive value directly
booleanProperty.setValue(new Boolean(true)); //now set to true indirectly
Boolean valueSet = (Boolean)booleanProperty.getValue();
assert(valueSet.booleanValue() == true);
Property intProperty = new Property(holder, "IntValue", int.class);
holder.setIntValue(9908); //first set to some value directly
intProperty.setValue(new Integer(719)); //now set indirectly
Integer intSet = (Integer)intProperty.getValue();
assert(intSet.intValue() == 719);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -