1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 4 |
Complexity Density: 0.15 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
55 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
1 |
@After... |
78 |
|
public void tearDown() |
79 |
|
{ |
80 |
1 |
this.mockery.assertIsSatisfied(); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
85 |
1 |
@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 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
102 |
1 |
{... |
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 |
|
} |