View Javadoc
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.scxml2;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.junit.After;
23  import org.junit.Assert;
24  import org.junit.Before;
25  import org.junit.Test;
26  
27  /**
28   * Unit tests {@link org.apache.commons.scxml2.TriggerEvent}.
29   */
30  public class TriggerEventTest {
31  
32      // Test data
33      private Map<String, String> payloadData;
34      private Object payload1, payload2;
35      private TriggerEvent te1, te2, te3, te4, te5, te6, te7;
36  
37      /**
38       * Set up instance variables required by this test case.
39       */
40      @Before
41      public void setUp() {
42          payloadData = new HashMap<String, String>();
43          payloadData.put("property1", "value1");
44          payload1 = payloadData;
45          payload2 = new Object();
46          te1 = new TriggerEvent("name1", TriggerEvent.CHANGE_EVENT, payload1);
47          te2 = new TriggerEvent("name1", TriggerEvent.CHANGE_EVENT, payload1);
48          te3 = new TriggerEvent("name2", TriggerEvent.CALL_EVENT, payload2);
49          te4 = new TriggerEvent("name2", TriggerEvent.CALL_EVENT, payload2);
50          te5 = new TriggerEvent("name3", TriggerEvent.SIGNAL_EVENT);
51          te6 = new TriggerEvent("name3", TriggerEvent.SIGNAL_EVENT);
52          te7 = new TriggerEvent("name3", TriggerEvent.TIME_EVENT);
53      }
54  
55      /**
56       * Tear down instance variables required by this test case.
57       */
58      @After
59      public void tearDown() {
60          payloadData.clear();
61          payloadData = null;
62          payload1 = payload2 = null;
63          te1 = te2 = te3 = te4 = te5 = te6 = te7 = null;
64      }
65  
66      /**
67       * Test the implementation
68       */
69      @Test
70      public void testTriggerEventGetters() {
71          Assert.assertEquals("name1", te1.getName());
72          Assert.assertEquals(2, te2.getType());
73          Assert.assertNull(te7.getPayload());
74      }
75  
76      @Test
77      public void testTriggerEventEquals() {
78          Assert.assertEquals(te1, te2);
79          Assert.assertEquals(te3, te4);
80          Assert.assertEquals(te5, te6);
81          Assert.assertNotEquals(te1, te4);
82          Assert.assertNotNull(te7);
83      }
84  
85      @Test
86      public void testTriggerEventToString() {
87          Assert.assertEquals("TriggerEvent{name=name3,type=4}", te7.toString());
88          Assert.assertEquals("TriggerEvent{name=name1,type=2,payload="
89              + "{property1=value1}}", te2.toString());
90      }
91  
92      @Test
93      public void testTriggerEventHashCode() {
94          Assert.assertEquals("TriggerEvent{name=name3,type=4}".hashCode(),
95              te7.hashCode());
96          Assert.assertEquals("TriggerEvent{name=name3,type=3}".hashCode(),
97              te5.hashCode());
98      }
99  }
100