Browse Source

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
pull/35608/head
Sam Brannen 4 months ago
parent
commit
b727dbb802
  1. 35
      spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexTests.java

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

@ -21,6 +21,10 @@ import java.util.Properties; @@ -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; @@ -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 { @@ -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();

Loading…
Cancel
Save