Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
23   97   8   3,29
0   58   0,35   3,5
7     1,14  
2    
 
  InvocationTest       Line # 30 21 0% 5 1 96% 0.96
  InvocationTest.ToString       Line # 71 2 0% 3 1 80% 0.8
 
  (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.tests;
18   
19    import static org.junit.Assert.*;
20   
21    import java.lang.reflect.Method;
22   
23    import org.easymock.internal.Invocation;
24    import org.junit.Before;
25    import org.junit.Test;
26   
27    /**
28    * @author OFFIS, Tammo Freese
29    */
 
30    public class InvocationTest {
31   
32    private Invocation call;
33   
34    private Invocation equalCall;
35   
36    private Invocation nonEqualCall;
37   
 
38  6 toggle @Before
39    public void setup() throws SecurityException, NoSuchMethodException {
40  6 final Object[] arguments1 = new Object[] { "" };
41  6 final Object[] arguments2 = new Object[] { "" };
42  6 final Object[] arguments3 = new Object[] { "X" };
43  6 final Method m = Object.class.getMethod("equals", new Class[] { Object.class });
44  6 final Object mock = new Object();
45  6 call = new Invocation(mock, m, arguments1);
46  6 equalCall = new Invocation(mock, m, arguments2);
47  6 nonEqualCall = new Invocation(mock, m, arguments3);
48    }
49   
 
50  2 toggle @Test
51    public void testEquals() {
52  2 assertFalse(call.equals(null));
53  2 assertFalse(call.equals(""));
54  2 assertTrue(call.equals(equalCall));
55  2 assertFalse(call.equals(nonEqualCall));
56    }
57   
 
58  2 toggle @Test
59    public void testHashCode() {
60  2 try {
61  2 call.hashCode();
62  0 fail();
63    } catch (final UnsupportedOperationException expected) {
64  2 assertEquals("hashCode() is not implemented", expected.getMessage());
65    }
66    }
67   
 
68  2 toggle @Test
69    public void testShouldDisplayMocksToStringIfValidJavaIdentifier() throws SecurityException,
70    NoSuchMethodException {
 
71    class ToString {
72    private final String name;
73   
 
74  4 toggle public ToString(final String name) {
75  4 this.name = name;
76    }
77   
 
78  4 toggle @Override
79    public String toString() {
80  4 return name;
81    }
82   
 
83  0 toggle public void aMethod() {
84    }
85    }
86   
87  2 final Method method = ToString.class.getMethod("aMethod", new Class[0]);
88  2 Invocation invocation = new Invocation(new ToString("validJavaIdentifier"), method, null);
89   
90  2 assertEquals(invocation.toString(), "validJavaIdentifier.aMethod()");
91   
92  2 invocation = new Invocation(new ToString("no-valid-java-identifier"), method, null);
93   
94  2 assertEquals("aMethod()", invocation.toString());
95   
96    }
97    }