1 46 package org.codehaus.groovy.runtime; 47 48 import junit.framework.TestCase; 49 50 54 public class MethodKeyTest extends TestCase { 55 56 public void testDefaultImplementation() throws Exception { 57 MethodKey a = new DefaultMethodKey("foo", new Class [] { Object .class, Integer .class }); 58 MethodKey a2 = new DefaultMethodKey("foo", new Class [] { Object .class, Integer .class }); 59 MethodKey b = new DefaultMethodKey("foo", new Class [] { Object .class }); 60 MethodKey c = new DefaultMethodKey("bar", new Class [] { Object .class, Integer .class }); 61 62 assertCompare(a, a, true); 63 assertCompare(a, a2, true); 64 assertCompare(b, b, true); 65 66 assertCompare(a, b, false); 67 assertCompare(a, c, false); 68 assertCompare(b, c, false); 69 } 70 71 public void testTemporaryImplementation() throws Exception { 72 MethodKey a = new DefaultMethodKey("foo", new Class [] { Object .class, Integer .class }); 73 MethodKey a2 = new TemporaryMethodKey("foo", new Object [] { new Object (), new Integer (1) }); 74 MethodKey b = new TemporaryMethodKey("foo", new Object [] { new Object () }); 75 MethodKey c = new TemporaryMethodKey("bar", new Object [] { new Object (), new Integer (1) }); 76 77 assertCompare(a, a, true); 78 assertCompare(a, a2, true); 79 assertCompare(b, b, true); 80 81 assertCompare(a, b, false); 82 assertCompare(a, c, false); 83 assertCompare(b, c, false); 84 } 85 86 protected void assertCompare(Object a, Object b, boolean expected) { 87 assertEquals("Compare " + a + " to " + b, expected, a.equals(b)); 88 if (expected) { 89 assertEquals("hashCode " + a + " to " + b, a.hashCode(), b.hashCode()); 90 } 91 } 92 } | Popular Tags |