Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests to verify patterns are not followed #803

Closed
jamietanna opened this issue Feb 21, 2022 · 1 comment · Fixed by #816
Closed

Adding tests to verify patterns are not followed #803

jamietanna opened this issue Feb 21, 2022 · 1 comment · Fixed by #816

Comments

@jamietanna
Copy link

As a follow-up to #774, it now is not as easy to write a rule that verifies that we do not follow a pattern, such as the below which ensures we don't use field injection with Spring's Dependency Injection:

  @ArchTest
  void requireNoAutowiredFieldInjection(JavaClasses classes) {
    classesThatAreNotTests()
        .and()
        .containAnyFieldsThat(
            describe(
                "are Autowired by Spring",
                f -> f.tryGetAnnotationOfType(Autowired.class).isPresent()))
        .should()
        .containNumberOfElements(equalTo(0))
        .check(classes);
  }

This now would require running the whole set of tests with archRule.failOnEmptyShould which although fine, leads to the risk that we have other tests that need to assert i.e. .containNumberOfElements(greaterThan(0)).

@codecholeric
Copy link
Collaborator

Thanks for raising the issue 🙂 Yes, I understand that we need to make this configurable per rule! We will tackle this ASAP! (see #808 and #806)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants