    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
    20  import junit.framework.Test;
    21  import junit.framework.TestCase;
    22  import junit.framework.TestSuite;
    23
    24  public class StopWatchTest extends TestCase {
    25
    26      public StopWatchTest(String testName) {
    27          super(testName);
    28      }
    29
    30      public static Test suite() {
    31          return new TestSuite(StopWatchTest.class);
    32      }
    33
    34      public static void main(String args[]) {
    35          String[] testCaseName = { StopWatchTest.class.getName()};
    36          junit.textui.TestRunner.main(testCaseName);
    37      }
    38
    39      private StopWatch stopWatch;
    40
    41      /***
    42       * Set up instance variables required by this test case.
    43       */
    44      public void setUp() {
    45          stopWatch = new StopWatch();
    46      }
    47
    48      /***
    49       * Tear down instance variables required by this test case.
    50       */
    51      public void tearDown() {
    52          stopWatch = null;
    53      }
    54
    55      public void testStopWatch() {
    56          assertEquals("reset", stopWatch.getCurrentState());
    57          stopWatch.fireEvent(StopWatch.EVENT_START);
    58          assertEquals("running", stopWatch.getCurrentState());
    59          stopWatch.fireEvent(StopWatch.EVENT_SPLIT);
    60          assertEquals("paused", stopWatch.getCurrentState());
    61          stopWatch.fireEvent(StopWatch.EVENT_UNSPLIT);
    62          assertEquals("running", stopWatch.getCurrentState());
    63          stopWatch.fireEvent(StopWatch.EVENT_STOP);
    64          assertEquals("stopped", stopWatch.getCurrentState());
    65          stopWatch.fireEvent(StopWatch.EVENT_RESET);
    66          assertEquals("reset", stopWatch.getCurrentState());
    67      }
    68
    69  }
    70