1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.bridge

File ActionExecutingEventTest.java

 

Code metrics

0
61
28
1
250
186
28
0.46
2.18
28
1

Classes

Class Line # Actions
ActionExecutingEventTest 33 61 0% 28 0
1.0100%
 

Contributing tests

This file is covered by 28 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 ActionExecutingEvent} event type.
30    *
31    * @version $Id: 5b4bc0b50044abe6a9bc193aa32951bd21278778 $
32    */
 
33    public class ActionExecutingEventTest
34    {
35    // Tests for constructors
36   
 
37  1 toggle @Test
38    public void testDefaultConstructor()
39    {
40  1 ActionExecutingEvent event = new ActionExecutingEvent();
41  1 Assert.assertNull("A default action was used!", event.getActionName());
42  1 Assert.assertFalse("Event was created canceled!", event.isCanceled());
43  1 Assert.assertNull("A cancel reason was initially set!", event.getReason());
44    }
45   
 
46  1 toggle @Test
47    public void testConstructorWithActionName()
48    {
49  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
50  1 Assert.assertEquals("Action name was lost!", "something", event.getActionName());
51  1 Assert.assertFalse("Event was created canceled!", event.isCanceled());
52  1 Assert.assertNull("A cancel reason was initially set!", event.getReason());
53    }
54   
55    // Tests for cancel()
56   
 
57  1 toggle @Test
58    public void testCancel()
59    {
60  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
61  1 Assert.assertFalse("Event was created canceled!", event.isCanceled());
62  1 event.cancel();
63  1 Assert.assertTrue("Event wasn't canceled when requested!", event.isCanceled());
64    }
65   
 
66  1 toggle @Test
67    public void testCancelWithReason()
68    {
69  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
70  1 event.cancel("Testing reason");
71  1 Assert.assertEquals("Cancelling reason was lost!", "Testing reason", event.getReason());
72    }
73   
74    // Tests for matches(Object)
75   
 
76  1 toggle @Test
77    public void testMatchesSameObject()
78    {
79  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
80  1 Assert.assertTrue("Same object wasn't matched!", event.matches(event));
81    }
82   
 
83  1 toggle @Test
84    public void testMatchesSameAction()
85    {
86  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
87  1 Assert.assertTrue("Same action wasn't matched!", event.matches(new ActionExecutingEvent("something")));
88    }
89   
 
90  1 toggle @Test
91    public void testDoesntMatchNull()
92    {
93  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
94  1 Assert.assertFalse("null was matched!", event.matches(null));
95    }
96   
 
97  1 toggle @Test
98    public void testDoesntMatchWildcardAction()
99    {
100  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
101  1 Assert.assertFalse("Wildcard action was matched!", event.matches(new ActionExecutingEvent()));
102    }
103   
 
104  1 toggle @Test
105    public void testDoesntMatchDifferentAction()
106    {
107  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
108  1 Assert.assertFalse("A different action was matched!", event.matches(new ActionExecutingEvent("else")));
109    }
110   
 
111  1 toggle @Test
112    public void testDoesntMatchDifferentCaseAction()
113    {
114  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
115  1 Assert.assertFalse("Action matching was case insensitive!",
116    event.matches(new ActionExecutingEvent("SomeThing")));
117    }
118   
 
119  1 toggle @Test
120    public void testDoesntMatchDifferentTypeOfAction()
121    {
122  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
123  1 Assert.assertFalse("A different type of action was matched!",
124    event.matches(new ActionExecutedEvent("something")));
125    }
126   
 
127  1 toggle @Test
128    public void testWildcardActionMatchesAll()
129    {
130  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
131  1 Assert.assertTrue("Wildcard action didn't match!", new ActionExecutingEvent().matches(event));
132  1 Assert.assertTrue("Wildcard action didn't match another wildcard action!",
133    new ActionExecutingEvent().matches(new ActionExecutingEvent()));
134    }
135   
 
136  1 toggle @Test
137    public void testWildcardActionDoesnMatchNull()
138    {
139  1 Assert.assertFalse("Wildcard action matched null!", new ActionExecutingEvent().matches(null));
140    }
141   
 
142  1 toggle @Test
143    public void testEmptyActionDoesntMatch()
144    {
145  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
146  1 Assert.assertFalse("Empty action behaves as wildcard!", new ActionExecutingEvent("").matches(event));
147    }
148   
149    // Tests for equals(Object)
150   
 
151  1 toggle @Test
152    public void testEqualsSameObject()
153    {
154  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
155  1 Assert.assertTrue("Same object wasn't equal!", event.equals(event));
156    }
157   
 
158  1 toggle @Test
159    public void testEqualsSameAction()
160    {
161  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
162  1 Assert.assertTrue("Same action wasn't equal!", event.equals(new ActionExecutingEvent("something")));
163    }
164   
 
165  1 toggle @Test
166    public void testEqualsWithNull()
167    {
168  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
169  1 Assert.assertFalse("null was equal!", event.equals(null));
170    }
171   
 
172  1 toggle @Test
173    public void testDoesntEqualWildcardAction()
174    {
175  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
176  1 Assert.assertFalse("Wildcard action was equal!", event.equals(new ActionExecutingEvent()));
177    }
178   
 
179  1 toggle @Test
180    public void testDoesntEqualDifferentAction()
181    {
182  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
183  1 Assert.assertFalse("A different action was equal!", event.equals(new ActionExecutingEvent("else")));
184    }
185   
 
186  1 toggle @Test
187    public void testDoesntEqualDifferentCaseAction()
188    {
189  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
190  1 Assert.assertFalse("Action equals comparison was case insensitive!",
191    event.equals(new ActionExecutingEvent("SomeThing")));
192    }
193   
 
194  1 toggle @Test
195    public void testDoesntEqualDifferentTypeOfAction()
196    {
197  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
198  1 Assert.assertFalse("Same object isn't matched!", event.equals(new ActionExecutedEvent("something")));
199    }
200   
 
201  1 toggle @Test
202    public void testWildcardActionDoesntEqualOtherActions()
203    {
204  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
205  1 Assert.assertFalse("Wildcard action equals another action!", new ActionExecutingEvent().equals(event));
206    }
207   
 
208  1 toggle @Test
209    public void testWildcardActionDoesntEqualEmptyAction()
210    {
211  1 ActionExecutingEvent event = new ActionExecutingEvent("");
212  1 Assert.assertFalse("Wildcard action equals another action!", new ActionExecutingEvent().equals(event));
213    }
214   
 
215  1 toggle @Test
216    public void testWildcardActionEqualsWildcardAction()
217    {
218  1 Assert.assertTrue("Wildcard action isn't equal to another wildcard action",
219    new ActionExecutingEvent().equals(new ActionExecutingEvent()));
220    }
221   
 
222  1 toggle @Test
223    public void testWildcardActionDoesntEqualNull()
224    {
225  1 Assert.assertFalse("Wildcard action equals null!", new ActionExecutingEvent().equals(null));
226    }
227   
228    // Tests for hashCode()
229   
 
230  1 toggle @Test
231    public void testHashCode()
232    {
233  1 ActionExecutingEvent event = new ActionExecutingEvent("something");
234  1 Assert.assertTrue("Hashcode was zero!", event.hashCode() != 0);
235    }
236   
 
237  1 toggle @Test
238    public void testHashCodeWithEmptyAction()
239    {
240  1 ActionExecutingEvent event = new ActionExecutingEvent("");
241  1 Assert.assertTrue("Hashcode for empty string action wasn't zero!", event.hashCode() == 0);
242    }
243   
 
244  1 toggle @Test
245    public void testHashCodeForWildcardAction()
246    {
247  1 ActionExecutingEvent event = new ActionExecutingEvent();
248  1 Assert.assertTrue("Hashcode for wildcard action wasn't zero!", event.hashCode() == 0);
249    }
250    }