|
21 | 21 | import java.util.Set; |
22 | 22 |
|
23 | 23 | 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; |
24 | 28 |
|
25 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
26 | 30 |
|
27 | 31 | /** |
28 | 32 | * Tests for {@link CandidateComponentsIndex}. |
29 | 33 | * |
30 | 34 | * @author Stephane Nicoll |
| 35 | + * @author Sam Brannen |
31 | 36 | */ |
32 | 37 | class CandidateComponentsIndexTests { |
33 | 38 |
|
@@ -69,6 +74,36 @@ void mergeCandidateStereotypes() { |
69 | 74 | assertThat(index.getCandidateTypes("com.example", "entity")).contains("com.example.Foo"); |
70 | 75 | } |
71 | 76 |
|
| 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 | + |
72 | 107 |
|
73 | 108 | private static Properties createProperties(String key, String stereotypes) { |
74 | 109 | Properties properties = new Properties(); |
|
0 commit comments