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