1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package org.perfectjpattern.core.behavioral.observer; |
22 |
|
|
23 |
|
import java.util.*; |
24 |
|
|
25 |
|
import junit.framework.*; |
26 |
|
|
27 |
|
import org.perfectjpattern.core.api.behavioral.observer.*; |
28 |
|
import org.perfectjpattern.core.api.behavioral.observer.data.*; |
29 |
|
import org.slf4j.*; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@author |
36 |
|
@version |
37 |
|
|
38 |
|
public |
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
39 |
|
class TestProxyObserver |
40 |
|
extends TestCase |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
45 |
1
|
@SuppressWarnings("unchecked")... |
46 |
|
public void |
47 |
|
testObserverPOJO() |
48 |
|
{ |
49 |
|
|
50 |
1
|
ISubject<EventDataOne> mySubjectOne = new Subject<EventDataOne>(); |
51 |
1
|
ISubject<EventDataTwo> mySubjectTwo = new Subject<EventDataTwo>(); |
52 |
1
|
ISubject<EventDataThree> mySubjectThree = |
53 |
|
new Subject<EventDataThree>(); |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
1
|
MyObserverPOJO myPOJO = new MyObserverPOJO(); |
58 |
|
|
59 |
1
|
mySubjectOne.attach(new ObserverProxy<EventDataOne>(myPOJO, |
60 |
|
"onEventOne", EventDataOne.class)); |
61 |
|
|
62 |
1
|
mySubjectTwo.attach(new ObserverProxy<EventDataTwo>(myPOJO, |
63 |
|
"onEventTwo", EventDataTwo.class)); |
64 |
|
|
65 |
1
|
mySubjectThree.attach(new ObserverProxy<EventDataThree>(myPOJO, |
66 |
|
"onEventThree", EventDataThree.class)); |
67 |
|
|
68 |
1
|
mySubjectOne.notifyObservers(new EventDataOne()); |
69 |
1
|
mySubjectTwo.notifyObservers(new EventDataTwo()); |
70 |
1
|
mySubjectThree.notifyObservers(new EventDataThree()); |
71 |
|
|
72 |
1
|
String[] myExpected = new String[] |
73 |
|
{ |
74 |
|
"onEventOne", |
75 |
|
"onEventTwo", |
76 |
|
"onEventThree" |
77 |
|
}; |
78 |
|
|
79 |
1
|
assertTrue("ObserverProxy did not work as expected, not all methods " + |
80 |
|
"were successfully called.", Arrays.deepEquals(myExpected, |
81 |
|
myPOJO.getCalledMethods().toArray())); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
public static |
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
88 |
|
class MyObserverPOJO |
89 |
|
{ |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
91 |
1
|
public void ... |
92 |
|
onEventOne(EventDataOne anEventData) |
93 |
|
{ |
94 |
1
|
theLogger.debug("Received event " + anEventData.toString()); |
95 |
|
|
96 |
1
|
theCalledMethods.add("onEventOne"); |
97 |
|
} |
98 |
|
|
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
100 |
1
|
public void ... |
101 |
|
onEventTwo(EventDataTwo anEventData) |
102 |
|
{ |
103 |
1
|
theLogger.debug("Received event " + anEventData.toString()); |
104 |
|
|
105 |
1
|
theCalledMethods.add("onEventTwo"); |
106 |
|
} |
107 |
|
|
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
109 |
1
|
public void ... |
110 |
|
onEventThree(EventDataThree anEventData) |
111 |
|
{ |
112 |
1
|
theLogger.debug("Received event " + anEventData.toString()); |
113 |
|
|
114 |
1
|
theCalledMethods.add("onEventThree"); |
115 |
|
} |
116 |
|
|
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
1
|
public List<String>... |
119 |
|
getCalledMethods() |
120 |
|
{ |
121 |
1
|
return theCalledMethods; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
private List<String> theCalledMethods = new ArrayList<String>(); |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
private static |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
136 |
|
class EventDataOne |
137 |
|
implements IEventData |
138 |
|
{ |
139 |
|
|
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
private static |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
144 |
|
class EventDataTwo |
145 |
|
implements IEventData |
146 |
|
{ |
147 |
|
|
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
private static |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
152 |
|
class EventDataThree |
153 |
|
implements IEventData |
154 |
|
{ |
155 |
|
|
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
private final static Logger theLogger = LoggerFactory.getLogger( |
166 |
|
TestProxyObserver.class); |
167 |
|
|
168 |
|
} |