Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
30   72   6   10
0   55   0,2   3
3     2  
1    
 
 
  StubTest       Line # 14 30 6 100% 1.0
 
  (2)
 
1    /*
2    * Copyright (c) 2001-2008 OFFIS, Tammo Freese.
3    * This program is made available under the terms of the MIT License.
4    */
5    package org.easymock.tests2;
6   
7    import static org.easymock.EasyMock.*;
8    import static org.junit.Assert.*;
9   
10    import org.easymock.tests.IMethods;
11    import org.junit.Before;
12    import org.junit.Test;
13   
 
14    public class StubTest {
15    private IMethods mock;
16   
 
17  2 toggle @Before
18    public void setup() {
19  2 mock = createStrictMock(IMethods.class);
20    }
21   
 
22  1 toggle @Test
23    public void stub() {
24  1 mock.simpleMethodWithArgument("1");
25  1 expectLastCall().anyTimes();
26  1 mock.simpleMethodWithArgument("2");
27  1 expectLastCall().anyTimes();
28  1 mock.simpleMethodWithArgument("3");
29  1 expectLastCall().asStub();
30   
31  1 replay(mock);
32   
33  1 mock.simpleMethodWithArgument("3");
34  1 mock.simpleMethodWithArgument("3");
35  1 mock.simpleMethodWithArgument("1");
36  1 mock.simpleMethodWithArgument("2");
37  1 mock.simpleMethodWithArgument("3");
38  1 mock.simpleMethodWithArgument("3");
39   
40  1 verify(mock);
41   
42    }
43   
 
44  1 toggle @Test
45    public void stubWithReturnValue() {
46  1 expect(mock.oneArg("1")).andReturn("A").andStubReturn("B");
47  1 expect(mock.oneArg("2")).andThrow(new IllegalArgumentException())
48    .andStubThrow(new IllegalStateException());
49   
50  1 replay(mock);
51   
52  1 assertEquals("A", mock.oneArg("1"));
53  1 assertEquals("B", mock.oneArg("1"));
54  1 assertEquals("B", mock.oneArg("1"));
55  1 try {
56  1 mock.oneArg("2");
57    } catch (IllegalArgumentException ignored) {
58    }
59  1 assertEquals("B", mock.oneArg("1"));
60  1 try {
61  1 mock.oneArg("2");
62    } catch (IllegalStateException ignored) {
63    }
64  1 assertEquals("B", mock.oneArg("1"));
65  1 try {
66  1 mock.oneArg("2");
67    } catch (IllegalStateException ignored) {
68    }
69  1 verify(mock);
70    }
71   
72    }