KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > atest > jmock > ReturnTypeAcceptanceTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package atest.jmock;
4
5 import org.jmock.Mock;
6 import org.jmock.MockObjectTestCase;
7
8
9 public class ReturnTypeAcceptanceTest extends MockObjectTestCase
10 {
11     public interface ReturnTypes
12     {
13         String JavaDoc returnString();
14
15         boolean returnBoolean();
16
17         byte returnByte();
18
19         char returnChar();
20
21         short returnShort();
22
23         int returnInt();
24
25         long returnLong();
26
27         float returnFloat();
28
29         double returnDouble();
30     }
31
32     private Mock mock;
33     private ReturnTypes proxy;
34
35     public void setUp() {
36         mock = mock(ReturnTypes.class, "theMock");
37         proxy = (ReturnTypes)mock.proxy();
38     }
39
40     public void testCanReturnObjectReferences() {
41         String JavaDoc result = new String JavaDoc("RESULT");
42
43         mock.stubs().method("returnString").will(returnValue(result));
44
45         assertSame("should be same result", result, proxy.returnString());
46     }
47
48     public void testCanReturnBooleanValues() {
49         mock.stubs().method("returnBoolean").will(returnValue(true));
50         assertTrue("should be true", proxy.returnBoolean());
51
52         mock.stubs().method("returnBoolean").will(returnValue(false));
53         assertFalse("should be false", proxy.returnBoolean());
54     }
55
56     public void testCanReturnByteValues() {
57         byte result = 123;
58
59         mock.stubs().method("returnByte").will(returnValue(result));
60
61         assertEquals("should be same result", result, proxy.returnByte());
62     }
63
64     public void testCanReturnCharValues() {
65         char result = '\u1234';
66
67         mock.stubs().method("returnChar").will(returnValue(result));
68
69         assertEquals("should be same result", result, proxy.returnChar());
70     }
71
72     public void testCanReturnShortValues() {
73         short result = 12345;
74
75         mock.stubs().method("returnShort").will(returnValue(result));
76
77         assertEquals("should be same result", result, proxy.returnShort());
78     }
79
80     public void testCanReturnIntValues() {
81         int result = 1234567890;
82
83         mock.stubs().method("returnInt").will(returnValue(result));
84
85         assertEquals("should be same result", result, proxy.returnInt());
86     }
87
88     public void testCanReturnLongValues() {
89         long result = 1234567890124356789L;
90
91         mock.stubs().method("returnLong").will(returnValue(result));
92
93         assertEquals("should be same result", result, proxy.returnLong());
94     }
95
96     public void testCanReturnFloatValues() {
97         float result = 12345.67890f;
98
99         mock.stubs().method("returnFloat").will(returnValue(result));
100
101         assertEquals("should be same result", result, proxy.returnFloat(), 0.0);
102     }
103
104     public void testCanReturnDoubleValues() {
105         double result = 1234567890.1234567890;
106
107         mock.stubs().method("returnDouble").will(returnValue(result));
108
109         assertEquals("should be same result", result, proxy.returnDouble(), 0.0);
110     }
111 }
112
Popular Tags