Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
25   151   25   1,04
0   103   1   8
24     1,04  
3    
 
  ReflectionUtilsTest       Line # 30 25 0% 15 0 100% 1.0
  ReflectionUtilsTest.B       Line # 32 0 0% 1 1 0% 0.0
  ReflectionUtilsTest.A       Line # 37 0 0% 9 9 0% 0.0
 
  (28)
 
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.tests2;
18   
19    import static org.junit.Assert.*;
20   
21    import java.lang.reflect.Constructor;
22    import java.lang.reflect.Method;
23   
24    import org.easymock.internal.ReflectionUtils;
25    import org.junit.Test;
26   
27    /**
28    * @author Henri Tremblay
29    */
 
30    public class ReflectionUtilsTest {
31   
 
32    public static class B {
 
33  0 toggle protected void foo(final long l) {
34    }
35    }
36   
 
37    public static class A extends B {
38   
 
39  0 toggle public A(final boolean bool, final byte b, final int i, final short s, final char c, final long l,
40    final float f, final double d) {
41    }
42   
 
43  0 toggle public A(final int i) {
44    }
45   
 
46  0 toggle protected A(final long l) {
47    }
48   
 
49  0 toggle private A(final byte b) {
50    }
51   
 
52  0 toggle A(final char c) {
53    }
54   
 
55  0 toggle public A(final CharSequence c) {
56    }
57   
 
58  0 toggle public A(final StringBuilder s) {
59    }
60   
 
61  0 toggle public void foo(final String s) {
62    }
63   
 
64  0 toggle public void foo(final int i) {
65    }
66    }
67   
 
68  2 toggle @Test
69    public void testFindMethod() {
70  2 final Method m = ReflectionUtils.findMethod(String.class, "length");
71  2 assertEquals("public int java.lang.String.length()", m.toString());
72    }
73   
 
74  2 toggle @Test
75    public void testFindMethod_NotFound() {
76  2 final Method m = ReflectionUtils.findMethod(String.class, "aaa");
77  2 assertNull(m);
78    }
79   
 
80  2 toggle @Test
81    public void testFindMethod_Ambiguous() {
82  2 try {
83  2 ReflectionUtils.findMethod(A.class, "foo");
84    } catch (final RuntimeException e) {
85  2 assertEquals("Ambiguous name: More than one method are named foo", e.getMessage());
86    }
87    }
88   
 
89  2 toggle @Test
90    public void testFindMethod_WrongParams() {
91  2 final Method m = ReflectionUtils.findMethod(A.class, "foo", int.class, int.class);
92  2 assertNull(m);
93    }
94   
 
95  2 toggle @Test
96    public void testFindMethod_Superclass() {
97  2 final Method m = ReflectionUtils.findMethod(A.class, "foo", long.class);
98  2 assertEquals("protected void " + B.class.getName() + ".foo(long)", m.toString());
99    }
100   
 
101  2 toggle @Test
102    public void testFindMethodClassOfQStringClassOfQArray() {
103  2 final Method m = ReflectionUtils.findMethod(A.class, "foo", int.class);
104  2 assertEquals("public void " + A.class.getName() + ".foo(int)", m.toString());
105    }
106   
 
107  2 toggle @Test
108    public void testGetConstructor_public() throws NoSuchMethodException {
109  2 final Constructor<A> c = ReflectionUtils.getConstructor(A.class, 5);
110  2 assertArrayEquals(new Class[] { int.class }, c.getParameterTypes());
111    }
112   
 
113  2 toggle @Test
114    public void testGetConstructor_protected() throws NoSuchMethodException {
115  2 final Constructor<A> c = ReflectionUtils.getConstructor(A.class, 5l);
116  2 assertArrayEquals(new Class[] { long.class }, c.getParameterTypes());
117    }
118   
 
119  2 toggle @Test
120    public void testGetConstructor_default() throws NoSuchMethodException {
121  2 final Constructor<A> c = ReflectionUtils.getConstructor(A.class, 'c');
122  2 assertArrayEquals(new Class[] { char.class }, c.getParameterTypes());
123    }
124   
 
125  2 toggle @Test(expected = NoSuchMethodException.class)
126    public void testGetConstructor_private() throws NoSuchMethodException {
127  2 ReflectionUtils.getConstructor(A.class, (byte) 5);
128    }
129   
 
130  2 toggle @Test(expected = IllegalArgumentException.class)
131    public void testGetConstructor_twoMatching() throws NoSuchMethodException {
132  2 ReflectionUtils.getConstructor(A.class, new StringBuilder());
133    }
134   
 
135  2 toggle @Test(expected = NoSuchMethodException.class)
136    public void testGetConstructor_notFound() throws NoSuchMethodException {
137  2 ReflectionUtils.getConstructor(A.class, true);
138    }
139   
 
140  2 toggle @Test(expected = NoSuchMethodException.class)
141    public void testGetConstructor_WrongParams() throws NoSuchMethodException {
142  2 ReflectionUtils.getConstructor(A.class, "", "");
143    }
144   
 
145  2 toggle @Test
146    public void testGetConstructor_AllPrimitives() throws NoSuchMethodException {
147  2 final Constructor<A> c = ReflectionUtils.getConstructor(A.class, true, (byte) 1, 2, (short) 3, 'g',
148    5l, 4.0f, 8.0);
149  2 assertNotNull(c);
150    }
151    }