@Test public void sameMethodState_SameHashCode() { MethodId method1 = createMethodeOne(); int hash1 = method1.hashCode(); MethodId method2 = createMethodeOne(); int hash2 = method2.hashCode(); assertTrue(hash1 == hash2); }
/** * Declares a method or constructor. * * @param flags a bitwise combination of {@link Modifier#PUBLIC}, {@link Modifier#PRIVATE}, {@link * Modifier#PROTECTED}, {@link Modifier#STATIC}, {@link Modifier#FINAL} and {@link * Modifier#SYNCHRONIZED}. * <p><strong>Warning:</strong> the {@link Modifier#SYNCHRONIZED} flag is insufficient to * generate a synchronized method. You must also use {@link Code#monitorEnter} and {@link * Code#monitorExit} to acquire a monitor. */ public Code declare(MethodId<?, ?> method, int flags) { TypeDeclaration typeDeclaration = getTypeDeclaration(method.declaringType); if (typeDeclaration.methods.containsKey(method)) { throw new IllegalStateException("already declared: " + method); } int supportedFlags = Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL | Modifier.SYNCHRONIZED; if ((flags & ~supportedFlags) != 0) { throw new IllegalArgumentException("Unexpected flag: " + Integer.toHexString(flags)); } // replace the SYNCHRONIZED flag with the DECLARED_SYNCHRONIZED flag if ((flags & Modifier.SYNCHRONIZED) != 0) { flags = (flags & ~Modifier.SYNCHRONIZED) | AccessFlags.ACC_DECLARED_SYNCHRONIZED; } if (method.isConstructor()) { flags |= ACC_CONSTRUCTOR; } MethodDeclaration methodDeclaration = new MethodDeclaration(method, flags); typeDeclaration.methods.put(method, methodDeclaration); return methodDeclaration.code; }
@Test public void differentType_ShouldBeUnequal() { String myString = " bogus"; MethodId method1 = createMethodeOne(); assertTrue("different type, should be unequal", !method1.equals(myString)); }
@Test public void fallBackShouldNotBeEqual() { MethodId method1 = createMethodeOne(); MethodId fallBack = method1.getFallBack(); assertNotEquals("fallBack should be different", method1, fallBack); }
@Test public void differentNameSpace2State_UnEqual() { MethodId method1 = createMethodeOne(); MethodId method2 = new MethodId("module.dll", "namespace2", "class", "method"); assertFalse(method1.equals(method2)); }
@Test public void sameMethodState_Equal() { MethodId method1 = createMethodeOne(); MethodId method2 = createMethodeOne(); assertTrue(method1.equals(method2)); }