TNG / ArchUnit

A Java architecture test library, to specify and assert architecture rules in plain Java
http://archunit.org
Apache License 2.0
3.18k stars 288 forks source link

Recommended test for @Transactional does not work in combination with generic interface/super class #1193

Open MariusKl opened 10 months ago

MariusKl commented 10 months ago

I use your recommended test to avoid internal calls to methods with @Transactional

no_classes_should_directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(
            Transactional.class);

Unfortunately this does not work if the method is an implementation of a generic interface method

public interface ItemProcessor<I, O> {
    Integer process(I var1) throws Exception;
}

public class LoadProcessor implements ItemProcessor<String, Integer> {

    @Override
    @Transactional
    public Integer process(String var1) throws Exception {
        return null;
    }
}

The result is java.lang.AssertionError: Architecture Violation [Priority: MEDIUM] - Rule 'no classes should directly call other methods declared in the same class that are annotated with @Transactional, because it bypasses the proxy mechanism' was violated (1 times): Method <org.example.LoadProcessor.process(java.lang.Object)> calls method <org.example.LoadProcessor.process(java.lang.String)> in (LoadProcessor.java:5)

Same result if ItemProcessor is an abstract class. Tested with archunit-junit5 in version 1.2.0.