1 5 package org.easymock.tests; 6 7 import java.lang.reflect.Method ; 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 public void testToStringForClasses() throws Throwable { 66 ObjectMethodsFilter filter = new ObjectMethodsFilter(null); 67 Method toString = Object .class.getMethod("toString", new Class [0]); 68 assertEquals("EasyMock for " + MockedClass.class.toString(), filter 69 .invoke(new DummyProxy(), toString, new Object [0])); 70 } 71 72 } 73 | Popular Tags |