|
18 | 18 |
|
19 | 19 | import java.util.List; |
20 | 20 | import java.util.Properties; |
21 | | -import java.util.Set; |
22 | 21 |
|
| 22 | +import org.junit.jupiter.api.Nested; |
23 | 23 | import org.junit.jupiter.api.Test; |
24 | 24 | import org.junit.jupiter.params.ParameterizedTest; |
25 | 25 | import org.junit.jupiter.params.provider.ValueSource; |
26 | 26 |
|
27 | | -import org.springframework.util.ClassUtils; |
28 | | - |
29 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
30 | 28 |
|
31 | 29 | /** |
|
36 | 34 | */ |
37 | 35 | class CandidateComponentsIndexTests { |
38 | 36 |
|
39 | | - @Test |
40 | | - void getCandidateTypes() { |
41 | | - CandidateComponentsIndex index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
42 | | - Set<String> actual = index.getCandidateTypes("com.example.service", "service"); |
43 | | - assertThat(actual).contains("com.example.service.One", |
44 | | - "com.example.service.sub.Two", "com.example.service.Three"); |
45 | | - } |
46 | | - |
47 | | - @Test |
48 | | - void getCandidateTypesNoMatch() { |
49 | | - CandidateComponentsIndex index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
50 | | - Set<String> actual = index.getCandidateTypes("com.example.service", "entity"); |
51 | | - assertThat(actual).isEmpty(); |
52 | | - } |
53 | | - |
54 | | - @Test |
55 | | - void getCandidateTypesSubPackage() { |
56 | | - CandidateComponentsIndex index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
57 | | - Set<String> actual = index.getCandidateTypes("com.example.service.sub", "service"); |
58 | | - assertThat(actual).contains("com.example.service.sub.Two"); |
59 | | - } |
| 37 | + @Nested |
| 38 | + class ComponentIndexFilesTests { |
60 | 39 |
|
61 | | - @Test |
62 | | - void getCandidateTypesSubPackageNoMatch() { |
63 | | - CandidateComponentsIndex index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
64 | | - Set<String> actual = index.getCandidateTypes("com.example.service.none", "service"); |
65 | | - assertThat(actual).isEmpty(); |
66 | | - } |
67 | | - |
68 | | - @Test |
69 | | - void mergeCandidateStereotypes() { |
70 | | - CandidateComponentsIndex index = new CandidateComponentsIndex(List.of( |
| 40 | + @Test |
| 41 | + void getCandidateTypes() { |
| 42 | + var index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
| 43 | + var candidateTypes = index.getCandidateTypes("com.example.service", "service"); |
| 44 | + assertThat(candidateTypes).contains("com.example.service.One", |
| 45 | + "com.example.service.sub.Two", "com.example.service.Three"); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void getCandidateTypesNoMatch() { |
| 50 | + var index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
| 51 | + var candidateTypes = index.getCandidateTypes("com.example.service", "entity"); |
| 52 | + assertThat(candidateTypes).isEmpty(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void getCandidateTypesSubPackage() { |
| 57 | + var index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
| 58 | + var candidateTypes = index.getCandidateTypes("com.example.service.sub", "service"); |
| 59 | + assertThat(candidateTypes).contains("com.example.service.sub.Two"); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void getCandidateTypesSubPackageNoMatch() { |
| 64 | + var index = new CandidateComponentsIndex(List.of(createSampleProperties())); |
| 65 | + var candidateTypes = index.getCandidateTypes("com.example.service.none", "service"); |
| 66 | + assertThat(candidateTypes).isEmpty(); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + void parsesMultipleCandidateStereotypes() { |
| 71 | + var index = new CandidateComponentsIndex(List.of( |
| 72 | + createProperties("com.example.Foo", "service", "entity"))); |
| 73 | + assertThat(index.getCandidateTypes("com.example", "service")).contains("com.example.Foo"); |
| 74 | + assertThat(index.getCandidateTypes("com.example", "entity")).contains("com.example.Foo"); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void mergesCandidateStereotypes() { |
| 79 | + var index = new CandidateComponentsIndex(List.of( |
71 | 80 | createProperties("com.example.Foo", "service"), |
72 | 81 | createProperties("com.example.Foo", "entity"))); |
73 | | - assertThat(index.getCandidateTypes("com.example", "service")).contains("com.example.Foo"); |
74 | | - assertThat(index.getCandidateTypes("com.example", "entity")).contains("com.example.Foo"); |
75 | | - } |
| 82 | + assertThat(index.getCandidateTypes("com.example", "service")).contains("com.example.Foo"); |
| 83 | + assertThat(index.getCandidateTypes("com.example", "entity")).contains("com.example.Foo"); |
| 84 | + } |
| 85 | + |
| 86 | + private static Properties createSampleProperties() { |
| 87 | + var properties = new Properties(); |
| 88 | + properties.put("com.example.service.One", "service"); |
| 89 | + properties.put("com.example.service.sub.Two", "service"); |
| 90 | + properties.put("com.example.service.Three", "service"); |
| 91 | + properties.put("com.example.domain.Four", "entity"); |
| 92 | + return properties; |
| 93 | + } |
| 94 | + |
| 95 | + private static Properties createProperties(String key, String... stereotypes) { |
| 96 | + var properties = new Properties(); |
| 97 | + properties.put(key, String.join(",", stereotypes)); |
| 98 | + return properties; |
| 99 | + } |
76 | 100 |
|
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 | 101 | } |
91 | 102 |
|
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 | | - |
107 | | - |
108 | | - private static Properties createProperties(String key, String stereotypes) { |
109 | | - Properties properties = new Properties(); |
110 | | - properties.put(key, String.join(",", stereotypes)); |
111 | | - return properties; |
112 | | - } |
| 103 | + @Nested |
| 104 | + class ProgrammaticIndexTests { |
| 105 | + |
| 106 | + @ParameterizedTest // gh-35601 |
| 107 | + @ValueSource(strings = { |
| 108 | + "com.example.service", |
| 109 | + "com.example.service.sub", |
| 110 | + "com.example.service.subX", |
| 111 | + "com.example.domain", |
| 112 | + "com.example.domain.X" |
| 113 | + }) |
| 114 | + void hasScannedPackage(String packageName) { |
| 115 | + var index = new CandidateComponentsIndex(); |
| 116 | + index.registerScan("com.example.service", "com.example.service.sub", "com.example.domain"); |
| 117 | + assertThat(index.hasScannedPackage(packageName)).isTrue(); |
| 118 | + } |
| 119 | + |
| 120 | + @ParameterizedTest // gh-35601 |
| 121 | + @ValueSource(strings = { |
| 122 | + "com.example.service", |
| 123 | + "com.example.domain", |
| 124 | + "com.example.web", |
| 125 | + }) |
| 126 | + void hasScannedPackageForStarPattern(String packageName) { |
| 127 | + var index = new CandidateComponentsIndex(); |
| 128 | + index.registerScan("com.example.*"); |
| 129 | + assertThat(index.hasScannedPackage(packageName)).isTrue(); |
| 130 | + } |
| 131 | + |
| 132 | + @ParameterizedTest // gh-35601 |
| 133 | + @ValueSource(strings = { |
| 134 | + "com.example", |
| 135 | + "com.example.service", |
| 136 | + "com.example.service.sub", |
| 137 | + }) |
| 138 | + void hasScannedPackageForStarStarPattern(String packageName) { |
| 139 | + var index = new CandidateComponentsIndex(); |
| 140 | + index.registerScan("com.example.**"); |
| 141 | + assertThat(index.hasScannedPackage(packageName)).isTrue(); |
| 142 | + } |
| 143 | + |
| 144 | + @ParameterizedTest // gh-35601 |
| 145 | + @ValueSource(strings = { |
| 146 | + "com.example", |
| 147 | + "com.exampleX", |
| 148 | + "com.exampleX.service", |
| 149 | + "com.example.serviceX", |
| 150 | + "com.example.domainX" |
| 151 | + }) |
| 152 | + void hasScannedPackageWithNoMatch(String packageName) { |
| 153 | + var index = new CandidateComponentsIndex(); |
| 154 | + index.registerScan("com.example.service", "com.example.domain"); |
| 155 | + assertThat(index.hasScannedPackage(packageName)).isFalse(); |
| 156 | + } |
| 157 | + |
| 158 | + @ParameterizedTest // gh-35601 |
| 159 | + @ValueSource(strings = { |
| 160 | + "com.example", |
| 161 | + "com.exampleX", |
| 162 | + "com.exampleX.service" |
| 163 | + }) |
| 164 | + void hasScannedPackageForStarPatternWithNoMatch(String packageName) { |
| 165 | + var index = new CandidateComponentsIndex(); |
| 166 | + index.registerScan("com.example.*"); |
| 167 | + assertThat(index.hasScannedPackage(packageName)).isFalse(); |
| 168 | + } |
| 169 | + |
| 170 | + @ParameterizedTest // gh-35601 |
| 171 | + @ValueSource(strings = { |
| 172 | + "com.exampleX", |
| 173 | + "com.exampleX.service" |
| 174 | + }) |
| 175 | + void hasScannedPackageForStarStarPatternWithNoMatch(String packageName) { |
| 176 | + var index = new CandidateComponentsIndex(); |
| 177 | + index.registerScan("com.example.**"); |
| 178 | + assertThat(index.hasScannedPackage(packageName)).isFalse(); |
| 179 | + } |
113 | 180 |
|
114 | | - private static Properties createSampleProperties() { |
115 | | - Properties properties = new Properties(); |
116 | | - properties.put("com.example.service.One", "service"); |
117 | | - properties.put("com.example.service.sub.Two", "service"); |
118 | | - properties.put("com.example.service.Three", "service"); |
119 | | - properties.put("com.example.domain.Four", "entity"); |
120 | | - return properties; |
121 | 181 | } |
122 | 182 |
|
123 | 183 | } |
0 commit comments