AnnotationHandler implements InvocationHandler { @SuppressWarnings("unchecked") public static <T extends Annotation> T create(Class<T> annotationType, Object bean) { return (T) Proxy.newProxyInstance(annotationType.getClassLoader(), new Class<?>[]{annotationType}, new AnnotationHandler(annotationType, bean)); } private  AnnotationHandler(Class<? extends Annotation> annotationType, Object bean); @SuppressWarnings("unchecked") static T create(Class<T> annotationType, Object bean); @Override Object invoke(Object proxy, Method method, Object[] args); boolean annotationEquals(Object proxy, Object other); int annotationHashCode(Object proxy); String annotationToString(Object proxy);  }
@Test public void testIdentityEquals() { Feature feature = createFeature(); FeatureInfo featureInfo1 = AnnotationHandler.create(FeatureInfo.class, feature); FeatureInfo featureInfo2 = AnnotationHandler.create(FeatureInfo.class, feature); Assert.assertFalse(featureInfo1 == featureInfo2); Assert.assertEquals(featureInfo1, featureInfo2); }
@Test public void testDeepEquals() { Feature feature1 = createFeature(); Feature feature2 = createFeature(); FeatureInfo featureInfo1 = AnnotationHandler.create(FeatureInfo.class, feature1); FeatureInfo featureInfo2 = AnnotationHandler.create(FeatureInfo.class, feature2); Assert.assertFalse(featureInfo1 == featureInfo2); Assert.assertEquals(featureInfo1, featureInfo2); }
@Test public void testHashCode() { Feature feature1 = createFeature(); Feature feature2 = createFeature(); FeatureInfo featureInfo1 = AnnotationHandler.create(FeatureInfo.class, feature1); FeatureInfo featureInfo2 = AnnotationHandler.create(FeatureInfo.class, feature2); Set<FeatureInfo> set = new HashSet<>(); set.add(featureInfo1); Assert.assertTrue(set.contains(featureInfo1)); Assert.assertTrue(set.contains(featureInfo2)); }
@Test public void testToString() { Feature feature = createFeature(); FeatureInfo featureInfo = AnnotationHandler.create(FeatureInfo.class, feature); String string = featureInfo.toString(); Assert.assertTrue(string.startsWith("@" + FeatureInfo.class.getName() + "[")); Assert.assertTrue(string.contains("name=I can convert a feature to an annotation")); Assert.assertTrue(string.contains("name=I can convert a scenario to an annotation")); }