use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ClassGraphCreator method createFieldAccessesFor.
@Override
public Set<JavaFieldAccess> createFieldAccessesFor(JavaCodeUnit codeUnit, Set<TryCatchBlockBuilder> tryCatchBlockBuilders) {
ImmutableSet.Builder<JavaFieldAccess> result = ImmutableSet.builder();
for (FieldAccessRecord record : processedFieldAccessRecords.get(codeUnit)) {
JavaFieldAccess access = accessBuilderFrom(new JavaFieldAccessBuilder(), record).withAccessType(record.getAccessType()).build();
result.add(access);
handlePossibleTryBlockAccess(tryCatchBlockBuilders, record, access);
}
return result.build();
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class FieldAccessConditionTest method FieldGetAccessCondition_only_satisfied_on_get_field.
@Test
public void FieldGetAccessCondition_only_satisfied_on_get_field() {
JavaFieldAccess getAccess = accessFromCallerToTargetWithType(GET);
FieldGetAccessCondition getFieldCondition = new FieldGetAccessCondition(target(name(getAccess.getTarget().getName())));
assertSatisfiedWithMessage(getFieldCondition, getAccess, "gets");
JavaFieldAccess setAccess = accessFromCallerToTargetWithType(SET);
getFieldCondition = new FieldGetAccessCondition(target(name(setAccess.getTarget().getName())));
assertViolatedWithMessage(getFieldCondition, setAccess, "sets");
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class FieldAccessConditionTest method FieldSetAccessCondition_only_satisfied_on_set_field.
@Test
public void FieldSetAccessCondition_only_satisfied_on_set_field() {
JavaFieldAccess setAccess = accessFromCallerToTargetWithType(SET);
FieldSetAccessCondition setFieldCondition = new FieldSetAccessCondition(target(name(setAccess.getTarget().getName())));
assertSatisfiedWithMessage(setFieldCondition, setAccess, "sets");
JavaFieldAccess getAccess = accessFromCallerToTargetWithType(GET);
setFieldCondition = new FieldSetAccessCondition(target(name(getAccess.getTarget().getName())));
assertViolatedWithMessage(setFieldCondition, getAccess, "gets");
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ViolationHandlingTest method multiple_accesses_necessary_for_violation_are_reported_together.
@Test
public void multiple_accesses_necessary_for_violation_are_reported_together() {
EvaluationResult result = classes().should().accessField(Target.class, "notExisting").evaluate(importClasses(Origin.class, Target.class));
FieldAccessRecorder fieldAccessRecorder = new FieldAccessRecorder();
result.handleViolations(fieldAccessRecorder);
assertThat(fieldAccessRecorder.getRecords()).as("number of violations").hasSize(1);
ReportedViolation<JavaFieldAccess> reportedViolation = getOnlyElement(fieldAccessRecorder.getRecords());
assertThatAccesses(reportedViolation.accesses).contain(accessToTargetField("fieldOne")).contain(accessToTargetField("fieldTwo")).contain(accessToTargetField("fieldThree"));
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method fields_know_their_accesses.
@Test
public void fields_know_their_accesses() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/dependents"));
JavaClass classHoldingDependencies = classes.get(ClassHoldingDependencies.class);
JavaClass firstClassWithDependency = classes.get(FirstClassWithDependency.class);
JavaClass secondClassWithDependency = classes.get(SecondClassWithDependency.class);
Set<JavaFieldAccess> accesses = classHoldingDependencies.getField("someInt").getAccessesToSelf();
Set<JavaFieldAccess> expected = ImmutableSet.<JavaFieldAccess>builder().addAll(getByName(classHoldingDependencies.getFieldAccessesFromSelf(), "someInt")).addAll(getByName(firstClassWithDependency.getFieldAccessesFromSelf(), "someInt")).addAll(getByName(secondClassWithDependency.getFieldAccessesFromSelf(), "someInt")).build();
assertThat(accesses).as("Field Accesses to someInt").isEqualTo(expected);
}
Aggregations