Class ProxyRules

java.lang.Object
com.tngtech.archunit.library.ProxyRules

@PublicAPI(usage=ACCESS) public final class ProxyRules extends Object
ProxyRules provides a set of general ArchConditions and ArchRules for checking the usage of proxies.
  • 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(Class<? extends 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.

      
       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
           }
       }
       
      However, this does not work if the method call comes from the same class.
      
       class 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
           }
       }
       
      This case could be checked with
      
       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(Class<? extends 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.

      
       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
           }
       }
       
      However, this does not work if the method call comes from the same class.
      
       class 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
           }
       }
       
      The condition
      
       directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Transactional.class)
       
      matches the second example.

    • 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)