Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
31   87   10   5,17
0   67   0,32   3
6     1,67  
2    
 
 
  CallbackTest       Line # 15 27 6 100% 1.0
  CallbackTest.Callback       Line # 19 4 4 87,5% 0.875
 
  (1)
 
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 CallbackTest {
16   
17    private IMethods mock;
18   
 
19    private static class Callback<T> implements IAnswer<T> {
20    private int callCount;
21   
22    private T result;
23   
 
24  3 toggle public Callback(T result) {
25  3 this.result = result;
26    }
27   
 
28  0 toggle public void run() {
29    }
30   
 
31  3 toggle public int getCallCount() {
32  3 return callCount;
33    }
34   
 
35  5 toggle public T answer() throws Throwable {
36  5 callCount++;
37  5 return result;
38    }
39    }
40   
 
41  1 toggle @Before
42    public void setUp() {
43  1 mock = createStrictMock(IMethods.class);
44    }
45   
 
46  1 toggle @Test
47    public void callback() {
48  1 Callback<String> c1 = new Callback<String>("1");
49  1 Callback<Object> c2 = new Callback<Object>(null);
50  1 Callback<Object> c3 = new Callback<Object>(null);
51   
52  1 expect(mock.oneArg("2")).andAnswer(c1).times(2);
53  1 mock.simpleMethodWithArgument("One");
54  1 expectLastCall().andAnswer(c2);
55  1 mock.simpleMethodWithArgument("Two");
56  1 expectLastCall().andAnswer(c3).times(2);
57   
58  1 replay(mock);
59   
60  1 mock.oneArg("2");
61  1 mock.oneArg("2");
62  1 try {
63  1 mock.oneArg("2");
64    } catch (AssertionError ignored) {
65    }
66  1 try {
67  1 mock.simpleMethodWithArgument("Two");
68    } catch (AssertionError ignored) {
69    }
70  1 mock.simpleMethodWithArgument("One");
71  1 try {
72  1 mock.simpleMethodWithArgument("One");
73    } catch (AssertionError ignored) {
74    }
75  1 mock.simpleMethodWithArgument("Two");
76  1 mock.simpleMethodWithArgument("Two");
77  1 try {
78  1 mock.simpleMethodWithArgument("Two");
79    } catch (AssertionError ignored) {
80    }
81  1 verify(mock);
82   
83  1 assertEquals(2, c1.getCallCount());
84  1 assertEquals(1, c2.getCallCount());
85  1 assertEquals(2, c3.getCallCount());
86    }
87    }