Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
23   87   8   3,29
0   63   0,35   3,5
7     1,14  
2    
 
 
  InvocationTest       Line # 16 21 5 96% 0.96
  InvocationTest.ToString       Line # 58 2 3 80% 0.8
 
  (3)
 
1    /*
2    * Copyright (c) 2001-2008 OFFIS, Tammo Freese.
3    * This program is made available under the terms of the MIT License.
4    */
5    package org.easymock.tests;
6   
7    import static org.junit.Assert.*;
8   
9    import java.lang.reflect.Method;
10   
11    import org.easymock.internal.EqualsMatcher;
12    import org.easymock.internal.Invocation;
13    import org.junit.Before;
14    import org.junit.Test;
15   
 
16    public class InvocationTest {
17   
18    private Invocation call;
19   
20    private Invocation equalCall;
21   
22    private Invocation nonEqualCall;
23   
 
24  3 toggle @Before
25    public void setup() throws SecurityException, NoSuchMethodException {
26  3 Object[] arguments1 = new Object[] { "" };
27  3 Object[] arguments2 = new Object[] { "" };
28  3 Object[] arguments3 = new Object[] { "X" };
29  3 Method m = Object.class.getMethod("equals",
30    new Class[] { Object.class });
31  3 Object mock = new Object();
32  3 call = new Invocation(mock, m, arguments1);
33  3 equalCall = new Invocation(mock, m, arguments2);
34  3 nonEqualCall = new Invocation(mock, m, arguments3);
35    }
36   
 
37  1 toggle @Test
38    public void testEquals() {
39  1 assertFalse(call.equals(null));
40  1 assertFalse(call.equals(""));
41  1 assertTrue(call.equals(equalCall));
42  1 assertFalse(call.equals(nonEqualCall));
43    }
44   
 
45  1 toggle @Test
46    public void testHashCode() {
47  1 try {
48  1 call.hashCode();
49  0 fail();
50    } catch (UnsupportedOperationException expected) {
51  1 assertEquals("hashCode() is not implemented", expected.getMessage());
52    }
53    }
54   
 
55  1 toggle @Test
56    public void testShouldDisplayMocksToStringIfValidJavaIdentifier()
57    throws SecurityException, NoSuchMethodException {
 
58    class ToString {
59    private final String name;
60   
 
61  2 toggle public ToString(String name) {
62  2 this.name = name;
63    }
64   
 
65  2 toggle @Override
66    public String toString() {
67  2 return name;
68    }
69   
 
70  0 toggle public void aMethod() {
71    }
72    }
73   
74  1 Method method = ToString.class.getMethod("aMethod", new Class[0]);
75  1 Invocation invocation = new Invocation(new ToString("validJavaIdentifier"),
76    method, null);
77   
78  1 assertEquals(invocation.toString(new EqualsMatcher()),
79    "validJavaIdentifier.aMethod()");
80   
81  1 invocation = new Invocation(new ToString("no-valid-java-identifier"),
82    method, null);
83   
84  1 assertEquals(invocation.toString(new EqualsMatcher()), "aMethod()");
85   
86    }
87    }