Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
30   87   6   10
0   55   0,2   3
3     2  
1    
 
  StubTest       Line # 29 30 0% 6 0 100% 1.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.tests2;
18   
19    import static org.easymock.EasyMock.*;
20    import static org.junit.Assert.*;
21   
22    import org.easymock.tests.IMethods;
23    import org.junit.Before;
24    import org.junit.Test;
25   
26    /**
27    * @author OFFIS, Tammo Freese
28    */
 
29    public class StubTest {
30    private IMethods mock;
31   
 
32  4 toggle @Before
33    public void setup() {
34  4 mock = createStrictMock(IMethods.class);
35    }
36   
 
37  2 toggle @Test
38    public void stub() {
39  2 mock.simpleMethodWithArgument("1");
40  2 expectLastCall().anyTimes();
41  2 mock.simpleMethodWithArgument("2");
42  2 expectLastCall().anyTimes();
43  2 mock.simpleMethodWithArgument("3");
44  2 expectLastCall().asStub();
45   
46  2 replay(mock);
47   
48  2 mock.simpleMethodWithArgument("3");
49  2 mock.simpleMethodWithArgument("3");
50  2 mock.simpleMethodWithArgument("1");
51  2 mock.simpleMethodWithArgument("2");
52  2 mock.simpleMethodWithArgument("3");
53  2 mock.simpleMethodWithArgument("3");
54   
55  2 verify(mock);
56   
57    }
58   
 
59  2 toggle @Test
60    public void stubWithReturnValue() {
61  2 expect(mock.oneArg("1")).andReturn("A").andStubReturn("B");
62  2 expect(mock.oneArg("2")).andThrow(new IllegalArgumentException()).andStubThrow(
63    new IllegalStateException());
64   
65  2 replay(mock);
66   
67  2 assertEquals("A", mock.oneArg("1"));
68  2 assertEquals("B", mock.oneArg("1"));
69  2 assertEquals("B", mock.oneArg("1"));
70  2 try {
71  2 mock.oneArg("2");
72    } catch (final IllegalArgumentException ignored) {
73    }
74  2 assertEquals("B", mock.oneArg("1"));
75  2 try {
76  2 mock.oneArg("2");
77    } catch (final IllegalStateException ignored) {
78    }
79  2 assertEquals("B", mock.oneArg("1"));
80  2 try {
81  2 mock.oneArg("2");
82    } catch (final IllegalStateException ignored) {
83    }
84  2 verify(mock);
85    }
86   
87    }