Skip to content

Adjust AnalyzeClasses annotation to support individual classes as parameter#1569

Open
TheManWhoStaresAtCode wants to merge 1 commit intomainfrom
1195_analyze_list_of_classes
Open

Adjust AnalyzeClasses annotation to support individual classes as parameter#1569
TheManWhoStaresAtCode wants to merge 1 commit intomainfrom
1195_analyze_list_of_classes

Conversation

@TheManWhoStaresAtCode
Copy link
Copy Markdown
Member

As suggested in the ticket adjust the annotation to have a new classes property to select individual classes as an additional option.

Resolves #1195

…ameter

Relates to #1195

Signed-off-by: Andreas Zöller <andreas.zoeller@tngtech.com>
@TheManWhoStaresAtCode TheManWhoStaresAtCode force-pushed the 1195_analyze_list_of_classes branch from 11e740b to f6a08b9 Compare December 28, 2025 22:02
Copy link
Copy Markdown

@StefanGraeber StefanGraeber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just some comment and naming updates I'd prefer

* <li>{@link #locations()} - specify custom locations via {@link LocationProvider}</li>
* <li>{@link #wholeClasspath()} - import all classes on the classpath</li>
* </ul>
* These options can be combined. If no option is specified, the package of the annotated test class will be imported.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find it obvious whether the different options are used as union or intersect.
AFAIK it is a union, so each option can only add more classes.
Should we make that clear?

docs/userguide/009_JUnit_Support.adoc and archunit-junit/src/main/java/com/tngtech/archunit/junit/internal/ClassCache.java confirm this assumption

* <li>{@link #locations()} - specify custom locations via {@link LocationProvider}</li>
* <li>{@link #wholeClasspath()} - import all classes on the classpath</li>
* </ul>
* These options can be combined. If no option is specified, the package of the annotated test class will be imported.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. can we make clear that each option adds more classes and never reduce the selection?

docs/userguide/009_JUnit_Support.adoc and archunit-junit/src/main/java/com/tngtech/archunit/junit/internal/ClassCache.java confirm this assumption

}

@Test
void passes_AnalyzeClasses_with_new_classes_property_to_cache() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like names like "new" because it will not be new at some time. Please remove that from the test name

verify(classCache).getClassesToAnalyzeFor(eq(AnalyzeClassesWithClassesProperty.class), classAnalysisRequestCaptor.capture());
ClassAnalysisRequest request = classAnalysisRequestCaptor.getValue();
AnalyzeClasses expected = AnalyzeClassesWithClassesProperty.class.getAnnotation(AnalyzeClasses.class);
assertThat(request.getClassesToAnalyze()).isEqualTo(expected.classes());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you use the classes from the annotation here but an explicit empty for other properties like getPackageNames?
Feels inconsistent to me

@Test
public void gets_all_classes_specified() {
JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, new TestAnalysisRequest()
.withClassesToAnalyze(getClass()));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe getClass() -> this.getClass() in both places to make it more obvious?

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 this pull request may close these issues.

Add support to analyse list of classes

2 participants