use of com.tngtech.archunit.core.importer.DomainBuilders.FieldAccessTargetBuilder in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_shadowed_and_superclass_field_access.
@Test
public void imports_shadowed_and_superclass_field_access() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/hierarchicalfieldaccess"));
JavaClass classThatAccessesFieldOfSuperclass = classes.get(AccessToSuperAndSubclassField.class);
JavaClass superclassWithAccessedField = classes.get(SuperclassWithAccessedField.class);
JavaClass subClassWithAccessedField = classes.get(SubclassWithAccessedField.class);
Set<JavaFieldAccess> accesses = classThatAccessesFieldOfSuperclass.getFieldAccessesFromSelf();
assertThat(accesses).hasSize(2);
JavaField field = superclassWithAccessedField.getField("field");
FieldAccessTarget expectedSuperclassFieldAccess = new FieldAccessTargetBuilder().withOwner(subClassWithAccessedField).withName(field.getName()).withType(field.getRawType()).withMember(() -> Optional.of(field)).build();
assertThatAccess(getOnly(accesses, "field", GET)).isFrom("accessSuperclassField").isTo(expectedSuperclassFieldAccess).inLineNumber(5);
assertThatAccess(getOnly(accesses, "maskedField", GET)).isFrom("accessSubclassField").isTo(subClassWithAccessedField.getField("maskedField")).inLineNumber(9);
}
Aggregations