Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
16   86   9   2,29
0   52   0,56   1,75
7     1,29  
4    
 
  LimitationsTest       Line # 31 15 0% 7 5 75% 0.75
  LimitationsTest.MyClass       Line # 33 1 0% 1 0 100% 1.0
  LimitationsTest.PrivateClass       Line # 39 0 0% 1 1 0% 0.0
  LimitationsTest.NativeClass       Line # 44 0 - 0 0 - -1.0
 
  (8)
 
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.tests;
18   
19    import static org.easymock.EasyMock.*;
20    import static org.junit.Assert.*;
21   
22    import java.util.AbstractList;
23   
24    import org.junit.Test;
25   
26    /**
27    * Test the limitations of class mocking
28    *
29    * @author Henri Tremblay
30    */
 
31    public class LimitationsTest {
32   
 
33    public static class MyClass {
 
34  2 toggle public final int foo() {
35  2 throw new RuntimeException();
36    }
37    }
38   
 
39    public static class PrivateClass {
 
40  0 toggle private PrivateClass() {
41    }
42    }
43   
 
44    public static class NativeClass {
45    public native int foo();
46    }
47   
 
48  0 toggle public void finalClass() {
49  0 try {
50  0 createMock(String.class);
51  0 fail("Magic, we can mock a final class");
52    } catch (final Exception e) {
53    }
54    }
55   
 
56  2 toggle @Test
57    public void abstractClass() {
58  2 final Object o = createMock(AbstractList.class);
59  2 assertTrue(o instanceof AbstractList<?>);
60    }
61   
 
62  2 toggle @Test
63    public void mockFinalMethod() {
64  2 final MyClass c = createMock(MyClass.class);
65   
66  2 try {
67  2 c.foo();
68  0 fail("Final method shouldn't be mocked");
69    } catch (final Exception e) {
70    }
71    }
72   
 
73  2 toggle @Test
74    public void privateConstructor() {
75  2 createMock(PrivateClass.class);
76    }
77   
 
78  2 toggle @Test
79    public void mockNativeMethod() {
80  2 final NativeClass mock = createMock(NativeClass.class);
81  2 expect(mock.foo()).andReturn(1);
82  2 replay(mock);
83  2 assertEquals(1, mock.foo());
84  2 verify(mock);
85    }
86    }