ArchUnit icon indicating copy to clipboard operation
ArchUnit copied to clipboard

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

Open MariusKl opened this issue 2 years ago • 0 comments

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.

MariusKl avatar Nov 15 '23 12:11 MariusKl