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

File EventGroupTest.java

 

Code metrics

0
134
10
1
242
188
10
0.07
13.4
10
1

Classes

Class Line # Actions
EventGroupTest 39 134 0% 10 1
0.993055699.3%
 

Contributing tests

This file is covered by 9 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.eventstream;
21   
22    import java.util.ArrayList;
23    import java.util.HashSet;
24    import java.util.List;
25    import java.util.Set;
26   
27    import org.junit.Assert;
28   
29    import org.junit.Before;
30    import org.junit.Test;
31    import org.xwiki.eventstream.Event.Importance;
32    import org.xwiki.eventstream.internal.DefaultEvent;
33   
34    /**
35    * Tests for the {@link EventGroup event group}.
36    *
37    * @version $Id: ea69f6cb38050cbbe7958d83095fa2aced45a29f $
38    */
 
39    public class EventGroupTest
40    {
41    EventGroup g;
42   
 
43  9 toggle @Before
44    public void setup()
45    {
46  9 this.g = new EventGroup();
47    }
48   
 
49  1 toggle @Test
50    public void testConstructors()
51    {
52  1 Event e = new DefaultEvent();
53   
54  1 Assert.assertNotNull(this.g.getEvents());
55  1 Assert.assertEquals(0, this.g.getEvents().size());
56   
57  1 this.g = new EventGroup(e);
58  1 Assert.assertEquals(1, this.g.getEvents().size());
59  1 Assert.assertTrue(this.g.getEvents().contains(e));
60   
61  1 List<Event> l = new ArrayList<Event>();
62  1 l.add(e);
63  1 this.g = new EventGroup(l);
64  1 Assert.assertEquals(1, this.g.getEvents().size());
65  1 Assert.assertTrue(this.g.getEvents().contains(e));
66   
67  1 Set<Event> s = new HashSet<Event>();
68  1 s.add(e);
69  1 this.g = new EventGroup(s);
70  1 Assert.assertEquals(1, this.g.getEvents().size());
71  1 Assert.assertTrue(this.g.getEvents().contains(e));
72    // Test that the internal set is not the same as the passed set
73  1 s.remove(e);
74  1 Assert.assertEquals(1, this.g.getEvents().size());
75  1 Assert.assertTrue(this.g.getEvents().contains(e));
76  1 s.add(new DefaultEvent());
77  1 s.add(new DefaultEvent());
78  1 Assert.assertEquals(1, this.g.getEvents().size());
79  1 this.g = new EventGroup(s);
80  1 Assert.assertEquals(2, this.g.getEvents().size());
81    }
82   
 
83  1 toggle @Test
84    public void testConstructorsWithNull()
85    {
86  1 this.g = new EventGroup((List<Event>) null);
87  1 Assert.assertNotNull(this.g.getEvents());
88  1 Assert.assertTrue(this.g.getEvents().isEmpty());
89   
90  1 this.g = new EventGroup((Set<Event>) null);
91  1 Assert.assertNotNull(this.g.getEvents());
92  1 Assert.assertTrue(this.g.getEvents().isEmpty());
93   
94  1 this.g = new EventGroup((Event[]) null);
95  1 Assert.assertNotNull(this.g.getEvents());
96  1 Assert.assertTrue(this.g.getEvents().isEmpty());
97    }
98   
 
99  1 toggle @Test
100    public void testConstructorsWithNullElements()
101    {
102  1 List<Event> eventsList = new ArrayList<Event>();
103  1 eventsList.add(new DefaultEvent());
104  1 eventsList.add(null);
105  1 eventsList.add(new DefaultEvent());
106  1 eventsList.add(new DefaultEvent());
107  1 this.g = new EventGroup(eventsList);
108  1 Assert.assertEquals(3, this.g.getEvents().size());
109   
110  1 Set<Event> eventsSet = new HashSet<Event>();
111  1 eventsSet.add(new DefaultEvent());
112  1 eventsSet.add(null);
113  1 eventsSet.add(new DefaultEvent());
114  1 eventsSet.add(new DefaultEvent());
115  1 this.g = new EventGroup(eventsSet);
116  1 Assert.assertEquals(3, this.g.getEvents().size());
117   
118  1 this.g = new EventGroup(new DefaultEvent(), null, new DefaultEvent(), null, new DefaultEvent());
119  1 Assert.assertEquals(3, this.g.getEvents().size());
120    }
121   
 
122  1 toggle @Test
123    public void testGetMainEvent()
124    {
125  1 Event e1 = new DefaultEvent();
126  1 e1.setImportance(Importance.BACKGROUND);
127  1 Event e2 = new DefaultEvent();
128  1 e2.setImportance(Importance.MAJOR);
129  1 Event e3 = new DefaultEvent();
130  1 e3.setImportance(Importance.MAJOR);
131   
132  1 Assert.assertNull(this.g.getMainEvent());
133   
134  1 this.g.addEvents(e1);
135  1 Assert.assertEquals(e1, this.g.getMainEvent());
136  1 this.g.addEvents(e2);
137  1 Assert.assertEquals(e2, this.g.getMainEvent());
138  1 this.g.addEvents(e3);
139  1 Assert.assertEquals(e2, this.g.getMainEvent());
140   
141  1 this.g.clearEvents();
142  1 Assert.assertNull(this.g.getMainEvent());
143   
144  1 this.g.clearEvents();
145  1 this.g.addEvents(e3);
146  1 Assert.assertEquals(e3, this.g.getMainEvent());
147  1 this.g.addEvents(e2);
148  1 Assert.assertEquals(e3, this.g.getMainEvent());
149  1 this.g.addEvents(e1);
150  1 Assert.assertEquals(e3, this.g.getMainEvent());
151   
152  1 this.g.clearEvents();
153  1 this.g.addEvents(e2);
154  1 Assert.assertEquals(e2, this.g.getMainEvent());
155  1 this.g.addEvents(e3);
156  1 Assert.assertEquals(e2, this.g.getMainEvent());
157  1 this.g.addEvents(e1);
158  1 Assert.assertEquals(e2, this.g.getMainEvent());
159   
160  1 this.g.clearEvents();
161  1 this.g.addEvents(e3);
162  1 Assert.assertEquals(e3, this.g.getMainEvent());
163  1 this.g.addEvents(e3);
164  1 Assert.assertEquals(e3, this.g.getMainEvent());
165  1 this.g.addEvents(e2);
166  1 Assert.assertEquals(e3, this.g.getMainEvent());
167    }
168   
 
169  1 toggle @Test
170    public void testAddEvents()
171    {
172  1 Assert.assertTrue(this.g.getEvents().isEmpty());
173  1 Event e1 = new DefaultEvent();
174  1 Assert.assertTrue(this.g.getEvents().isEmpty());
175  1 this.g.addEvents(e1);
176  1 Assert.assertFalse(this.g.getEvents().isEmpty());
177  1 Assert.assertEquals(1, this.g.getEvents().size());
178  1 this.g.addEvents(e1);
179  1 Assert.assertEquals(1, this.g.getEvents().size());
180  1 Event e2 = new DefaultEvent();
181  1 this.g.addEvents(e2, e2, e2);
182  1 Assert.assertEquals(2, this.g.getEvents().size());
183  1 this.g.addEvents(e1, e2);
184  1 Assert.assertEquals(2, this.g.getEvents().size());
185  1 Event e3 = new DefaultEvent();
186  1 this.g.addEvents(e1, e2, e3);
187  1 Assert.assertEquals(3, this.g.getEvents().size());
188  1 this.g.clearEvents();
189  1 Assert.assertEquals(0, this.g.getEvents().size());
190  1 Assert.assertTrue(this.g.getEvents().isEmpty());
191  1 this.g.addEvents(e1, e2, e3);
192  1 Assert.assertEquals(3, this.g.getEvents().size());
193    }
194   
 
195  1 toggle @Test
196    public void testAddEventsWithNull()
197    {
198  1 this.g.addEvents((Event) null);
199  1 Assert.assertTrue(this.g.getEvents().isEmpty());
200   
201  1 this.g.addEvents(new DefaultEvent());
202  1 Assert.assertEquals(1, this.g.getEvents().size());
203  1 this.g.addEvents((Event) null);
204  1 Assert.assertEquals(1, this.g.getEvents().size());
205    }
206   
 
207  1 toggle @Test
208    public void testClearEvents()
209    {
210  1 Assert.assertTrue(this.g.getEvents().isEmpty());
211  1 this.g.addEvents(new DefaultEvent());
212  1 this.g.addEvents(new DefaultEvent());
213  1 this.g.addEvents(new DefaultEvent());
214  1 Assert.assertFalse(this.g.getEvents().isEmpty());
215  1 this.g.clearEvents();
216  1 Assert.assertTrue(this.g.getEvents().isEmpty());
217  1 this.g.clearEvents();
218  1 Assert.assertTrue(this.g.getEvents().isEmpty());
219  1 this.g.addEvents(new DefaultEvent());
220  1 Assert.assertFalse(this.g.getEvents().isEmpty());
221  1 this.g.clearEvents();
222  1 Assert.assertTrue(this.g.getEvents().isEmpty());
223    }
224   
 
225  1 toggle @Test(expected = java.lang.UnsupportedOperationException.class)
226    public void testGetEventsIsReadonly()
227    {
228  1 this.g.addEvents(new DefaultEvent(), new DefaultEvent());
229  1 this.g.getEvents().clear();
230  0 Assert.fail("No exception thrown");
231    }
232   
 
233  1 toggle @Test
234    public void testGetEventsIsNotLive()
235    {
236  1 this.g.addEvents(new DefaultEvent(), new DefaultEvent());
237  1 Set<Event> view = this.g.getEvents();
238  1 Assert.assertEquals(2, view.size());
239  1 this.g.addEvents(new DefaultEvent());
240  1 Assert.assertEquals(2, view.size());
241    }
242    }