Skip to content

Commit b727dbb

Browse files
committed
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
1 parent 113b9d1 commit b727dbb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
import java.util.Set;
2222

2323
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.ValueSource;
26+
27+
import org.springframework.util.ClassUtils;
2428

2529
import static org.assertj.core.api.Assertions.assertThat;
2630

2731
/**
2832
* Tests for {@link CandidateComponentsIndex}.
2933
*
3034
* @author Stephane Nicoll
35+
* @author Sam Brannen
3136
*/
3237
class CandidateComponentsIndexTests {
3338

@@ -69,6 +74,36 @@ void mergeCandidateStereotypes() {
6974
assertThat(index.getCandidateTypes("com.example", "entity")).contains("com.example.Foo");
7075
}
7176

77+
@ParameterizedTest // gh-35601
78+
@ValueSource(strings = {
79+
"com.example.service",
80+
"com.example.service.sub",
81+
"com.example.service.subX",
82+
"com.example.domain",
83+
"com.example.domain.X"
84+
})
85+
void hasScannedPackage(String packageName) {
86+
CandidateComponentsIndex index = new CandidateComponentsIndex();
87+
createSampleProperties().keySet()
88+
.forEach(key -> index.registerScan(ClassUtils.getPackageName((String) key)));
89+
assertThat(index.hasScannedPackage(packageName)).isTrue();
90+
}
91+
92+
@ParameterizedTest // gh-35601
93+
@ValueSource(strings = {
94+
"com.example",
95+
"com.exampleX",
96+
"com.exampleX.service",
97+
"com.example.serviceX",
98+
"com.example.domainX"
99+
})
100+
void hasScannedPackageWithNoMatch(String packageName) {
101+
CandidateComponentsIndex index = new CandidateComponentsIndex();
102+
createSampleProperties().keySet()
103+
.forEach(key -> index.registerScan(ClassUtils.getPackageName((String) key)));
104+
assertThat(index.hasScannedPackage(packageName)).isFalse();
105+
}
106+
72107

73108
private static Properties createProperties(String key, String stereotypes) {
74109
Properties properties = new Properties();

0 commit comments

Comments
 (0)