DependencyKey { public static DependencyKey<?> fromField(Field field) { return new DependencyKey<>(TypeToken.of(field.getGenericType()), ReflectUtil.findQualifierAnnotation(field)); } private  DependencyKey(TypeToken<V> typeToken, @Nullable Annotation identityAnnotation); static DependencyKey<T> of(Class<T> clazz); static DependencyKey<T> of(TypeToken<T> typeToken); static DependencyKey<T> of(Class<T> clazz, @Nullable Annotation identityAnnotation); static DependencyKey<T> of(TypeToken<T> typeToken, @Nullable Annotation identityAnnotation); static DependencyKey<?> fromField(Field field); static DependencyKey<?> fromField(Field field, TypeToken<?> context); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); final TypeToken<V> typeToken; final @Nullable Annotation identityAnnotation; }
@Test public void testKeyEquality() { DependencyKey key1 = DependencyKey.fromField(prop("testProp1")); DependencyKey key2 = DependencyKey.fromField(prop("testProp2")); DependencyKey key3 = DependencyKey.fromField(prop("testProp3")); DependencyKey key4 = DependencyKey.fromField(prop("testProp4")); DependencyKey key5 = DependencyKey.fromField(prop("testProp5")); assertThat(key1) .isEqualTo(key5) .isNotEqualTo(key2) .isNotEqualTo(key4); assertThat(key2) .isEqualTo(key3) .isNotEqualTo(key4) .isNotEqualTo(key5); }
@Test(expected = MultipleQualifierAnnotationException.class) public void testMultipleQualifiersFailure() { DependencyKey.fromField(prop("badTestProp")); }