Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
36   125   5   7,2
0   66   0,14   5
5     1  
1    
 
  SerializationTest       Line # 32 36 0% 5 1 97,6% 0.9756098
 
  (6)
 
1    /**
2    * Copyright 2001-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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 Henri Tremblay
31    */
 
32    public class SerializationTest implements Serializable {
33   
34    private static final long serialVersionUID = -774994679161263654L;
35   
 
36  2 toggle @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   
 
59  2 toggle @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   
 
83  2 toggle @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   
 
105  0 toggle @Test
106    @Ignore
107    public void testChangingClassLoader() {
108   
109    }
110   
 
111  24 toggle @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    }