001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependency;
034:
035: import junit.framework.*;
036:
037: public class TestClassNode extends TestCase {
038: private NodeFactory factory;
039: private ClassNode node;
040:
041: protected void setUp() throws Exception {
042: factory = new NodeFactory();
043: }
044:
045: public void testSwitchClassNodeFromReferencedToConcrete() {
046: node = factory.createClass("a.A", false);
047:
048: assertFalse("Not referenced", node.getPackageNode()
049: .isConfirmed());
050: assertFalse("Not referenced", node.isConfirmed());
051: node.setConfirmed(true);
052: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
053: assertTrue("Not concrete", node.isConfirmed());
054: }
055:
056: public void testSwitchOneClassNodeOutOfTwoFromReferencedToConcrete() {
057: node = factory.createClass("a.A", false);
058: factory.createClass("a.B", false);
059:
060: assertFalse("Not referenced", node.getPackageNode()
061: .isConfirmed());
062: assertFalse("Not referenced", node.isConfirmed());
063: node.setConfirmed(true);
064: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
065: assertTrue("Not concrete", node.isConfirmed());
066: }
067:
068: public void testMakingClassNodeConcreteDoesNotChangeItsFeatures() {
069: node = factory.createClass("a.A", false);
070: factory.createFeature("a.A.a", false);
071:
072: assertFalse("Not referenced", node.getPackageNode()
073: .isConfirmed());
074: assertFalse("Not referenced", node.isConfirmed());
075: assertFalse("Not referenced", ((Node) node.getFeatures()
076: .iterator().next()).isConfirmed());
077: node.setConfirmed(true);
078: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
079: assertTrue("Not concrete", node.isConfirmed());
080: assertFalse("Not referenced", ((Node) node.getFeatures()
081: .iterator().next()).isConfirmed());
082: }
083:
084: public void testSwitchEmptyClassNodeFromConcreteToReferenced() {
085: node = factory.createClass("a.A", true);
086:
087: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
088: assertTrue("Not concrete", node.isConfirmed());
089: node.setConfirmed(false);
090: assertFalse("Not referenced", node.getPackageNode()
091: .isConfirmed());
092: assertFalse("Not referenced", node.isConfirmed());
093: }
094:
095: public void testSwitchOneClassNodeOutOfTwoFromConcreteToReferenced() {
096: node = factory.createClass("a.A", true);
097: factory.createClass("a.B", true);
098:
099: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
100: assertTrue("Not concrete", node.isConfirmed());
101: node.setConfirmed(false);
102: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
103: assertFalse("Not referenced", node.isConfirmed());
104: }
105:
106: public void testSwitchClassNodeWithConcreteFeatureFromConcreteToReferenced() {
107: node = factory.createClass("a.A", true);
108: factory.createFeature("a.A.a", true);
109:
110: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
111: assertTrue("Not concrete", node.isConfirmed());
112: assertTrue("Not concrete", ((Node) node.getFeatures()
113: .iterator().next()).isConfirmed());
114: node.setConfirmed(false);
115: assertFalse("Not referenced", node.getPackageNode()
116: .isConfirmed());
117: assertFalse("Not referenced", node.isConfirmed());
118: assertFalse("Not referenced", ((Node) node.getFeatures()
119: .iterator().next()).isConfirmed());
120: }
121:
122: public void testSwitchClassNodeWithReferencedClassFromConcreteToReferenced() {
123: node = factory.createClass("a.A", true);
124: factory.createFeature("a.A.a", false);
125:
126: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
127: assertTrue("Not concrete", node.isConfirmed());
128: assertFalse("Not referenced", ((Node) node.getFeatures()
129: .iterator().next()).isConfirmed());
130: node.setConfirmed(false);
131: assertFalse("Not referenced", node.getPackageNode()
132: .isConfirmed());
133: assertFalse("Not referenced", node.isConfirmed());
134: assertFalse("Not referenced", ((Node) node.getFeatures()
135: .iterator().next()).isConfirmed());
136: }
137: }
|