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

📄 fixedpropertytest.java

📁 PIY(Program It Yourself)是一个基于Java的应用程序开发环境
💻 JAVA
字号:
package piytest;

import junit.framework.*;
import piy.*;
import piytest.support.GenericPropertyHolder;
import java.awt.Color;

/**
* Test set for the FixedProperty class.
* @author David Vivash
* @version 1.0, 26/04/01
*/
public class FixedPropertyTest extends TestCase
{
	private FixedProperty fixedString, fixedInt, fixedColor;
	private GenericPropertyHolder holder = null;


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

	public static Test suite() {
		return new TestSuite(FixedPropertyTest.class);
	}

	public void setUp() {
		fixedString = new FixedProperty("Text", String.class);
		fixedInt	= new FixedProperty(new Integer(999), int.class); //note the type specifies a primitive
		fixedColor	= new FixedProperty(new Color(1, 2, 3), Color.class);	

		holder = new GenericPropertyHolder();
	}

	public void testSetValue() {
		fixedString.setValue(new Color(10,20,30));
		
		//setting the value doesn't change the asserted type
		assert(fixedString.getType() == String.class);

		//the "actual" type has been recorded as a Color nevertheless
		assert(fixedString.getValue().getClass() == Color.class);

		//the property has been bound to an fresh property - it is not linked
		//to an external one.
		assert(fixedString.getInternal() == true);
	}
	
	public void testSetProperty() {
		Property colorProperty = new Property(holder, "ColorValue", Color.class);
		fixedColor.setProperty(colorProperty);

		assert(fixedColor.getInternal() == false);

		//now the fixed property is bound to our colorProperty, check that changes
		//in the colorProperty are reflected in the fixedColor
		colorProperty.setValue(new Color(100,50, 25));
		assert(fixedColor.getActualValue() == colorProperty.getValue());

		//check for primitives
		Property intProperty = new Property(holder, "IntValue", int.class);
		fixedInt.setProperty(intProperty);
		
		assert(fixedInt.getInternal() == false);
		
		intProperty.setValue(new Integer(-20)); //since this call goes through reflection, it will be unwrapped to the primitive

		assert(((Integer)fixedInt.getActualValue()).intValue() == -20);
		
	}


}

⌨️ 快捷键说明

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