1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.easymock.tests2; |
18 |
|
|
19 |
|
import static org.easymock.EasyMock.*; |
20 |
|
import static org.junit.Assert.*; |
21 |
|
|
22 |
|
import java.io.*; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.junit.Ignore; |
27 |
|
import org.junit.Test; |
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
|
|
|
| 97,6% |
Uncovered Elements: 1 (41) |
Complexity: 5 |
Complexity Density: 0,14 |
|
32 |
|
public class SerializationTest implements Serializable { |
33 |
|
|
34 |
|
private static final long serialVersionUID = -774994679161263654L; |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
1
PASS
|
|
36 |
2
|
@SuppressWarnings("unchecked")... |
37 |
|
@Test |
38 |
|
public void test() throws Exception { |
39 |
|
|
40 |
2
|
List<String> mock = createMock(List.class); |
41 |
|
|
42 |
2
|
mock = serialize(mock); |
43 |
|
|
44 |
2
|
expect(mock.get(1)).andReturn("a"); |
45 |
|
|
46 |
2
|
mock = serialize(mock); |
47 |
|
|
48 |
2
|
replay(mock); |
49 |
|
|
50 |
2
|
mock = serialize(mock); |
51 |
|
|
52 |
2
|
assertEquals("a", mock.get(1)); |
53 |
|
|
54 |
2
|
mock = serialize(mock); |
55 |
|
|
56 |
2
|
verify(mock); |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
1
PASS
|
|
59 |
2
|
@SuppressWarnings("unchecked")... |
60 |
|
@Test |
61 |
|
public void testClass() throws Exception { |
62 |
|
|
63 |
2
|
ArrayList<String> mock = createMockBuilder(ArrayList.class).addMockedMethod("get").withConstructor() |
64 |
|
.createMock(); |
65 |
|
|
66 |
2
|
mock = serialize(mock); |
67 |
|
|
68 |
2
|
expect(mock.get(1)).andReturn("a"); |
69 |
|
|
70 |
2
|
mock = serialize(mock); |
71 |
|
|
72 |
2
|
replay(mock); |
73 |
|
|
74 |
2
|
mock = serialize(mock); |
75 |
|
|
76 |
2
|
assertEquals("a", mock.get(1)); |
77 |
|
|
78 |
2
|
mock = serialize(mock); |
79 |
|
|
80 |
2
|
verify(mock); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
1
PASS
|
|
83 |
2
|
@Test... |
84 |
|
public void testAllMockedMethod() throws Exception { |
85 |
|
|
86 |
2
|
SerializationTest mock = createMock(SerializationTest.class); |
87 |
|
|
88 |
2
|
mock = serialize(mock); |
89 |
|
|
90 |
2
|
mock.test(); |
91 |
|
|
92 |
2
|
mock = serialize(mock); |
93 |
|
|
94 |
2
|
replay(mock); |
95 |
|
|
96 |
2
|
mock = serialize(mock); |
97 |
|
|
98 |
2
|
mock.test(); |
99 |
|
|
100 |
2
|
mock = serialize(mock); |
101 |
|
|
102 |
2
|
verify(mock); |
103 |
|
} |
104 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1
PASS
|
|
105 |
0
|
@Test... |
106 |
|
@Ignore |
107 |
|
public void testChangingClassLoader() { |
108 |
|
|
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
|
111 |
24
|
@SuppressWarnings("unchecked")... |
112 |
|
private <T> T serialize(T o) throws IOException, ClassNotFoundException { |
113 |
24
|
final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); |
114 |
24
|
final ObjectOutputStream out = new ObjectOutputStream(bOut); |
115 |
24
|
out.writeObject(o); |
116 |
24
|
out.close(); |
117 |
|
|
118 |
24
|
final ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); |
119 |
24
|
final ObjectInputStream in = new ObjectInputStream(bIn); |
120 |
24
|
o = (T) in.readObject(); |
121 |
24
|
in.close(); |
122 |
|
|
123 |
24
|
return o; |
124 |
|
} |
125 |
|
} |