Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
58   126   8   9,67
0   92   0,14   6
6     1,33  
1    
 
 
  UsageDefaultReturnValueTest       Line # 15 58 8 96,9% 0.96875
 
  (5)
 
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.tests;
6   
7    import static org.easymock.EasyMock.*;
8    import static org.junit.Assert.*;
9   
10    import org.easymock.MockControl;
11    import org.junit.Before;
12    import org.junit.Test;
13   
14    @SuppressWarnings("deprecation")
 
15    public class UsageDefaultReturnValueTest {
16    MockControl<IMethods> control;
17   
18    IMethods mock;
19   
 
20  5 toggle @Before
21    public void setup() {
22  5 control = MockControl.createControl(IMethods.class);
23  5 mock = control.getMock();
24    }
25   
 
26  1 toggle @Test
27    public void defaultReturnValue() {
28  1 mock.threeArgumentMethod(7, "", "test");
29  1 control.setReturnValue("test", 1);
30   
31  1 mock.threeArgumentMethod(8, null, "test2");
32  1 control.setReturnValue("test2", 1);
33   
34  1 Object defaultValue = new Object();
35  1 control.setDefaultReturnValue(defaultValue);
36   
37  1 control.replay();
38  1 assertEquals("test", mock.threeArgumentMethod(7, "", "test"));
39  1 assertEquals("test2", mock.threeArgumentMethod(8, null, "test2"));
40  1 assertSame(defaultValue, mock.threeArgumentMethod(7, new Object(),
41    "test"));
42  1 assertSame(defaultValue, mock.threeArgumentMethod(7, "", "test"));
43  1 assertSame(defaultValue, mock.threeArgumentMethod(8, null, "test"));
44  1 assertSame(defaultValue, mock.threeArgumentMethod(9, null, "test"));
45   
46  1 control.verify();
47    }
48   
 
49  1 toggle @Test
50    public void defaultVoidCallable() {
51   
52  1 mock.twoArgumentMethod(1, 2);
53  1 control.setDefaultVoidCallable();
54   
55  1 mock.twoArgumentMethod(1, 1);
56  1 RuntimeException expected = new RuntimeException();
57  1 control.setThrowable(expected);
58   
59  1 control.replay();
60  1 mock.twoArgumentMethod(2, 1);
61  1 mock.twoArgumentMethod(1, 2);
62  1 mock.twoArgumentMethod(3, 7);
63   
64  1 try {
65  1 mock.twoArgumentMethod(1, 1);
66  0 fail("RuntimeException expected");
67    } catch (RuntimeException actual) {
68  1 assertSame(expected, actual);
69    }
70   
71    }
72   
 
73  1 toggle @Test
74    public void defaultThrowable() {
75  1 mock.twoArgumentMethod(1, 2);
76  1 control.setVoidCallable();
77  1 mock.twoArgumentMethod(1, 1);
78  1 control.setVoidCallable();
79   
80  1 RuntimeException expected = new RuntimeException();
81  1 control.setDefaultThrowable(expected);
82   
83  1 control.replay();
84   
85  1 mock.twoArgumentMethod(1, 2);
86  1 mock.twoArgumentMethod(1, 1);
87  1 try {
88  1 mock.twoArgumentMethod(2, 1);
89  0 fail("RuntimeException expected");
90    } catch (RuntimeException actual) {
91  1 assertSame(expected, actual);
92    }
93    }
94   
 
95  1 toggle @Test
96    public void defaultReturnValueBoolean() {
97  1 mock.booleanReturningMethod(12);
98  1 control.setReturnValue(true);
99  1 control.setDefaultReturnValue(false);
100   
101  1 control.replay();
102   
103  1 assertFalse(mock.booleanReturningMethod(11));
104  1 assertTrue(mock.booleanReturningMethod(12));
105  1 assertFalse(mock.booleanReturningMethod(13));
106   
107  1 control.verify();
108    }
109   
 
110  1 toggle @Test
111    public void returnValueAndDefaultReturnValue() throws Exception {
112   
113  1 mock.oneArg("");
114   
115  1 expectLastCall().andReturn("1");
116  1 control.setDefaultReturnValue("2");
117   
118  1 control.replay();
119   
120  1 assertEquals("1", mock.oneArg(""));
121  1 assertEquals("2", mock.oneArg(""));
122  1 assertEquals("2", mock.oneArg("X"));
123   
124  1 control.verify();
125    }
126    }