001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestParticlePropertyModel.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.gui.model;
009:
010: import junit.framework.TestCase;
011:
012: import com.uwyn.rife.gui.model.exceptions.GuiModelException;
013:
014: public class TestParticlePropertyModel extends ParticlePropertyModel {
015: public TestParticlePropertyModel(ParticleModel particleModel,
016: String name) throws GuiModelException {
017: super (particleModel, name);
018: }
019:
020: public static class Test extends TestCase implements
021: ParticleModelListener {
022: private Object mPropertyAdded = null;
023:
024: public Test(String name) {
025: super (name);
026: }
027:
028: public void testInstantiation() {
029: ParticleModel particlemodel_instance = null;
030: ParticlePropertyModel propertymodel_instance = null;
031:
032: particlemodel_instance = new TestParticleModel();
033: assertTrue(particlemodel_instance.addParticleListener(this ));
034: assertNull(mPropertyAdded);
035:
036: try {
037: propertymodel_instance = new TestParticlePropertyModel(
038: particlemodel_instance, "particleproperty1");
039: } catch (GuiModelException e) {
040: assertTrue(e.getMessage(), false);
041: }
042: assertSame(mPropertyAdded, propertymodel_instance);
043: assertNotNull(propertymodel_instance);
044: assertTrue(propertymodel_instance instanceof ParticlePropertyModel);
045: }
046:
047: public void testDifferentButEqualPropertyObjectsCreation() {
048: ParticleModel particlemodel_instance = null;
049: ParticlePropertyModel propertymodel_instance1 = null;
050:
051: particlemodel_instance = new TestParticleModel();
052: assertTrue(particlemodel_instance.addParticleListener(this ));
053: assertNull(mPropertyAdded);
054:
055: try {
056: propertymodel_instance1 = new TestParticlePropertyModel(
057: particlemodel_instance, "particleproperty1");
058: assertSame(mPropertyAdded, propertymodel_instance1);
059: mPropertyAdded = null;
060: new TestParticlePropertyModel(particlemodel_instance,
061: "particleproperty1");
062: fail();
063: } catch (GuiModelException e) {
064: assertTrue(true);
065: }
066: assertNull(mPropertyAdded);
067: }
068:
069: public void testValidName() {
070: ParticleModel particlemodel_instance = null;
071: ParticlePropertyModel propertymodel_instance1 = null;
072: ParticlePropertyModel propertymodel_instance2 = null;
073:
074: particlemodel_instance = new TestParticleModel();
075:
076: try {
077: propertymodel_instance1 = new TestParticlePropertyModel(
078: particlemodel_instance, "particleproperty1");
079: propertymodel_instance2 = new TestParticlePropertyModel(
080: particlemodel_instance, "particleproperty2");
081: } catch (GuiModelException e) {
082: assertTrue(e.getMessage(), false);
083: }
084: assertEquals(propertymodel_instance1
085: .isValidName("particleproperty1"), true);
086: assertEquals(propertymodel_instance1
087: .isValidName("particleproperty2"), false);
088: assertEquals(propertymodel_instance1
089: .isValidName("particleproperty3"), true);
090: assertEquals(propertymodel_instance2
091: .isValidName("particleproperty1"), false);
092: assertEquals(propertymodel_instance2
093: .isValidName("particleproperty2"), true);
094: assertEquals(propertymodel_instance2
095: .isValidName("particleproperty3"), true);
096: }
097:
098: public void testNoInitialDescription() {
099: ParticleModel particlemodel_instance = null;
100: TestParticlePropertyModel propertymodel_instance = null;
101:
102: particlemodel_instance = new TestParticleModel();
103:
104: try {
105: propertymodel_instance = new TestParticlePropertyModel(
106: particlemodel_instance, "particleproperty1");
107: } catch (GuiModelException e) {
108: assertTrue(e.getMessage(), false);
109: }
110:
111: assertNull(propertymodel_instance.getDescription());
112: }
113:
114: public void testSetDescription() {
115: ParticleModel particlemodel_instance = null;
116: TestParticlePropertyModel propertymodel_instance = null;
117:
118: particlemodel_instance = new TestParticleModel();
119:
120: try {
121: propertymodel_instance = new TestParticlePropertyModel(
122: particlemodel_instance, "particleproperty1");
123: } catch (GuiModelException e) {
124: assertTrue(e.getMessage(), false);
125: }
126:
127: propertymodel_instance.setDescription("the description");
128:
129: assertEquals(propertymodel_instance.getDescription(),
130: "the description");
131: }
132:
133: public void parentChanged() {
134: }
135:
136: public void childAdded(ParticleModel child) {
137: }
138:
139: public void childRemoved(ParticleModel child) {
140: }
141:
142: public void propertyAdded(ParticlePropertyModel property) {
143: mPropertyAdded = property;
144: }
145:
146: public void propertyRemoved(ParticlePropertyModel property) {
147: }
148:
149: public void propertyRenamed(ParticlePropertyModel property) {
150: }
151: }
152:
153: private static class TestParticleModel extends ParticleModel {
154: }
155: }
|