Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
16   91   7   2,29
0   54   0,44   1,75
7     1  
4    
 
  ObjectMethodsTest       Line # 31 16 0% 7 0 100% 1.0
  ObjectMethodsTest.EmptyInterface       Line # 35 0 - 0 0 - -1.0
  ObjectMethodsTest.MockedClass       Line # 75 0 - 0 0 - -1.0
  ObjectMethodsTest.DummyProxy       Line # 78 0 - 0 0 - -1.0
 
  (12)
 
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.lang.reflect.Method;
23   
24    import org.easymock.internal.ObjectMethodsFilter;
25    import org.junit.Before;
26    import org.junit.Test;
27   
28    /**
29    * @author OFFIS, Tammo Freese
30    */
 
31    public class ObjectMethodsTest {
32   
33    private EmptyInterface mock;
34   
 
35    private interface EmptyInterface {
36    }
37   
 
38  12 toggle @Before
39    public void setup() {
40  12 mock = createMock(EmptyInterface.class);
41    }
42   
 
43  2 toggle @Test
44    public void equalsBeforeActivation() {
45  2 assertEquals(mock, mock);
46  2 assertTrue(!mock.equals(null));
47    }
48   
 
49  2 toggle @Test
50    public void equalsAfterActivation() {
51  2 replay(mock);
52  2 assertEquals(mock, mock);
53  2 assertTrue(!mock.equals(null));
54    }
55   
 
56  2 toggle @Test
57    public void testHashCode() {
58  2 final int hashCodeBeforeActivation = mock.hashCode();
59  2 replay(mock);
60  2 final int hashCodeAfterActivation = mock.hashCode();
61  2 assertEquals(hashCodeBeforeActivation, hashCodeAfterActivation);
62    }
63   
 
64  2 toggle @Test
65    public void toStringBeforeActivation() {
66  2 assertEquals("EasyMock for " + EmptyInterface.class.toString(), mock.toString());
67    }
68   
 
69  2 toggle @Test
70    public void toStringAfterActivation() {
71  2 replay(mock);
72  2 assertEquals("EasyMock for " + EmptyInterface.class.toString(), mock.toString());
73    }
74   
 
75    private static class MockedClass {
76    }
77   
 
78    private static class DummyProxy extends MockedClass {
79    }
80   
81    // if the class is no Proxy, ObjectMethodFilter should use the
82    // superclasses' name. This is needed for the class extension.
 
83  2 toggle @Test
84    public void toStringForClasses() throws Throwable {
85  2 final ObjectMethodsFilter filter = new ObjectMethodsFilter(Object.class, null, null);
86  2 final Method toString = Object.class.getMethod("toString", new Class[0]);
87  2 assertEquals("EasyMock for " + MockedClass.class.toString(), filter.invoke(new DummyProxy(),
88    toString, new Object[0]));
89    }
90   
91    }