Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
29   86   7   4,14
0   60   0,24   7
7     1  
1    
 
 
  CallbackAndArgumentsTest       Line # 15 29 7 100% 1.0
 
  (3)
 
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.IAnswer;
11    import org.easymock.tests.IMethods;
12    import org.junit.Before;
13    import org.junit.Test;
14   
 
15    public class CallbackAndArgumentsTest {
16   
17    private IMethods mock;
18   
 
19  3 toggle @Before
20    public void setUp() {
21  3 mock = createStrictMock(IMethods.class);
22    }
23   
 
24  1 toggle @Test
25    public void callbackGetsArguments() {
26   
27  1 final StringBuffer buffer = new StringBuffer();
28   
29  1 mock.simpleMethodWithArgument((String) notNull());
30  1 expectLastCall().andAnswer(new IAnswer<Object>() {
 
31  2 toggle public Object answer() {
32  2 buffer.append((String) getCurrentArguments()[0]);
33  2 return null;
34    }
35    }).times(2);
36   
37  1 replay(mock);
38   
39  1 mock.simpleMethodWithArgument("1");
40  1 mock.simpleMethodWithArgument("2");
41   
42  1 verify(mock);
43   
44  1 assertEquals("12", buffer.toString());
45    }
46   
 
47  1 toggle @Test(expected = IllegalStateException.class)
48    public void currentArgumentsFailsOutsideCallbacks() {
49  1 getCurrentArguments();
50    }
51   
 
52  1 toggle @Test
53    public void callbackGetsArgumentsEvenIfAMockCallsAnother() {
54   
55  1 final StringBuffer buffer = new StringBuffer();
56   
57  1 final IMethods mock2 = createStrictMock(IMethods.class);
58  1 mock2.simpleMethod();
59  1 expectLastCall().andAnswer(new IAnswer<Object>() {
 
60  2 toggle public Object answer() {
61    // empty, only needed to force deletion of arguments
62  2 return null;
63    }
64    }).times(2);
65   
66  1 mock.simpleMethodWithArgument((String) notNull());
67  1 expectLastCall().andAnswer(new IAnswer<Object>() {
 
68  2 toggle public Object answer() {
69  2 mock2.simpleMethod();
70  2 buffer.append((String) getCurrentArguments()[0]);
71  2 return null;
72    }
73    }).times(2);
74   
75  1 replay(mock);
76  1 replay(mock2);
77   
78  1 mock.simpleMethodWithArgument("1");
79  1 mock.simpleMethodWithArgument("2");
80   
81  1 verify(mock);
82  1 verify(mock2);
83   
84  1 assertEquals("12", buffer.toString());
85    }
86    }