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

File StackingComponentEventManagerTest.java

 

Code metrics

0
27
4
1
116
71
4
0.15
6.75
4
1

Classes

Class Line # Actions
StackingComponentEventManagerTest 41 27 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.internal;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24   
25    import org.jmock.Expectations;
26    import org.jmock.Mockery;
27    import org.junit.After;
28    import org.junit.Before;
29    import org.junit.Test;
30    import org.xwiki.component.descriptor.DefaultComponentDescriptor;
31    import org.xwiki.component.event.ComponentDescriptorAddedEvent;
32    import org.xwiki.component.event.ComponentDescriptorRemovedEvent;
33    import org.xwiki.component.manager.ComponentManager;
34    import org.xwiki.observation.ObservationManager;
35   
36    /**
37    * Test {@link StackingComponentEventManager}.
38    *
39    * @version $Id: 7e1703aff43b5f5399e19d6cec2988da1cfc3766 $
40    */
 
41    public class StackingComponentEventManagerTest
42    {
43    private StackingComponentEventManager eventManager;
44   
45    private DefaultComponentDescriptor<CharSequence> descriptor1;
46   
47    private DefaultComponentDescriptor<Collection> descriptor2;
48   
49    private ObservationManager mockObservationManager;
50   
51    private ComponentManager mockComponentManager;
52   
53    private Mockery mockery;
54   
 
55  1 toggle @Before
56    public void setUp()
57    {
58  1 this.eventManager = new StackingComponentEventManager();
59   
60  1 this.descriptor1 = new DefaultComponentDescriptor<CharSequence>();
61  1 this.descriptor1.setImplementation(String.class);
62  1 this.descriptor1.setRoleType(CharSequence.class);
63  1 this.descriptor1.setRoleHint("hint1");
64  1 this.descriptor2 = new DefaultComponentDescriptor<Collection>();
65  1 this.descriptor2.setImplementation(ArrayList.class);
66  1 this.descriptor2.setRoleType(Collection.class);
67  1 this.descriptor2.setRoleHint("hint2");
68   
69  1 this.mockery = new Mockery();
70   
71  1 this.mockObservationManager = this.mockery.mock(ObservationManager.class);
72  1 this.mockComponentManager = this.mockery.mock(ComponentManager.class);
73   
74  1 this.eventManager.setObservationManager(this.mockObservationManager);
75    }
76   
 
77  1 toggle @After
78    public void tearDown()
79    {
80  1 this.mockery.assertIsSatisfied();
81    }
82   
83    // Tests
84   
 
85  1 toggle @Test
86    public void flushEvents()
87    {
88  1 this.eventManager.shouldStack(true);
89   
90  1 this.eventManager.notifyComponentRegistered(this.descriptor1);
91  1 this.eventManager.notifyComponentRegistered(this.descriptor1, this.mockComponentManager);
92  1 this.eventManager.notifyComponentUnregistered(this.descriptor2);
93  1 this.eventManager.notifyComponentUnregistered(this.descriptor2, this.mockComponentManager);
94   
95  1 final ComponentDescriptorAddedEvent addedEvent =
96    new ComponentDescriptorAddedEvent(this.descriptor1.getRoleType(), this.descriptor1.getRoleHint());
97  1 final ComponentDescriptorRemovedEvent removedEvent =
98    new ComponentDescriptorRemovedEvent(this.descriptor2.getRoleType(), this.descriptor2.getRoleHint());
99   
100  1 this.mockery.checking(new Expectations()
101    {
 
102  1 toggle {
103  1 oneOf(mockObservationManager).notify(with(equal(addedEvent)), with(same(mockComponentManager)),
104    with(same(descriptor1)));
105  1 oneOf(mockObservationManager).notify(with(equal(addedEvent)), with(aNull(Object.class)),
106    with(same(descriptor1)));
107  1 oneOf(mockObservationManager).notify(with(equal(removedEvent)), with(same(mockComponentManager)),
108    with(same(descriptor2)));
109  1 oneOf(mockObservationManager).notify(with(equal(removedEvent)), with(aNull(Object.class)),
110    with(same(descriptor2)));
111    }
112    });
113   
114  1 this.eventManager.flushEvents();
115    }
116    }