Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
88   196   15   6,29
0   144   0,17   14
14     1,07  
1    
 
  UsageVarargTest       Line # 32 88 0% 15 1 99% 0.99019605
 
  (24)
 
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 java.lang.reflect.InvocationHandler;
23    import java.lang.reflect.Method;
24    import java.lang.reflect.Proxy;
25   
26    import org.junit.Before;
27    import org.junit.Test;
28   
29    /**
30    * @author OFFIS, Tammo Freese
31    */
 
32    public class UsageVarargTest {
33   
34    private IVarArgs mock;
35   
 
36  24 toggle @Before
37    public void setup() {
38  24 mock = createStrictMock(IVarArgs.class);
39    }
40   
 
41  2 toggle @Test
42    public void varargObjectAccepted() {
43  2 mock.withVarargsString(1, "1");
44  2 mock.withVarargsString(2, "1", "2");
45  2 mock.withVarargsString(2, "1", "2");
46  2 mock.withVarargsObject(3, "1");
47  2 mock.withVarargsObject(4, "1", "2");
48   
49  2 replay(mock);
50  2 mock.withVarargsString(1, "1");
51  2 mock.withVarargsString(2, "1", "2");
52  2 mock.withVarargsString(2, "1", "2");
53  2 mock.withVarargsObject(3, "1");
54  2 mock.withVarargsObject(4, "1", "2");
55  2 verify(mock);
56    }
57   
 
58  2 toggle @Test
59    public void varargBooleanAccepted() {
60  2 mock.withVarargsBoolean(1, true);
61  2 mock.withVarargsBoolean(2, true, false);
62   
63  2 replay(mock);
64  2 mock.withVarargsBoolean(1, true);
65  2 mock.withVarargsBoolean(2, true, false);
66  2 verify(mock);
67    }
68   
 
69  2 toggle @Test
70    public void varargByteAccepted() {
71  2 mock.withVarargsByte(1, (byte) 1);
72  2 mock.withVarargsByte(2, (byte) 1, (byte) 2);
73   
74  2 replay(mock);
75  2 mock.withVarargsByte(1, (byte) 1);
76  2 mock.withVarargsByte(2, (byte) 1, (byte) 2);
77  2 verify(mock);
78    }
79   
 
80  2 toggle @Test
81    public void varargCharAccepted() {
82  2 mock.withVarargsChar(1, 'a');
83  2 mock.withVarargsChar(1, 'a', 'b');
84   
85  2 replay(mock);
86  2 mock.withVarargsChar(1, 'a');
87  2 mock.withVarargsChar(1, 'a', 'b');
88  2 verify(mock);
89    }
90   
 
91  2 toggle @Test
92    public void varargDoubleAccepted() {
93  2 mock.withVarargsDouble(1, 1.0d);
94  2 mock.withVarargsDouble(1, 1.0d, 2.0d);
95   
96  2 replay(mock);
97  2 mock.withVarargsDouble(1, 1.0d);
98  2 mock.withVarargsDouble(1, 1.0d, 2.0d);
99  2 verify(mock);
100    }
101   
 
102  2 toggle @Test
103    public void varargFloatAccepted() {
104  2 mock.withVarargsFloat(1, 1.0f);
105  2 mock.withVarargsFloat(1, 1.0f, 2.0f);
106   
107  2 replay(mock);
108  2 mock.withVarargsFloat(1, 1.0f);
109  2 mock.withVarargsFloat(1, 1.0f, 2.0f);
110  2 verify(mock);
111    }
112   
 
113  2 toggle @Test
114    public void varargIntAccepted() {
115  2 mock.withVarargsInt(1, 1);
116  2 mock.withVarargsInt(1, 1, 2);
117   
118  2 replay(mock);
119  2 mock.withVarargsInt(1, 1);
120  2 mock.withVarargsInt(1, 1, 2);
121  2 verify(mock);
122    }
123   
 
124  2 toggle @Test
125    public void varargLongAccepted() {
126  2 mock.withVarargsLong(1, (long) 1);
127  2 mock.withVarargsLong(1, 1, 2);
128   
129  2 replay(mock);
130  2 mock.withVarargsLong(1, (long) 1);
131  2 mock.withVarargsLong(1, 1, 2);
132  2 verify(mock);
133    }
134   
 
135  2 toggle @Test
136    public void varargShortAccepted() {
137  2 mock.withVarargsShort(1, (short) 1);
138  2 mock.withVarargsShort(1, (short) 1, (short) 2);
139   
140  2 replay(mock);
141  2 mock.withVarargsShort(1, (short) 1);
142  2 mock.withVarargsShort(1, (short) 1, (short) 2);
143  2 verify(mock);
144    }
145   
 
146  2 toggle @Test
147    public void varargAcceptedIfArrayIsGiven() {
148  2 final IVarArgs object = (IVarArgs) Proxy.newProxyInstance(Thread.currentThread()
149    .getContextClassLoader(), new Class[] { IVarArgs.class }, new InvocationHandler() {
150   
 
151  12 toggle public Object invoke(final Object proxy, final Method method, final Object[] args)
152    throws Throwable {
153  12 return null;
154    }
155    });
156  2 object.withVarargsObject(1);
157  2 object.withVarargsObject(1, (Object) null);
158  2 object.withVarargsObject(1, (Object[]) null);
159  2 object.withVarargsObject(1, new Object[0]);
160  2 object.withVarargsObject(1, false);
161  2 object.withVarargsObject(1, new boolean[] { true, false });
162    }
163   
164    /**
165    * Make sure we can validate any kind of varargs call
166    */
 
167  2 toggle @Test
168    public void allKinds() {
169  2 mock.withVarargsObject(eq(1), aryEq((Object[]) null));
170  2 mock.withVarargsObject(eq(1), isNull());
171  2 mock.withVarargsObject(1, "a", "b");
172  2 mock.withVarargsObject(1, "a", "b");
173  2 mock.withVarargsObject(eq(1), aryEq(new Object[] { "a", "b" }));
174  2 mock.withVarargsObject(1);
175  2 replay(mock);
176  2 mock.withVarargsObject(1, (Object[]) null);
177  2 mock.withVarargsObject(1, (Object) null);
178  2 mock.withVarargsObject(1, "a", "b");
179  2 mock.withVarargsObject(1, new Object[] { "a", "b" });
180  2 mock.withVarargsObject(1, (Object) new Object[] { "a", "b" });
181  2 mock.withVarargsObject(1);
182  2 verify(mock);
183    }
184   
 
185  2 toggle @Test
186    public void differentLength() {
187  2 mock.withVarargsInt(1, 2, 3);
188  2 replay(mock);
189  2 try {
190  2 mock.withVarargsInt(1, 2);
191  0 fail("not the same number of params");
192    } catch (final AssertionError e) {
193   
194    }
195    }
196    }