    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.commons.scxml.semantics;
    18
    19  import org.apache.commons.scxml.model.State;
    20  import org.apache.commons.scxml.model.TransitionTarget;
    21
    22  import junit.framework.Test;
    23  import junit.framework.TestCase;
    24  import junit.framework.TestSuite;
    25
    26  public class TransitionTargetComparatorTest extends TestCase {
    27
    28      public TransitionTargetComparatorTest(String testName) {
    29          super(testName);
    30      }
    31
    32      public static Test suite() {
    33          return new TestSuite(TransitionTargetComparatorTest.class);
    34      }
    35
    36      public static void main(String args[]) {
    37          String[] testCaseName = { TransitionTargetComparatorTest.class.getName()};
    38          junit.textui.TestRunner.main(testCaseName);
    39      }
    40
    41      private TransitionTargetComparator comparator;
    42
    43      public void setUp() {
    44          comparator = new TransitionTargetComparator();
    45      }
    46
    47      public void testComparatorEquals() {
    48          TransitionTarget target = new State();
    49
    50          assertEquals(0, comparator.compare(target, target));
    51      }
    52
    53      public void testComparatorNegative() {
    54          TransitionTarget target1 = new State();
    55          TransitionTarget target2 = new State();
    56
    57          target1.setParent(target2);
    58
    59          assertEquals(-1, comparator.compare(target1, target2));
    60      }
    61
    62      public void testComparatorPositive() {
    63          TransitionTarget target1 = new State();
    64          TransitionTarget target2 = new State();
    65
    66          target2.setParent(target1);
    67
    68          assertEquals(1, comparator.compare(target1, target2));
    69      }
    70
    71      public void testComparatorFirstMoreParents() {
    72          TransitionTarget target1 = new State();
    73          TransitionTarget parent1 = new State();
    74          TransitionTarget parent2 = new State();
    75
    76          parent1.setParent(parent2);
    77          target1.setParent(parent1);
    78
    79          TransitionTarget target2 = new State();
    80          TransitionTarget parent3 = new State();
    81
    82          target2.setParent(parent3);
    83
    84          assertEquals(-1, comparator.compare(target1, target2));
    85      }
    86
    87      public void testComparatorSecondMoreParents() {
    88          TransitionTarget target1 = new State();
    89          TransitionTarget parent1 = new State();
    90          TransitionTarget parent2 = new State();
    91
    92          parent1.setParent(parent2);
    93          target1.setParent(parent1);
    94
    95          TransitionTarget target2 = new State();
    96          TransitionTarget parent3 = new State();
    97
    98          target2.setParent(parent3);
    99
    100         assertEquals(1, comparator.compare(target2, target1)); // reversed
    101     }
    102
    103     public void testComparatorSameParents() {
    104         TransitionTarget target1 = new State();
    105         TransitionTarget parent1 = new State();
    106
    107         target1.setParent(parent1);
    108
    109         TransitionTarget target2 = new State();
    110         TransitionTarget parent2 = new State();
    111
    112         target2.setParent(parent2);
    113
    114         assertEquals(0, comparator.compare(target1, target2));
    115     }
    116 }