KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > easymock > tests > UsageOverloadedDefaultValueTest


1 /*
2  * Copyright (c) 2001-2005 OFFIS. This program is made available under the terms of
3  * the MIT License.
4  */

5 package org.easymock.tests;
6
7 import junit.framework.TestCase;
8
9 import org.easymock.MockControl;
10
11 public class UsageOverloadedDefaultValueTest extends TestCase {
12     MockControl<IMethods> control;
13
14     IMethods mock;
15
16     protected void setUp() {
17         control = MockControl.createControl(IMethods.class);
18         mock = control.getMock();
19     }
20
21     public void testOverloading() {
22
23         mock.oneArgumentMethod(true);
24         control.setReturnValue("true");
25         control.setDefaultReturnValue("false");
26
27         mock.oneArgumentMethod((byte) 0);
28         control.setReturnValue("byte 0");
29         control.setDefaultReturnValue("byte 1");
30
31         mock.oneArgumentMethod((short) 0);
32         control.setReturnValue("short 0");
33         control.setDefaultReturnValue("short 1");
34
35         mock.oneArgumentMethod((char) 0);
36         control.setReturnValue("char 0");
37         control.setDefaultReturnValue("char 1");
38
39         mock.oneArgumentMethod(0);
40         control.setReturnValue("int 0");
41         control.setDefaultReturnValue("int 1");
42
43         mock.oneArgumentMethod((long) 0);
44         control.setReturnValue("long 0");
45         control.setDefaultReturnValue("long 1");
46
47         mock.oneArgumentMethod((float) 0);
48         control.setReturnValue("float 0");
49         control.setDefaultReturnValue("float 1");
50
51         mock.oneArgumentMethod(0.0);
52         control.setReturnValue("double 0");
53         control.setDefaultReturnValue("double 1");
54
55         mock.oneArgumentMethod("Object 0");
56         control.setReturnValue("String 0");
57         control.setDefaultReturnValue("String 1");
58
59         control.replay();
60
61         assertEquals("true", mock.oneArgumentMethod(true));
62         assertEquals("false", mock.oneArgumentMethod(false));
63
64         assertEquals("byte 0", mock.oneArgumentMethod((byte) 0));
65         assertEquals("byte 1", mock.oneArgumentMethod((byte) 1));
66
67         assertEquals("short 0", mock.oneArgumentMethod((short) 0));
68         assertEquals("short 1", mock.oneArgumentMethod((short) 1));
69
70         assertEquals("char 0", mock.oneArgumentMethod((char) 0));
71         assertEquals("char 1", mock.oneArgumentMethod((char) 1));
72
73         assertEquals("int 0", mock.oneArgumentMethod(0));
74         assertEquals("int 1", mock.oneArgumentMethod(1));
75
76         assertEquals("long 0", mock.oneArgumentMethod((long) 0));
77         assertEquals("long 1", mock.oneArgumentMethod((long) 1));
78
79         assertEquals("float 0", mock.oneArgumentMethod((float) 0.0));
80         assertEquals("float 1", mock.oneArgumentMethod((float) 1.0));
81
82         assertEquals("double 0", mock.oneArgumentMethod(0.0));
83         assertEquals("double 1", mock.oneArgumentMethod(1.0));
84
85         assertEquals("String 0", mock.oneArgumentMethod("Object 0"));
86         assertEquals("String 1", mock.oneArgumentMethod("Object 1"));
87
88         control.verify();
89     }
90
91     public void testDefaultThrowable() {
92
93         mock.oneArgumentMethod("Object");
94         RuntimeException JavaDoc expected = new RuntimeException JavaDoc();
95         control.setDefaultThrowable(expected);
96
97         control.replay();
98
99         try {
100             mock.oneArgumentMethod("Something else");
101             fail("runtime exception expected");
102         } catch (RuntimeException JavaDoc expectedException) {
103             assertSame(expected, expectedException);
104         }
105     }
106 }
Popular Tags