Search in sources :

Example 21 with JavaFieldAccess

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

the class ClassFileImporterLambdaAccessesTest method imports_field_access_from_lambda_without_parameter.

@Test
public void imports_field_access_from_lambda_without_parameter() {
    class Target {
    }
    @SuppressWarnings("unused")
    class Caller {

        Target target;

        Consumer<Target> call() {
            return (target) -> this.target = target;
        }
    }
    JavaClasses classes = new ClassFileImporter().importClasses(Target.class, Caller.class);
    JavaFieldAccess access = getOnlyElement(filterOriginByName(classes.get(Caller.class).getFieldAccessesFromSelf(), "call"));
    assertThatAccess(access).isFrom("call").isTo(Caller.class, "target");
}
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) JavaFieldAccess(com.tngtech.archunit.core.domain.JavaFieldAccess) MethodCallTarget(com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 22 with JavaFieldAccess

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

the class FieldAccessConditionTest method FieldAccessCondition_satisfied_on_both_get_and_set_field.

@Test
public void FieldAccessCondition_satisfied_on_both_get_and_set_field() {
    JavaFieldAccess setAccess = accessFromCallerToTargetWithType(SET);
    FieldAccessCondition setFieldCondition = new FieldAccessCondition(target(name(setAccess.getTarget().getName())));
    assertSatisfiedWithMessage(setFieldCondition, setAccess, "sets");
    JavaFieldAccess getAccess = accessFromCallerToTargetWithType(GET);
    setFieldCondition = new FieldAccessCondition(target(name(getAccess.getTarget().getName())));
    assertSatisfiedWithMessage(setFieldCondition, getAccess, "gets");
}
Also used : JavaFieldAccess(com.tngtech.archunit.core.domain.JavaFieldAccess) Test(org.junit.Test)

Aggregations

JavaFieldAccess (com.tngtech.archunit.core.domain.JavaFieldAccess)22 Test (org.junit.Test)21 JavaClass (com.tngtech.archunit.core.domain.JavaClass)16 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)10 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 FieldAccessTarget (com.tngtech.archunit.core.domain.AccessTarget.FieldAccessTarget)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 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 JavaField (com.tngtech.archunit.core.domain.JavaField)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 FieldAccessRecord (com.tngtech.archunit.core.importer.AccessRecord.FieldAccessRecord)1 FieldAccessTargetBuilder (com.tngtech.archunit.core.importer.DomainBuilders.FieldAccessTargetBuilder)1