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

Expose architectural concepts via ArchUnit ArchCondition for use in custom verifications #100

Open
jamietanna opened this issue Jan 24, 2022 · 1 comment

Comments

@jamietanna
Copy link

I'm planning on writing ArchUnit tests that validate i.e.:

  @ArchTest
  @SuppressWarnings("unused")
  ArchRule mockMvcShouldOnlyBeUsedInInterfaceLayer =
      classes()
          .that()
          .areAnnotatedWith(AutoConfigureMockMvc.class)
          .should()
          .resideInAPackage("..interfaces.."); // this is the `@InterfaceLayer`

However, you'll notice that the package name here is a String, whereas it'd be ideal to reference the annotated package.

As this isn't possible, and as I'd also like to be able to TDD the migration to the new layered architecture, it'd be good to write a test that validates the @InterfaceLayer is on the same value as the package picked up by "..interfaces..".

However, as the annotations are only CLASS which means we can't pick them up at runtime through Reflection.

Is there any reason they're only CLASS, not RUNTIME?

@odrotbohm
Copy link
Member

I think this is a matter of us providing references to concepts like "resides in Interface layer" as ArchCondition via our APIs so that you can hand them into the ….should(…) method.

Note that the annotation retention doesn't make a difference here, as ArchUnit is reading the class file information via ASM, not reflection. We so far didn't see a need to raise that level to runtime, as there's currently nothing that would evaluate these annotations via reflection.

@odrotbohm odrotbohm changed the title Migrate annotations' RetentionPolicy to RUNTIME Expose architectural concepts via ArchUnit ArchCondition for use in custom verifications Feb 8, 2022
@odrotbohm odrotbohm transferred this issue from xmolecules/jmolecules Feb 8, 2022
rweisleder added a commit to rweisleder/jmolecules-integrations that referenced this issue Mar 23, 2023
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

No branches or pull requests

2 participants