Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
26   154   17   1,53
0   88   0,65   4,25
17     1  
4    
 
  MockClassControlTest       Line # 32 22 0% 13 0 100% 1.0
  MockClassControlTest.ClassToMock       Line # 38 0 - 0 0 - -1.0
  MockClassControlTest.ClassToMockWithOverload       Line # 47 3 0% 3 6 0% 0.0
  MockClassControlTest.ClassWithAnotherOverload       Line # 65 1 0% 1 2 0% 0.0
 
  (14)
 
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 org.junit.After;
23    import org.junit.Before;
24    import org.junit.Test;
25   
26    /**
27    * Tests of MockClassControl basic functionnalities
28    *
29    * @author Henri Tremblay
30    * @author OFFIS, Tammo Freese
31    */
 
32    public class MockClassControlTest {
33   
34    /**
35    * Class that will be mocked. The methods defined in it are there just to
36    * make sure they are correctly overloaded by the mock.
37    */
 
38    public static class ClassToMock {
39   
40    }
41   
42    /**
43    * Same as ClassToMock except that the methods with a standard behavior
44    * provided by the mock are overloaded. We expect the standard behavior to
45    * still be called.
46    */
 
47    public static class ClassToMockWithOverload {
48   
 
49  0 toggle @Override
50    public boolean equals(final Object o) {
51  0 return false;
52    }
53   
 
54  0 toggle @Override
55    public int hashCode() {
56  0 return -1;
57    }
58   
 
59  0 toggle @Override
60    public String toString() {
61  0 return "super";
62    }
63    }
64   
 
65    public static class ClassWithAnotherOverload extends ClassToMockWithOverload {
66   
 
67  0 toggle @Override
68    public String toString() {
69  0 return "super.super";
70    }
71    }
72   
73    private Object mock;
74   
 
75  14 toggle @Before
76    public void setUp() throws Exception {
77    }
78   
 
79  14 toggle @After
80    public void tearDown() throws Exception {
81  14 mock = null;
82    }
83   
 
84  14 toggle private void initMock(final Class<?> toMock) {
85  14 mock = createMock(toMock);
86    }
87   
 
88  2 toggle @Test
89    public void testEquals() {
90  2 testEquals(ClassToMock.class);
91    }
92   
 
93  2 toggle @Test
94    public void testEquals_WithOverload() {
95  2 testEquals(ClassToMockWithOverload.class);
96    }
97   
98    /**
99    * Make sure that a mock is equals to itself
100    */
 
101  4 toggle private void testEquals(final Class<?> toMock) {
102  4 initMock(toMock);
103  4 assertEquals(mock, mock);
104  4 replay(mock);
105  4 assertEquals(mock, mock);
106    }
107   
 
108  2 toggle @Test
109    public void testHashCode() {
110  2 testHashCode(ClassToMock.class);
111    }
112   
 
113  2 toggle @Test
114    public void testHashCode_WithOverload() {
115  2 testHashCode(ClassToMockWithOverload.class);
116    }
117   
118    /**
119    * Make sure the hashCode doesn't need to be recorded and that it stays the
120    * same after the replay
121    */
 
122  4 toggle private void testHashCode(final Class<?> toMock) {
123  4 initMock(toMock);
124  4 final int code = mock.hashCode();
125  4 replay(mock);
126  4 assertEquals(code, mock.hashCode());
127    }
128   
 
129  2 toggle @Test
130    public void testToString() {
131  2 testToString(ClassToMock.class);
132    }
133   
 
134  2 toggle @Test
135    public void testToString_WithOverload() {
136  2 testToString(ClassToMockWithOverload.class);
137    }
138   
 
139  2 toggle @Test
140    public void testToString_WithTwoOverload() {
141  2 testToString(ClassWithAnotherOverload.class);
142    }
143   
144    /**
145    * Check that the toString is the EasyMock one giving the mocked class
146    */
 
147  6 toggle private void testToString(final Class<?> toMock) {
148  6 initMock(toMock);
149  6 final String expectedValue = "EasyMock for " + toMock.toString();
150  6 assertEquals(expectedValue, mock.toString());
151  6 replay(mock);
152  6 assertEquals(expectedValue, mock.toString());
153    }
154    }