1 5 package org.easymock.classextension.tests; 6 7 import junit.framework.TestCase; 8 9 import org.easymock.MockControl; 10 import org.easymock.classextension.MockClassControl; 11 12 15 public class MockClassControlTest extends TestCase { 16 17 21 public static class ClassToMock { 22 23 } 24 25 30 public static class ClassToMockWithOverload { 31 32 public boolean equals(Object o) { 33 return false; 34 } 35 36 public int hashCode() { 37 return -1; 38 } 39 40 public String toString() { 41 return "super"; 42 } 43 } 44 45 private MockControl ctrl; 46 47 private Object mock; 48 49 public void setUp() throws Exception { 50 super.setUp(); 51 } 52 53 public void tearDown() throws Exception { 54 super.tearDown(); 55 ctrl = null; 56 mock = null; 57 } 58 59 private void initMock(Class toMock) { 60 ctrl = MockClassControl.createControl(toMock); 61 mock = ctrl.getMock(); 62 } 63 64 public void testEquals() { 65 testEquals(ClassToMock.class); 66 } 67 68 public void testEquals_WithOverload() { 69 testEquals(ClassToMockWithOverload.class); 70 } 71 72 75 public void testEquals(Class toMock) { 76 initMock(toMock); 77 assertEquals(mock, mock); 78 ctrl.replay(); 79 assertEquals(mock, mock); 80 } 81 82 public void testHashCode() { 83 testHashCode(ClassToMock.class); 84 } 85 86 public void testHashCode_WithOverload() { 87 testHashCode(ClassToMockWithOverload.class); 88 } 89 90 94 private void testHashCode(Class toMock) { 95 initMock(toMock); 96 int code = mock.hashCode(); 97 ctrl.replay(); 98 assertEquals(code, mock.hashCode()); 99 } 100 101 public void testToString() { 102 testToString(ClassToMock.class); 103 } 104 105 public void testToString_WithOverload() { 106 testToString(ClassToMockWithOverload.class); 107 } 108 109 112 private void testToString(Class toMock) { 113 initMock(toMock); 114 String expectedValue = "EasyMock for " + toMock.toString(); 115 assertEquals(expectedValue, mock.toString()); 116 ctrl.replay(); 117 assertEquals(expectedValue, mock.toString()); 118 } 119 } 120 | Popular Tags |