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.structural.proxy; |
22 |
|
|
23 |
|
import junit.framework.*; |
24 |
|
|
25 |
|
import org.perfectjpattern.core.api.structural.proxy.*; |
26 |
|
import org.slf4j.*; |
27 |
|
|
28 |
|
|
29 |
|
@link |
30 |
|
|
31 |
|
@author |
32 |
|
@version |
33 |
|
|
34 |
|
public |
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.08 |
|
35 |
|
class TestProxy |
36 |
|
extends TestCase |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
41 |
1
|
public void... |
42 |
|
testProxying() |
43 |
|
{ |
44 |
1
|
theLogger.debug("Step #1: Create component and proxy"); |
45 |
1
|
SomeComponent mySubject = new SomeComponent(); |
46 |
1
|
IProxy<ISomeComponent> myProxy = new AbstractProxy< |
47 |
|
ISomeComponent>(ISomeComponent.class, mySubject) |
48 |
|
{ |
49 |
|
|
50 |
|
}; |
51 |
|
|
52 |
1
|
theLogger.debug("Step #2: Make sure that the 'Subject' is correct"); |
53 |
1
|
assertSame("IProxy.getSubject not correctly implemented", mySubject, |
54 |
|
myProxy.getRealSubject()); |
55 |
|
|
56 |
1
|
theLogger.debug("Step #3: Get reference to proxied component"); |
57 |
1
|
ISomeComponent myComponent = myProxy.getSubject(); |
58 |
|
|
59 |
1
|
theLogger.debug("Step #4: Call methods through the proxied component"); |
60 |
1
|
myComponent.method1("Hello proxy world!"); |
61 |
1
|
myComponent.method2(); |
62 |
|
|
63 |
1
|
theLogger.debug("Running assertions"); |
64 |
1
|
assertTrue("method1 was not called", mySubject.isMethod1Called()); |
65 |
|
|
66 |
1
|
assertTrue("method2 was not called", mySubject.isMethod2Called()); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
public static |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
76 |
|
interface ISomeComponent |
77 |
|
{ |
78 |
|
|
79 |
|
public void |
80 |
|
method1(String aValue); |
81 |
|
|
82 |
|
|
83 |
|
public void |
84 |
|
method2(); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
private static |
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
92 |
|
class SomeComponent |
93 |
|
implements ISomeComponent |
94 |
|
{ |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
96 |
1
|
public void ... |
97 |
|
method1(String aValue) |
98 |
|
{ |
99 |
1
|
theLogger.debug(aValue); |
100 |
|
|
101 |
1
|
theMethod1Called = true; |
102 |
|
} |
103 |
|
|
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
1
|
public void ... |
106 |
|
method2() |
107 |
|
{ |
108 |
1
|
theMethod2Called = true; |
109 |
|
} |
110 |
|
|
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
1
|
public boolean... |
113 |
|
isMethod1Called() |
114 |
|
{ |
115 |
1
|
return theMethod1Called; |
116 |
|
} |
117 |
|
|
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
1
|
public boolean... |
120 |
|
isMethod2Called() |
121 |
|
{ |
122 |
1
|
return theMethod2Called; |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
private boolean theMethod1Called; |
129 |
|
private boolean theMethod2Called; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
private final static Logger theLogger = LoggerFactory.getLogger(TestProxy.class); |
140 |
|
|
141 |
|
} |