Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
11   73   5   2,2
0   35   0,45   1,25
5     1  
4    
 
  ConstructorTest       Line # 27 9 0% 3 0 100% 1.0
  ConstructorTest.FooClass       Line # 29 1 0% 1 2 0% 0.0
  ConstructorTest.EmptyConstructorClass       Line # 36 0 - 0 0 - -1.0
  ConstructorTest.ConstructorCallingPublicMethodClass       Line # 39 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 org.junit.Test;
23   
24    /**
25    * @author Henri Tremblay
26    */
 
27    public class ConstructorTest {
28   
 
29    public static class FooClass {
 
30  0 toggle public void foo() {
31    // Since it's always mocked, it should never be called
32  0 fail();
33    }
34    }
35   
 
36    public static class EmptyConstructorClass extends FooClass {
37    }
38   
 
39    public static class ConstructorCallingPublicMethodClass extends FooClass {
40   
 
41  0 toggle public ConstructorCallingPublicMethodClass() {
42  0 foo();
43    }
44    }
45   
 
46  4 toggle private void testConstructor(final Class<? extends FooClass> mockedClass) {
47  4 final FooClass mock = createMock(mockedClass);
48  4 assertTrue(mockedClass.isAssignableFrom(mock.getClass()));
49  4 mock.foo();
50  4 expectLastCall();
51  4 replay(mock);
52  4 mock.foo();
53  4 verify(mock);
54    }
55   
56    /**
57    * Test if a class with an empty constructor is mocked correctly.
58    */
 
59  2 toggle @Test
60    public void emptyConstructor() {
61  2 testConstructor(EmptyConstructorClass.class);
62    }
63   
64    /**
65    * Test that a constructor calling a mocked method (in this case a public
66    * one) is mocked correctly. The expected behavior is that the mocked method
67    * won't be called and just be ignored
68    */
 
69  2 toggle @Test
70    public void constructorCallingPublicMethod() {
71  2 testConstructor(ConstructorCallingPublicMethodClass.class);
72    }
73    }