Introduce tests for CandidateComponentsIndex.hasScannedPackage()

This indirectly tests the implementation of matchPackage(), which was
fixed in the previous commit.

See gh-35497
See gh-35601
This commit is contained in:
Sam Brannen
2025-10-11 15:49:31 +02:00
parent 113b9d131c
commit b727dbb802
@@ -21,6 +21,10 @@ import java.util.Properties;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -28,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link CandidateComponentsIndex}.
*
* @author Stephane Nicoll
* @author Sam Brannen
*/
class CandidateComponentsIndexTests {
@@ -69,6 +74,36 @@ class CandidateComponentsIndexTests {
assertThat(index.getCandidateTypes("com.example", "entity")).contains("com.example.Foo");
}
@ParameterizedTest // gh-35601
@ValueSource(strings = {
"com.example.service",
"com.example.service.sub",
"com.example.service.subX",
"com.example.domain",
"com.example.domain.X"
})
void hasScannedPackage(String packageName) {
CandidateComponentsIndex index = new CandidateComponentsIndex();
createSampleProperties().keySet()
.forEach(key -> index.registerScan(ClassUtils.getPackageName((String) key)));
assertThat(index.hasScannedPackage(packageName)).isTrue();
}
@ParameterizedTest // gh-35601
@ValueSource(strings = {
"com.example",
"com.exampleX",
"com.exampleX.service",
"com.example.serviceX",
"com.example.domainX"
})
void hasScannedPackageWithNoMatch(String packageName) {
CandidateComponentsIndex index = new CandidateComponentsIndex();
createSampleProperties().keySet()
.forEach(key -> index.registerScan(ClassUtils.getPackageName((String) key)));
assertThat(index.hasScannedPackage(packageName)).isFalse();
}
private static Properties createProperties(String key, String stereotypes) {
Properties properties = new Properties();