    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.env;
    18
    19  import java.net.URL;
    20
    21  import junit.framework.Test;
    22  import junit.framework.TestCase;
    23  import junit.framework.TestSuite;
    24  import junit.textui.TestRunner;
    25
    26  /***
    27   * Unit tests {@link org.apache.commons.scxml.env.AbstractStateMachine}.
    28   */
    29  public class AbstractStateMachineTest extends TestCase {
    30
    31      /***
    32       * Construct a new instance of AbstractStateMachineTest with the specified name
    33       */
    34      public AbstractStateMachineTest(String name) {
    35          super(name);
    36      }
    37
    38      public void testMoreThanOneScxmlDocument() throws Exception {
    39          URL fooScxmlDocument = getClass().getResource("foo.xml");
    40          URL barScxmlDocument = getClass().getResource("bar.xml");
    41
    42          Foo f = new Foo(fooScxmlDocument);
    43          Bar b = new Bar(barScxmlDocument);
    44
    45          assertTrue(f.fooCalled());
    46          assertTrue(b.barCalled());
    47      }
    48
    49      private class Foo extends AbstractStateMachine {
    50
    51          private boolean fooCalled;
    52
    53          public Foo(final URL scxmlDocument) {
    54              super(scxmlDocument);
    55          }
    56
    57          public void foo() {
    58              fooCalled = true;
    59          }
    60
    61          public boolean fooCalled() {
    62              return fooCalled;
    63          }
    64      }
    65
    66      private class Bar extends AbstractStateMachine {
    67
    68          private boolean barCalled;
    69
    70          public Bar(final URL scxmlDocument) {
    71              super(scxmlDocument);
    72          }
    73
    74          public void bar() {
    75              barCalled = true;
    76          }
    77
    78          public boolean barCalled() {
    79              return barCalled;
    80          }
    81      }
    82
    83      public static Test suite() {
    84          TestSuite suite = new TestSuite(AbstractStateMachineTest.class);
    85          suite.setName("AbstractStateMachine Tests");
    86          return suite;
    87      }
    88
    89      public static void main(String args[]) {
    90          TestRunner.run(suite());
    91      }
    92  }