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;
018:
019: import java.util.Map;
020: import java.util.HashMap;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025: import junit.textui.TestRunner;
026:
027: /**
028: * Unit tests {@link org.apache.commons.scxml.TriggerEvent}.
029: */
030: public class TriggerEventTest extends TestCase {
031: /**
032: * Construct a new instance of TriggerEventTest with the specified name
033: */
034: public TriggerEventTest(String name) {
035: super (name);
036: }
037:
038: public static Test suite() {
039: TestSuite suite = new TestSuite(TriggerEventTest.class);
040: suite.setName("TriggerEvent Tests");
041: return suite;
042: }
043:
044: // Test data
045: private Map payloadData;
046: private Object payload1, payload2;
047: private TriggerEvent te1, te2, te3, te4, te5, te6, te7;
048:
049: /**
050: * Set up instance variables required by this test case.
051: */
052: public void setUp() {
053: payloadData = new HashMap();
054: payloadData.put("property1", "value1");
055: payload1 = payloadData;
056: payload2 = new Object();
057: te1 = new TriggerEvent("name1", TriggerEvent.CHANGE_EVENT,
058: payload1);
059: te2 = new TriggerEvent("name1", TriggerEvent.CHANGE_EVENT,
060: payload1);
061: te3 = new TriggerEvent("name2", TriggerEvent.CALL_EVENT,
062: payload2);
063: te4 = new TriggerEvent("name2", TriggerEvent.CALL_EVENT,
064: payload2);
065: te5 = new TriggerEvent("name3", TriggerEvent.SIGNAL_EVENT);
066: te6 = new TriggerEvent("name3", TriggerEvent.SIGNAL_EVENT);
067: te7 = new TriggerEvent("name3", TriggerEvent.TIME_EVENT);
068: }
069:
070: /**
071: * Tear down instance variables required by this test case.
072: */
073: public void tearDown() {
074: payloadData.clear();
075: payloadData = null;
076: payload1 = payload2 = null;
077: te1 = te2 = te3 = te4 = te5 = te6 = te7 = null;
078: }
079:
080: /**
081: * Test the implementation
082: */
083: public void testTriggerEventGetters() {
084: assertEquals(te1.getName(), "name1");
085: assertEquals(te2.getType(), 2);
086: assertNull(te7.getPayload());
087: }
088:
089: public void testTriggerEventEquals() {
090: assertTrue(te1.equals(te2));
091: assertTrue(te3.equals(te4));
092: assertTrue(te5.equals(te6));
093: assertFalse(te1.equals(te4));
094: assertFalse(te7.equals(null));
095: }
096:
097: public void testTriggerEventToString() {
098: assertEquals("TriggerEvent{name=name3,type=4}", te7.toString());
099: assertEquals("TriggerEvent{name=name1,type=2,payload="
100: + "{property1=value1}}", te2.toString());
101: }
102:
103: public void testTriggerEventHashCode() {
104: assertEquals("TriggerEvent{name=name3,type=4}".hashCode(), te7
105: .hashCode());
106: assertEquals("TriggerEvent{name=name3,type=3}".hashCode(), te5
107: .hashCode());
108: }
109:
110: public static void main(String args[]) {
111: TestRunner.run(suite());
112: }
113: }
|