use of com.tngtech.archunit.core.domain.JavaConstructorReference in project ArchUnit by TNG.
the class ClassFileImporterAutomaticResolutionTest method automatically_resolves_constructor_reference_target_owners.
@Test
public void automatically_resolves_constructor_reference_target_owners() {
@SuppressWarnings("unused")
class Origin {
Supplier<?> resolvesConstructorReferenceTargetOwner() {
return Data_automatically_resolves_constructor_reference_target_owners.Target::new;
}
}
JavaClass javaClass = ImporterWithAdjustedResolutionRuns.disableAllIterationsExcept(MAX_ITERATIONS_FOR_ACCESSES_TO_TYPES_PROPERTY_NAME).importClass(Origin.class);
JavaConstructorReference reference = getOnlyElement(javaClass.getMethod("resolvesConstructorReferenceTargetOwner").getConstructorReferencesFromSelf());
assertThat(reference.getTargetOwner()).isFullyImported(true);
}
use of com.tngtech.archunit.core.domain.JavaConstructorReference in project ArchUnit by TNG.
the class ClassFileImporterCodeUnitReferencesTest method creates_correct_description_for_references.
@Test
public void creates_correct_description_for_references() {
JavaClasses javaClasses = new ClassFileImporter().importClasses(Origin.class, Target.class);
JavaClass originClass = javaClasses.get(Origin.class);
JavaClass targetClass = javaClasses.get(Target.class);
JavaMethod constructorReferenceOrigin = originClass.getMethod("referencesConstructor");
JavaConstructor targetConstructor = targetClass.getConstructor();
JavaMethod methodReferenceOrigin = originClass.getMethod("referencesMethod");
JavaMethod targetMethod = targetClass.getMethod("call");
JavaConstructorReference constructorReference = getOnlyElement(constructorReferenceOrigin.getConstructorReferencesFromSelf());
assertThat(constructorReference.getDescription()).isEqualTo(String.format("Method <%s> references constructor <%s> in (%s.java:%d)", constructorReferenceOrigin.getFullName(), targetConstructor.getFullName(), Origin.class.getSimpleName(), 9));
JavaMethodReference methodReference = getOnlyElement(originClass.getMethod("referencesMethod").getMethodReferencesFromSelf());
assertThat(methodReference.getDescription()).isEqualTo(String.format("Method <%s> references method <%s> in (%s.java:%d)", methodReferenceOrigin.getFullName(), targetMethod.getFullName(), Origin.class.getSimpleName(), 13));
}
use of com.tngtech.archunit.core.domain.JavaConstructorReference in project ArchUnit by TNG.
the class ClassGraphCreator method createConstructorReferencesFor.
@Override
public Set<JavaConstructorReference> createConstructorReferencesFor(JavaCodeUnit codeUnit, Set<TryCatchBlockBuilder> tryCatchBlockBuilders) {
ImmutableSet.Builder<JavaConstructorReference> result = ImmutableSet.builder();
for (AccessRecord<ConstructorReferenceTarget> record : processedConstructorReferenceRecords.get(codeUnit)) {
JavaConstructorReference constructorReference = accessBuilderFrom(new JavaConstructorReferenceBuilder(), record).build();
result.add(constructorReference);
handlePossibleTryBlockAccess(tryCatchBlockBuilders, record, constructorReference);
}
return result.build();
}
use of com.tngtech.archunit.core.domain.JavaConstructorReference in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method imports_constructor_reference_from_lambda_without_parameter.
@Test
public void imports_constructor_reference_from_lambda_without_parameter() {
@SuppressWarnings("unused")
class Caller {
Supplier<Supplier<Data_of_imports_constructor_reference_from_lambda_without_parameter.Target>> call() {
return () -> Data_of_imports_constructor_reference_from_lambda_without_parameter.Target::new;
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Data_of_imports_constructor_reference_from_lambda_without_parameter.Target.class, Caller.class);
JavaConstructorReference reference = getOnlyElement(classes.get(Caller.class).getConstructorReferencesFromSelf());
assertThatAccess(reference).isFrom("call").isTo(Data_of_imports_constructor_reference_from_lambda_without_parameter.Target.class, CONSTRUCTOR_NAME);
}
Aggregations