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

File ComponentDescriptorAddedEventTest.java

 

Code metrics

0
14
6
2
95
57
6
0.43
2.33
3
1

Classes

Class Line # Actions
ComponentDescriptorAddedEventTest 33 14 0% 6 2
0.990%
ComponentDescriptorAddedEventTest.Dummy 38 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.component.event;
21   
22    import java.lang.reflect.Type;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.xwiki.observation.event.Event;
27   
28    /**
29    * Unit tests for {@link ComponentDescriptorAddedEvent}.
30    *
31    * @version $Id: 13411f4b48c8e2c5b34a87b39c86b44537aa979f $
32    */
 
33    public class ComponentDescriptorAddedEventTest
34    {
35    /**
36    * Used in tests below.
37    */
 
38    private static class Dummy
39    {
40    }
41   
 
42  1 toggle @Test
43    public void testMatchesAllComponentRoles()
44    {
45  1 ComponentDescriptorAddedEvent event = new ComponentDescriptorAddedEvent();
46    // Note: We use any class for the test but it's supposed to be a component role class.
47  1 Assert.assertTrue(event.matches(new ComponentDescriptorAddedEvent((Type) Dummy.class, "rolehint")));
48    }
49   
 
50  1 toggle @Test
51    public void testMatchesWhenDifferentEvent()
52    {
53  1 ComponentDescriptorAddedEvent event = new ComponentDescriptorAddedEvent();
54  1 Assert.assertFalse(event.matches(new Event()
55    {
 
56  0 toggle @Override
57    public boolean matches(Object otherEvent)
58    {
59  0 return false;
60    }
61    }));
62    }
63   
 
64  1 toggle @Test
65    public void testMatchesWhenSpecificRoleSpecified()
66    {
67    // Note: We use any class for the test but it's supposed to be a component role class.
68  1 ComponentDescriptorAddedEvent event = new ComponentDescriptorAddedEvent((Type) Dummy.class);
69  1 Assert.assertTrue(event.matches(new ComponentDescriptorAddedEvent((Type) Dummy.class, "rolehint")));
70    // Use a different class so that it doesn't match
71  1 Assert.assertFalse(event.matches(new ComponentDescriptorAddedEvent((Type) ComponentDescriptorAddedEvent.class,
72    "rolehint")));
73    }
74   
 
75  1 toggle @Test
76    public void testEquals()
77    {
78  1 Assert.assertEquals(new ComponentDescriptorAddedEvent(), new ComponentDescriptorAddedEvent());
79  1 Assert.assertEquals(new ComponentDescriptorAddedEvent((Type) Dummy.class), new ComponentDescriptorAddedEvent(
80    (Type) Dummy.class));
81  1 Assert.assertEquals(new ComponentDescriptorAddedEvent((Type) Dummy.class, "rolehint"),
82    new ComponentDescriptorAddedEvent((Type) Dummy.class, "rolehint"));
83    }
84   
 
85  1 toggle @Test
86    public void testHashCode()
87    {
88  1 Assert.assertEquals(new ComponentDescriptorAddedEvent().hashCode(),
89    new ComponentDescriptorAddedEvent().hashCode());
90  1 Assert.assertEquals(new ComponentDescriptorAddedEvent((Type) Dummy.class).hashCode(),
91    new ComponentDescriptorAddedEvent((Type) Dummy.class).hashCode());
92  1 Assert.assertEquals(new ComponentDescriptorAddedEvent((Type) Dummy.class, "rolehint").hashCode(),
93    new ComponentDescriptorAddedEvent((Type) Dummy.class, "rolehint").hashCode());
94    }
95    }