KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Method JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import org.easymock.MockControl;
12 import org.easymock.internal.ObjectMethodsFilter;
13
14 public class ObjectMethodsTest extends TestCase {
15     private MockControl<EmptyInterface> control;
16
17     private EmptyInterface mock;
18
19     private interface EmptyInterface {
20     }
21
22     protected void setUp() {
23         control = MockControl.createControl(EmptyInterface.class);
24         mock = control.getMock();
25     }
26
27     public void testEqualsBeforeActivation() {
28         assertEquals(mock, mock);
29         assertTrue(!mock.equals(null));
30     }
31
32     public void testEqualsAfterActivation() {
33         control.replay();
34         assertEquals(mock, mock);
35         assertTrue(!mock.equals(null));
36     }
37
38     public void testHashCode() {
39         int hashCodeBeforeActivation = mock.hashCode();
40         control.replay();
41         int hashCodeAfterActivation = mock.hashCode();
42         assertEquals(hashCodeBeforeActivation, hashCodeAfterActivation);
43     }
44
45     public void testToStringBeforeActivation() {
46         assertEquals("EasyMock for " + EmptyInterface.class.toString(), mock
47                 .toString());
48     }
49
50     public void testToStringAfterActivation() {
51         control.replay();
52         assertEquals("EasyMock for " + EmptyInterface.class.toString(), mock
53                 .toString());
54     }
55
56     private static class MockedClass {
57     }
58
59     private static class DummyProxy extends MockedClass {
60     }
61
62     // if no interface is found, ObjectMethodFilter should use the
63
// superclasses' name. This is needed for the class extension.
64
// We have to find a way to find that special case there...
65
public void testToStringForClasses() throws Throwable JavaDoc {
66         ObjectMethodsFilter filter = new ObjectMethodsFilter(null);
67         Method JavaDoc toString = Object JavaDoc.class.getMethod("toString", new Class JavaDoc[0]);
68         assertEquals("EasyMock for " + MockedClass.class.toString(), filter
69                 .invoke(new DummyProxy(), toString, new Object JavaDoc[0]));
70     }
71
72 }
73
Popular Tags