Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
19   89   9   3,17
0   60   0,47   6
6     1,5  
1    
 
  ClassExtensionHelperTest       Line # 38 19 0% 9 5 80% 0.8
 
  (10)
 
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.easymock.internal.ClassExtensionHelper.*;
20    import static org.junit.Assert.*;
21   
22    import java.lang.reflect.InvocationHandler;
23    import java.lang.reflect.Method;
24    import java.lang.reflect.Proxy;
25    import java.util.ArrayList;
26    import java.util.List;
27   
28    import net.sf.cglib.proxy.Enhancer;
29    import net.sf.cglib.proxy.NoOp;
30   
31    import org.easymock.EasyMock;
32    import org.easymock.internal.MocksControl;
33    import org.junit.Test;
34   
35    /**
36    * @author Henri Tremblay
37    */
 
38    public class ClassExtensionHelperTest {
39   
 
40  2 toggle @Test
41    public void testGetControl_EasyMock() {
42  2 final List<?> mock = EasyMock.createMock(List.class);
43  2 assertNotNull(getControl(mock));
44    }
45   
 
46  2 toggle @Test
47    public void testGetControl_EasyMockClassExtension() {
48  2 final ArrayList<?> mock = EasyMock.createMock(ArrayList.class);
49  2 assertTrue(getControl(mock) instanceof MocksControl);
50    }
51   
 
52  2 toggle @Test
53    public void testGetControl_EnhancedButNotAMock() {
54  2 final Object o = Enhancer.create(ArrayList.class, NoOp.INSTANCE);
55  2 try {
56  2 getControl(o);
57  0 fail();
58    } catch (final IllegalArgumentException e) {
59  2 assertEquals("Not a mock: " + o.getClass().getName(), e.getMessage());
60    }
61    }
62   
 
63  2 toggle @Test
64    public void testGetControl_ProxyButNotMock() {
65  2 final Object o = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { List.class },
66    new InvocationHandler() {
 
67  0 toggle public Object invoke(final Object proxy, final Method method, final Object[] args)
68    throws Throwable {
69  0 return null;
70    }
71    });
72  2 try {
73  2 getControl(o);
74  0 fail();
75    } catch (final IllegalArgumentException e) {
76  2 assertEquals("Not a mock: " + o.getClass().getName(), e.getMessage());
77    }
78    }
79   
 
80  2 toggle @Test
81    public void testGetControl_NotAMock() {
82  2 try {
83  2 getControl("");
84  0 fail();
85    } catch (final IllegalArgumentException e) {
86  2 assertEquals("Not a mock: " + String.class.getName(), e.getMessage());
87    }
88    }
89    }