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 */ 017package org.apache.commons.scxml2; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.junit.After; 023import org.junit.Assert; 024import org.junit.Before; 025import org.junit.Test; 026 027/** 028 * Unit tests {@link org.apache.commons.scxml2.TriggerEvent}. 029 */ 030public class TriggerEventTest { 031 032 // Test data 033 private Map<String, String> payloadData; 034 private Object payload1, payload2; 035 private TriggerEvent te1, te2, te3, te4, te5, te6, te7; 036 037 /** 038 * Set up instance variables required by this test case. 039 */ 040 @Before 041 public void setUp() { 042 payloadData = new HashMap<String, String>(); 043 payloadData.put("property1", "value1"); 044 payload1 = payloadData; 045 payload2 = new Object(); 046 te1 = new TriggerEvent("name1", TriggerEvent.CHANGE_EVENT, payload1); 047 te2 = new TriggerEvent("name1", TriggerEvent.CHANGE_EVENT, payload1); 048 te3 = new TriggerEvent("name2", TriggerEvent.CALL_EVENT, payload2); 049 te4 = new TriggerEvent("name2", TriggerEvent.CALL_EVENT, payload2); 050 te5 = new TriggerEvent("name3", TriggerEvent.SIGNAL_EVENT); 051 te6 = new TriggerEvent("name3", TriggerEvent.SIGNAL_EVENT); 052 te7 = new TriggerEvent("name3", TriggerEvent.TIME_EVENT); 053 } 054 055 /** 056 * Tear down instance variables required by this test case. 057 */ 058 @After 059 public void tearDown() { 060 payloadData.clear(); 061 payloadData = null; 062 payload1 = payload2 = null; 063 te1 = te2 = te3 = te4 = te5 = te6 = te7 = null; 064 } 065 066 /** 067 * Test the implementation 068 */ 069 @Test 070 public void testTriggerEventGetters() { 071 Assert.assertEquals("name1", te1.getName()); 072 Assert.assertEquals(2, te2.getType()); 073 Assert.assertNull(te7.getPayload()); 074 } 075 076 @Test 077 public void testTriggerEventEquals() { 078 Assert.assertEquals(te1, te2); 079 Assert.assertEquals(te3, te4); 080 Assert.assertEquals(te5, te6); 081 Assert.assertNotEquals(te1, te4); 082 Assert.assertNotNull(te7); 083 } 084 085 @Test 086 public void testTriggerEventToString() { 087 Assert.assertEquals("TriggerEvent{name=name3,type=4}", te7.toString()); 088 Assert.assertEquals("TriggerEvent{name=name1,type=2,payload=" 089 + "{property1=value1}}", te2.toString()); 090 } 091 092 @Test 093 public void testTriggerEventHashCode() { 094 Assert.assertEquals("TriggerEvent{name=name3,type=4}".hashCode(), 095 te7.hashCode()); 096 Assert.assertEquals("TriggerEvent{name=name3,type=3}".hashCode(), 097 te5.hashCode()); 098 } 099} 100