Search in sources :

Example 1 with CONSTRUCTOR_NAME

use of com.tngtech.archunit.core.domain.JavaConstructor.CONSTRUCTOR_NAME in project ArchUnit by TNG.

the class ClassFileImporterLambdaAccessesTest method imports_complex_combination_of_lambda_accesses_to_nested_class.

@Test
public void imports_complex_combination_of_lambda_accesses_to_nested_class() {
    @SuppressWarnings("unused")
    class Caller {

        private Target target;

        void call() {
            Supplier<Supplier<Supplier<Target>>> quiteNestedConstructorCallSupplier = () -> () -> Target::new;
            Function<String, Supplier<Supplier<Supplier<Target>>>> quiteNestedMethodCallSupplier = s -> () -> () -> () -> target.inner.method(s);
            Supplier<Supplier<Supplier<String>>> quiteNestedFieldSupplier = () -> () -> () -> target.inner.field;
        }

        class Target {

            final Inner inner = new Inner();

            class Inner {

                String field;

                Target method(String s) {
                    return Target.this;
                }
            }
        }
    }
    JavaClasses classes = new ClassFileImporter().importClasses(Caller.class, Caller.Target.class);
    Set<JavaAccess<?>> accesses = classes.get(Caller.class).getAccessesFromSelf();
    assertThatAccesses(accesses).contain(access().fromOrigin(Caller.class, "call").toTarget(Caller.Target.class, CONSTRUCTOR_NAME)).contain(access().fromOrigin(Caller.class, "call").toTarget(Caller.Target.Inner.class, "method")).contain(access().fromOrigin(Caller.class, "call").toTarget(Caller.Target.Inner.class, "field"));
}
Also used : AccessesAssertion.access(com.tngtech.archunit.testutil.assertion.AccessesAssertion.access) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod) RunWith(org.junit.runner.RunWith) DataProviders.$(com.tngtech.java.junit.dataprovider.DataProviders.$) MethodCallTarget(com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) JavaClassDescriptorImporterTestUtils.isLambdaMethodName(com.tngtech.archunit.core.importer.JavaClassDescriptorImporterTestUtils.isLambdaMethodName) Assertions.assertThatCall(com.tngtech.archunit.testutil.Assertions.assertThatCall) Assertions.assertThatAccesses(com.tngtech.archunit.testutil.Assertions.assertThatAccesses) CONSTRUCTOR_NAME(com.tngtech.archunit.core.domain.JavaConstructor.CONSTRUCTOR_NAME) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Assertions.assertThat(com.tngtech.archunit.testutil.Assertions.assertThat) Utils.namesOf(com.tngtech.archunit.core.domain.properties.HasName.Utils.namesOf) JavaAccess(com.tngtech.archunit.core.domain.JavaAccess) Collectors.toSet(java.util.stream.Collectors.toSet) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) DataProviders.$$(com.tngtech.java.junit.dataprovider.DataProviders.$$) Predicate(java.util.function.Predicate) JavaMethodCall(com.tngtech.archunit.core.domain.JavaMethodCall) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) JavaConstructorCall(com.tngtech.archunit.core.domain.JavaConstructorCall) Test(org.junit.Test) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Formatters.formatNamesOf(com.tngtech.archunit.core.domain.Formatters.formatNamesOf) Consumer(java.util.function.Consumer) JavaMethodReference(com.tngtech.archunit.core.domain.JavaMethodReference) Assertions.assertThatAccess(com.tngtech.archunit.testutil.Assertions.assertThatAccess) Condition(org.assertj.core.api.Condition) JavaFieldAccess(com.tngtech.archunit.core.domain.JavaFieldAccess) JavaConstructorReference(com.tngtech.archunit.core.domain.JavaConstructorReference) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) MethodCallTarget(com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget) Supplier(java.util.function.Supplier) JavaAccess(com.tngtech.archunit.core.domain.JavaAccess) Test(org.junit.Test)

Aggregations

Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 MethodCallTarget (com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget)1 Formatters.formatNamesOf (com.tngtech.archunit.core.domain.Formatters.formatNamesOf)1 JavaAccess (com.tngtech.archunit.core.domain.JavaAccess)1 JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)1 CONSTRUCTOR_NAME (com.tngtech.archunit.core.domain.JavaConstructor.CONSTRUCTOR_NAME)1 JavaConstructorCall (com.tngtech.archunit.core.domain.JavaConstructorCall)1 JavaConstructorReference (com.tngtech.archunit.core.domain.JavaConstructorReference)1 JavaFieldAccess (com.tngtech.archunit.core.domain.JavaFieldAccess)1 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)1 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)1 JavaMethodReference (com.tngtech.archunit.core.domain.JavaMethodReference)1 Utils.namesOf (com.tngtech.archunit.core.domain.properties.HasName.Utils.namesOf)1 JavaClassDescriptorImporterTestUtils.isLambdaMethodName (com.tngtech.archunit.core.importer.JavaClassDescriptorImporterTestUtils.isLambdaMethodName)1 Assertions.assertThat (com.tngtech.archunit.testutil.Assertions.assertThat)1 Assertions.assertThatAccess (com.tngtech.archunit.testutil.Assertions.assertThatAccess)1 Assertions.assertThatAccesses (com.tngtech.archunit.testutil.Assertions.assertThatAccesses)1 Assertions.assertThatCall (com.tngtech.archunit.testutil.Assertions.assertThatCall)1 AccessesAssertion.access (com.tngtech.archunit.testutil.assertion.AccessesAssertion.access)1