EqualsInterceptor { @RuntimeType public static Object intercept(@This Object thiz, @Argument(0) Object other, @FieldValue("bean") Object bean) throws IllegalAccessException, NoSuchFieldException { if (thiz == other) { return true; } else if (other instanceof EnhancedProxy) { return bean.equals(ReflectionUtils.getValue(other, "bean")); } else { return bean.equals(other); } } private  EqualsInterceptor(); @RuntimeType static Object intercept(@This Object thiz, @Argument(0) Object other, @FieldValue("bean") Object bean);  }
@Test public void testProxyEqualsTarget() throws Exception { final ClassA target = new ClassA(); final Object proxy = EnhancedProxy.create(target, null); final boolean isEqual = (boolean) EqualsInterceptor.intercept(proxy, target, target); assertTrue(isEqual); }
@Test public void testProxyEqualsSelf() throws Exception { final ClassA target = new ClassA(); final Object proxy = EnhancedProxy.create(target, null); final boolean isEqual = (boolean) EqualsInterceptor.intercept(proxy, proxy, target); assertTrue(isEqual); }
@Test public void testProxyEqualsOtherProxyForSameTarget() throws Exception { final ClassA target = new ClassA(); final Object proxy1 = EnhancedProxy.create(target, null); final Object proxy2 = EnhancedProxy.create(target, null); final boolean isEqual = (boolean) EqualsInterceptor.intercept(proxy1, proxy2, target); assertTrue(isEqual); }
@Test public void testProxyForOneTargetIsNotEqualsToOtherTarget() throws Exception { final ClassA target = new ClassA(); final Object proxy = EnhancedProxy.create(target, null); final boolean isEqual = (boolean) EqualsInterceptor.intercept(proxy, new ClassA(), target); assertFalse(isEqual); }
@Test public void testProxyForOneTargetIsNotEqualsProxyForOtherTarget() throws Exception { final ClassA target1 = new ClassA(); final Object proxy1 = EnhancedProxy.create(target1, null); final ClassA target2 = new ClassA(); final Object proxy2 = EnhancedProxy.create(target2, null); final boolean isEqual = (boolean) EqualsInterceptor.intercept(proxy1, proxy2, target1); assertFalse(isEqual); }