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

File CancelableEventTest.java

 

Code metrics

0
65
8
3
177
108
8
0.12
8.12
2.67
1

Classes

Class Line # Actions
CancelableEventTest 27 63 0% 5 0
1.0100%
CancelableEventTest.TestCancelableEvent 29 2 0% 3 0
1.0100%
CancelableEventTest.TestCancelableEvent2 47 0 - 0 0
-1.0 -
 

Contributing tests

This file is covered by 5 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.observation.event;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24    import org.xwiki.observation.event.filter.EventFilter;
25    import org.xwiki.observation.event.filter.FixedNameEventFilter;
26   
 
27    public class CancelableEventTest
28    {
 
29    static class TestCancelableEvent extends AbstractCancelableEvent
30    {
 
31  5 toggle public TestCancelableEvent()
32    {
33   
34    }
35   
 
36  16 toggle public TestCancelableEvent(String name)
37    {
38  16 super(name);
39    }
40   
 
41  16 toggle public TestCancelableEvent(EventFilter eventFilter)
42    {
43  16 super(eventFilter);
44    }
45    }
46   
 
47    static class TestCancelableEvent2 extends AbstractCancelableEvent
48    {
49   
50    }
51   
52    // Tests
53   
 
54  1 toggle @Test
55    public void testAbstractCancelableEvent()
56    {
57  1 TestCancelableEvent event = new TestCancelableEvent();
58   
59    // matches
60   
61  1 Assert.assertTrue(event.matches(event));
62  1 Assert.assertTrue(event.matches(new TestCancelableEvent("name")));
63  1 Assert.assertTrue(event.matches(new TestCancelableEvent(new FixedNameEventFilter("name2"))));
64   
65  1 Assert.assertFalse(event.matches(new TestCancelableEvent2()));
66   
67    // equals
68   
69  1 Assert.assertTrue(event.equals(event));
70  1 Assert.assertTrue(event.equals(new TestCancelableEvent()));
71   
72  1 Assert.assertFalse(event.equals(new TestCancelableEvent("name")));
73  1 Assert.assertFalse(event.equals(new TestCancelableEvent(new FixedNameEventFilter("name"))));
74  1 Assert.assertFalse(event.equals(new TestCancelableEvent2()));
75   
76    // hashcode
77   
78  1 Assert.assertEquals(event.hashCode(), new TestCancelableEvent().hashCode());
79  1 Assert.assertFalse(event.equals(new TestCancelableEvent2()));
80   
81  1 Assert.assertNotEquals(event.hashCode(), new TestCancelableEvent("name").hashCode());
82  1 Assert.assertNotEquals(event.hashCode(), new TestCancelableEvent(new FixedNameEventFilter("name")).hashCode());
83    }
84   
 
85  1 toggle @Test
86    public void testAbstractCancelableEventEventFilter()
87    {
88  1 TestCancelableEvent event = new TestCancelableEvent(new FixedNameEventFilter("name"));
89   
90    // matches
91   
92  1 Assert.assertTrue(event.matches(event));
93  1 Assert.assertTrue(event.matches(new TestCancelableEvent("name")));
94  1 Assert.assertTrue(event.matches(new TestCancelableEvent(new FixedNameEventFilter("name"))));
95   
96  1 Assert.assertFalse(event.matches(new TestCancelableEvent("name2")));
97  1 Assert.assertFalse(event.matches(new TestCancelableEvent(new FixedNameEventFilter("name2"))));
98  1 Assert.assertFalse(event.matches(new TestCancelableEvent2()));
99   
100    // equals
101   
102  1 Assert.assertTrue(event.equals(event));
103  1 Assert.assertTrue(event.equals(new TestCancelableEvent("name")));
104  1 Assert.assertTrue(event.equals(new TestCancelableEvent(new FixedNameEventFilter("name"))));
105   
106  1 Assert.assertFalse(event.equals(null));
107  1 Assert.assertFalse(event.equals(new TestCancelableEvent("name2")));
108  1 Assert.assertFalse(event.equals(new TestCancelableEvent(new FixedNameEventFilter("name2"))));
109  1 Assert.assertFalse(event.equals(new TestCancelableEvent2()));
110   
111    // hashcode
112   
113  1 Assert.assertEquals(event.hashCode(), new TestCancelableEvent("name").hashCode());
114  1 Assert.assertEquals(event.hashCode(), new TestCancelableEvent(new FixedNameEventFilter("name")).hashCode());
115   
116  1 Assert.assertNotEquals(event.hashCode(), new TestCancelableEvent("name2").hashCode());
117  1 Assert.assertNotEquals(event.hashCode(), new TestCancelableEvent(new FixedNameEventFilter("name2")).hashCode());
118    }
119   
 
120  1 toggle @Test
121    public void testAbstractCancelableEventString()
122    {
123  1 TestCancelableEvent event = new TestCancelableEvent("name");
124   
125    // matches
126   
127  1 Assert.assertTrue(event.matches(event));
128  1 Assert.assertTrue(event.matches(new TestCancelableEvent("name")));
129  1 Assert.assertTrue(event.matches(new TestCancelableEvent(new FixedNameEventFilter("name"))));
130   
131  1 Assert.assertFalse(event.matches(new TestCancelableEvent("name2")));
132  1 Assert.assertFalse(event.matches(new TestCancelableEvent(new FixedNameEventFilter("name2"))));
133  1 Assert.assertFalse(event.matches(new TestCancelableEvent2()));
134   
135    // equals
136   
137  1 Assert.assertTrue(event.equals(event));
138  1 Assert.assertTrue(event.equals(new TestCancelableEvent("name")));
139  1 Assert.assertTrue(event.equals(new TestCancelableEvent(new FixedNameEventFilter("name"))));
140   
141  1 Assert.assertFalse(event.equals(null));
142  1 Assert.assertFalse(event.equals(new TestCancelableEvent("name2")));
143  1 Assert.assertFalse(event.equals(new TestCancelableEvent(new FixedNameEventFilter("name2"))));
144  1 Assert.assertFalse(event.equals(new TestCancelableEvent2()));
145   
146    // hashcode
147   
148  1 Assert.assertEquals(event.hashCode(), new TestCancelableEvent("name").hashCode());
149  1 Assert.assertEquals(event.hashCode(), new TestCancelableEvent(new FixedNameEventFilter("name")).hashCode());
150   
151  1 Assert.assertNotEquals(event.hashCode(), new TestCancelableEvent("name2").hashCode());
152  1 Assert.assertNotEquals(event.hashCode(), new TestCancelableEvent(new FixedNameEventFilter("name2")).hashCode());
153    }
154   
 
155  1 toggle @Test
156    public void testCancel()
157    {
158  1 CancelableEvent event = new TestCancelableEvent();
159  1 Assert.assertFalse(event.isCanceled());
160  1 Assert.assertNull(event.getReason());
161  1 event.cancel();
162  1 Assert.assertTrue(event.isCanceled());
163  1 Assert.assertNull(event.getReason());
164    }
165   
 
166  1 toggle @Test
167    public void testCancelWithReason()
168    {
169  1 String reason = "Tralala";
170  1 CancelableEvent event = new TestCancelableEvent();
171  1 Assert.assertFalse(event.isCanceled());
172  1 Assert.assertNull(event.getReason());
173  1 event.cancel(reason);
174  1 Assert.assertTrue(event.isCanceled());
175  1 Assert.assertEquals(reason, event.getReason());
176    }
177    }