KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > expectation > ReturnValueTest


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

3 package test.jmock.expectation;
4
5 import junit.framework.AssertionFailedError;
6 import junit.framework.TestCase;
7 import org.jmock.expectation.ReturnValue;
8
9
10 public class ReturnValueTest extends TestCase
11 {
12     private ReturnValue value;
13
14     protected void setUp() throws Exception JavaDoc {
15         super.setUp();
16         value = new ReturnValue(getName());
17     }
18
19     public void testGetNull() {
20         value.setValue(null);
21         assertTrue(value.getValue() == null);
22     }
23
24     public void testGetValue() {
25         value.setValue(this);
26         assertEquals(this, value.getValue());
27     }
28
29     public void testGetBooleanValue() {
30         value.setValue(true);
31         assertTrue(value.getBooleanValue());
32     }
33
34     public void testIntValue() {
35         value.setValue(13);
36         assertEquals(13, value.getIntValue());
37     }
38
39     public void testLongValue() {
40         long now = System.currentTimeMillis();
41         value.setValue(now);
42         assertEquals(now, value.getLongValue());
43         value.getIntValue();
44     }
45
46     public void testValueNotSet() {
47         try {
48             value.getValue();
49             fail("Error not thrown");
50         }
51         catch (AssertionFailedError e) {
52             assertEquals("The return value \"" + getName() + "\" has not been set.", e.getMessage());
53         }
54     }
55
56 }
57
Popular Tags