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

File CancelableEventTest.java

 

Code metrics

0
65
8
3
183
112
8
0.12
8.12
2.67
1

Classes

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