Package com.tngtech.archunit.library
Class ProxyRules
java.lang.Object
com.tngtech.archunit.library.ProxyRules
@PublicAPI(usage=ACCESS) public final class ProxyRules extends java.lang.Object
ProxyRules provides a set of general
ArchConditions
and ArchRules
for checking the usage of proxies.-
Method Summary
Modifier and Type Method Description static ArchCondition<JavaClass>
directly_call_other_methods_declared_in_the_same_class_that(DescribedPredicate<? super AccessTarget.MethodCallTarget> predicate)
Returns a condition that matches classes that directly calls other methods declared in the same class that matches the given predicate.static ArchCondition<JavaClass>
directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns a condition that matches classes that directly calls other methods declared in the same class that are annotated with the given annotation.static ArchRule
no_classes_should_directly_call_other_methods_declared_in_the_same_class_that(DescribedPredicate<? super AccessTarget.MethodCallTarget> predicate)
Returns a rule that checks that none of the given classes directly calls other methods declared in the same class that matches the given predicate.static ArchRule
no_classes_should_directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns a rule that checks that none of the given classes directly calls other methods declared in the same class that are annotated with the given annotation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
no_classes_should_directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with
@PublicAPI(usage=ACCESS) public static ArchRule no_classes_should_directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns a rule that checks that none of the given classes directly calls other methods declared in the same class that are annotated with the given annotation.As an example, the Spring Framework handles transactions by creating a proxy. This proxy does the actual transaction management every time a method annotated with
@Transactional
is invoked.
However, this does not work if the method call comes from the same class.class FooEndpoint { void updateFooName(String name) { // ... fooService.update(foo); // Spring proxies this method call to do the actual transaction management } } class FooService { @Transactional void update(Foo foo) { // ... does something } }
This case could be checked withclass FooService { void updateFooName(String name) { // ... update(foo); // Spring does not proxy this method call and does not start a transaction } @Transactional void update(Foo foo) { // ... does something } }
no_classes_should_directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Transactional.class)
-
no_classes_should_directly_call_other_methods_declared_in_the_same_class_that
@PublicAPI(usage=ACCESS) public static ArchRule no_classes_should_directly_call_other_methods_declared_in_the_same_class_that(DescribedPredicate<? super AccessTarget.MethodCallTarget> predicate)Returns a rule that checks that none of the given classes directly calls other methods declared in the same class that matches the given predicate.For an example, see
no_classes_should_directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Class)
-
directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with
@PublicAPI(usage=ACCESS) public static ArchCondition<JavaClass> directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns a condition that matches classes that directly calls other methods declared in the same class that are annotated with the given annotation.As an example, the Spring Framework handles transactions by creating a proxy. This proxy does the actual transaction management every time a method annotated with
@Transactional
is invoked.
However, this does not work if the method call comes from the same class.class FooEndpoint { void updateFooName(String name) { // ... fooService.update(foo); // Spring proxies this method call to do the actual transaction management } } class FooService { @Transactional void update(Foo foo) { // ... does something } }
The conditionclass FooService { void updateFooName(String name) { // ... update(foo); // Spring does not proxy this method call and does not start a transaction } @Transactional void update(Foo foo) { // ... does something } }
matches the second example.directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Transactional.class)
-
directly_call_other_methods_declared_in_the_same_class_that
@PublicAPI(usage=ACCESS) public static ArchCondition<JavaClass> directly_call_other_methods_declared_in_the_same_class_that(DescribedPredicate<? super AccessTarget.MethodCallTarget> predicate)Returns a condition that matches classes that directly calls other methods declared in the same class that matches the given predicate.For an example, see
directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Class)
-