1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.bridge

File ActionExecutedEventTest.java

 

Code metrics

0
50
26
1
227
167
26
0.52
1.92
26
1

Classes

Class Line # Actions
ActionExecutedEventTest 33 50 0% 26 0
1.0100%
 

Contributing tests

This file is covered by 26 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.bridge;
21   
22    import org.junit.Assert;
23   
24    import org.junit.Test;
25    import org.xwiki.bridge.event.ActionExecutedEvent;
26    import org.xwiki.bridge.event.ActionExecutingEvent;
27   
28    /**
29    * Tests for the {@link ActionExecutedEvent} event type.
30    *
31    * @version $Id: 8d5e81d0f7d18d75d3c025263dbf62834e1814c9 $
32    */
 
33    public class ActionExecutedEventTest
34    {
35    // Tests for constructors
36   
 
37  1 toggle @Test
38    public void testDefaultConstructor()
39    {
40  1 ActionExecutedEvent event = new ActionExecutedEvent();
41  1 Assert.assertNull("A default action was used!", event.getActionName());
42    }
43   
 
44  1 toggle @Test
45    public void testConstructorWithActionName()
46    {
47  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
48  1 Assert.assertEquals("Action name was lost!", "something", event.getActionName());
49    }
50   
51    // Tests for matches(Object)
52   
 
53  1 toggle @Test
54    public void testMatchesSameObject()
55    {
56  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
57  1 Assert.assertTrue("Same object wasn't matched!", event.matches(event));
58    }
59   
 
60  1 toggle @Test
61    public void testMatchesSameAction()
62    {
63  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
64  1 Assert.assertTrue("Same action wasn't matched!", event.matches(new ActionExecutedEvent("something")));
65    }
66   
 
67  1 toggle @Test
68    public void testDoesntMatchNull()
69    {
70  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
71  1 Assert.assertFalse("null was matched!", event.matches(null));
72    }
73   
 
74  1 toggle @Test
75    public void testDoesntMatchWildcardAction()
76    {
77  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
78  1 Assert.assertFalse("Wildcard action was matched!", event.matches(new ActionExecutedEvent()));
79    }
80   
 
81  1 toggle @Test
82    public void testDoesntMatchDifferentAction()
83    {
84  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
85  1 Assert.assertFalse("A different action was matched!", event.matches(new ActionExecutedEvent("else")));
86    }
87   
 
88  1 toggle @Test
89    public void testDoesntMatchDifferentCaseAction()
90    {
91  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
92  1 Assert.assertFalse("Action matching was case insensitive!",
93    event.matches(new ActionExecutedEvent("SomeThing")));
94    }
95   
 
96  1 toggle @Test
97    public void testDoesntMatchDifferentTypeOfAction()
98    {
99  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
100  1 Assert.assertFalse("A different type of action was matched!",
101    event.matches(new ActionExecutingEvent("something")));
102    }
103   
 
104  1 toggle @Test
105    public void testWildcardActionMatchesAll()
106    {
107  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
108  1 Assert.assertTrue("Wildcard action didn't match!", new ActionExecutedEvent().matches(event));
109  1 Assert.assertTrue("Wildcard action didn't match another wildcard action!",
110    new ActionExecutedEvent().matches(new ActionExecutedEvent()));
111    }
112   
 
113  1 toggle @Test
114    public void testWildcardActionDoesnMatchNull()
115    {
116  1 Assert.assertFalse("Wildcard action matched null!", new ActionExecutedEvent().matches(null));
117    }
118   
 
119  1 toggle @Test
120    public void testEmptyActionDoesntMatch()
121    {
122  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
123  1 Assert.assertFalse("Empty action behaves as wildcard!", new ActionExecutedEvent("").matches(event));
124    }
125   
126    // Tests for equals(Object)
127   
 
128  1 toggle @Test
129    public void testEqualsSameObject()
130    {
131  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
132  1 Assert.assertTrue("Same object wasn't equal!", event.equals(event));
133    }
134   
 
135  1 toggle @Test
136    public void testEqualsSameAction()
137    {
138  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
139  1 Assert.assertTrue("Same action wasn't equal!", event.equals(new ActionExecutedEvent("something")));
140    }
141   
 
142  1 toggle @Test
143    public void testEqualsWithNull()
144    {
145  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
146  1 Assert.assertFalse("null was equal!", event.equals(null));
147    }
148   
 
149  1 toggle @Test
150    public void testDoesntEqualWildcardAction()
151    {
152  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
153  1 Assert.assertFalse("Wildcard action was equal!", event.equals(new ActionExecutedEvent()));
154    }
155   
 
156  1 toggle @Test
157    public void testDoesntEqualDifferentAction()
158    {
159  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
160  1 Assert.assertFalse("A different action was equal!", event.equals(new ActionExecutedEvent("else")));
161    }
162   
 
163  1 toggle @Test
164    public void testDoesntEqualDifferentCaseAction()
165    {
166  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
167  1 Assert.assertFalse("Action equals comparison was case insensitive!",
168    event.equals(new ActionExecutedEvent("SomeThing")));
169    }
170   
 
171  1 toggle @Test
172    public void testDoesntEqualDifferentTypeOfAction()
173    {
174  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
175  1 Assert.assertFalse("Same object isn't matched!", event.equals(new ActionExecutingEvent("something")));
176    }
177   
 
178  1 toggle @Test
179    public void testWildcardActionDoesntEqualOtherActions()
180    {
181  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
182  1 Assert.assertFalse("Wildcard action equals another action!", new ActionExecutedEvent().equals(event));
183    }
184   
 
185  1 toggle @Test
186    public void testWildcardActionDoesntEqualEmptyAction()
187    {
188  1 ActionExecutedEvent event = new ActionExecutedEvent("");
189  1 Assert.assertFalse("Wildcard action equals another action!", new ActionExecutedEvent().equals(event));
190    }
191   
 
192  1 toggle @Test
193    public void testWildcardActionEqualsWildcardAction()
194    {
195  1 Assert.assertTrue("Wildcard action isn't equal to another wildcard action",
196    new ActionExecutedEvent().equals(new ActionExecutedEvent()));
197    }
198   
 
199  1 toggle @Test
200    public void testWildcardActionDoesntEqualNull()
201    {
202  1 Assert.assertFalse("Wildcard action equals null!", new ActionExecutedEvent().equals(null));
203    }
204   
205    // Tests for hashCode()
206   
 
207  1 toggle @Test
208    public void testHashCode()
209    {
210  1 ActionExecutedEvent event = new ActionExecutedEvent("something");
211  1 Assert.assertTrue("Hashcode was zero!", event.hashCode() != 0);
212    }
213   
 
214  1 toggle @Test
215    public void testHashCodeWithEmptyAction()
216    {
217  1 ActionExecutedEvent event = new ActionExecutedEvent("");
218  1 Assert.assertTrue("Hashcode for empty string action wasn't zero!", event.hashCode() == 0);
219    }
220   
 
221  1 toggle @Test
222    public void testHashCodeForWildcardAction()
223    {
224  1 ActionExecutedEvent event = new ActionExecutedEvent();
225  1 Assert.assertTrue("Hashcode for wildcard action wasn't zero!", event.hashCode() == 0);
226    }
227    }