Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
13   82   5   2,6
0   43   0,38   1
5     1  
5    
 
  GenericTest       Line # 32 10 0% 2 0 100% 1.0
  GenericTest.C       Line # 34 0 - 0 0 - -1.0
  GenericTest.B       Line # 38 1 0% 1 2 0% 0.0
  GenericTest.AbstractFoo       Line # 53 1 0% 1 2 0% 0.0
  GenericTest.ConcreteFoo       Line # 61 1 0% 1 2 0% 0.0
 
  (4)
 
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.util.Collection;
23   
24    import org.junit.Test;
25   
26    /**
27    * Bridges are generated method used for generics. They shouldn't be mocked to
28    * keep delegating correctly to the real implementation.
29    *
30    * @author Henri Tremblay
31    */
 
32    public class GenericTest {
33   
 
34    public interface C<U> {
35    public void doCMethod(U u);
36    }
37   
 
38    public class B implements C<Integer> {
 
39  0 toggle public void doCMethod(final Integer u) {
40  0 fail("Should be mocked");
41    }
42    }
43   
 
44  2 toggle @Test
45    public void testBridgeUnmocked() {
46  2 final B b = createMock(B.class);
47  2 b.doCMethod(new Integer(6));
48  2 replay(b);
49  2 ((C<Integer>) b).doCMethod(new Integer(6));
50  2 verify(b);
51    }
52   
 
53    static abstract class AbstractFoo {
 
54  0 toggle public Collection<String> getSomeStrings() {
55  0 return null;
56    }
57   
58    public abstract Collection<Integer> getSomeIntegers();
59    }
60   
 
61    public class ConcreteFoo extends AbstractFoo {
 
62  0 toggle @Override
63    public Collection<Integer> getSomeIntegers() {
64  0 return null;
65    }
66    }
67   
68    /**
69    * The JDK (and not Eclipse) creates a bridge in a concrete class extending
70    * a package scope one. In this case, the bridge contains a call to the
71    * super method. So we want to make sure the mocking is forwarding
72    * correctly.
73    */
 
74  2 toggle @Test
75    public void testPackageScope() {
76  2 final ConcreteFoo b = createMock(ConcreteFoo.class);
77  2 expect(b.getSomeStrings()).andReturn(null);
78  2 replay(b);
79  2 ((AbstractFoo) b).getSomeStrings();
80  2 verify(b);
81    }
82    }