001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.scxml.semantics;
018:
019: import org.apache.commons.scxml.model.State;
020: import org.apache.commons.scxml.model.TransitionTarget;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: public class TransitionTargetComparatorTest extends TestCase {
027:
028: public TransitionTargetComparatorTest(String testName) {
029: super (testName);
030: }
031:
032: public static Test suite() {
033: return new TestSuite(TransitionTargetComparatorTest.class);
034: }
035:
036: public static void main(String args[]) {
037: String[] testCaseName = { TransitionTargetComparatorTest.class
038: .getName() };
039: junit.textui.TestRunner.main(testCaseName);
040: }
041:
042: private TransitionTargetComparator comparator;
043:
044: public void setUp() {
045: comparator = new TransitionTargetComparator();
046: }
047:
048: public void testComparatorEquals() {
049: TransitionTarget target = new State();
050:
051: assertEquals(0, comparator.compare(target, target));
052: }
053:
054: public void testComparatorNegative() {
055: TransitionTarget target1 = new State();
056: TransitionTarget target2 = new State();
057:
058: target1.setParent(target2);
059:
060: assertEquals(-1, comparator.compare(target1, target2));
061: }
062:
063: public void testComparatorPositive() {
064: TransitionTarget target1 = new State();
065: TransitionTarget target2 = new State();
066:
067: target2.setParent(target1);
068:
069: assertEquals(1, comparator.compare(target1, target2));
070: }
071:
072: public void testComparatorFirstMoreParents() {
073: TransitionTarget target1 = new State();
074: TransitionTarget parent1 = new State();
075: TransitionTarget parent2 = new State();
076:
077: parent1.setParent(parent2);
078: target1.setParent(parent1);
079:
080: TransitionTarget target2 = new State();
081: TransitionTarget parent3 = new State();
082:
083: target2.setParent(parent3);
084:
085: assertEquals(-1, comparator.compare(target1, target2));
086: }
087:
088: public void testComparatorSecondMoreParents() {
089: TransitionTarget target1 = new State();
090: TransitionTarget parent1 = new State();
091: TransitionTarget parent2 = new State();
092:
093: parent1.setParent(parent2);
094: target1.setParent(parent1);
095:
096: TransitionTarget target2 = new State();
097: TransitionTarget parent3 = new State();
098:
099: target2.setParent(parent3);
100:
101: assertEquals(1, comparator.compare(target2, target1)); // reversed
102: }
103:
104: public void testComparatorSameParents() {
105: TransitionTarget target1 = new State();
106: TransitionTarget parent1 = new State();
107:
108: target1.setParent(parent1);
109:
110: TransitionTarget target2 = new State();
111: TransitionTarget parent2 = new State();
112:
113: target2.setParent(parent2);
114:
115: assertEquals(0, comparator.compare(target1, target2));
116: }
117: }
|