|
9 | 9 | import com.intuit.karate.core.Tags; |
10 | 10 | import com.intuit.karate.resource.Resource; |
11 | 11 | import io.testomat.core.model.ExceptionDetails; |
| 12 | +import java.nio.charset.StandardCharsets; |
12 | 13 | import java.util.ArrayList; |
13 | 14 | import java.util.Arrays; |
14 | 15 | import java.util.Collection; |
| 16 | +import java.util.UUID; |
15 | 17 | import java.util.stream.Collectors; |
16 | 18 | import org.junit.jupiter.api.Test; |
17 | 19 |
|
@@ -143,13 +145,107 @@ void getRidGeneratesStableUuid() { |
143 | 145 | ScenarioRuntime sr = mockScenarioRuntime(); |
144 | 146 |
|
145 | 147 | when(sr.scenario.getLine()).thenReturn(4); |
| 148 | + when(sr.scenario.getExampleIndex()).thenReturn(-1); |
146 | 149 |
|
147 | 150 | String rid1 = extractor.getRid(sr); |
148 | 151 | String rid2 = extractor.getRid(sr); |
149 | 152 |
|
| 153 | + assertThat(rid1) |
| 154 | + .isNotNull() |
| 155 | + .isEqualTo(rid2); |
| 156 | + } |
| 157 | + |
| 158 | + @Test |
| 159 | + void getRidSameWithoutExampleIndex() { |
| 160 | + ScenarioRuntime sr1 = mockScenarioRuntime(); |
| 161 | + ScenarioRuntime sr2 = mockScenarioRuntime(); |
| 162 | + |
| 163 | + when(sr1.scenario.getLine()).thenReturn(5); |
| 164 | + when(sr2.scenario.getLine()).thenReturn(5); |
| 165 | + |
| 166 | + when(sr1.scenario.getExampleIndex()).thenReturn(-1); |
| 167 | + when(sr2.scenario.getExampleIndex()).thenReturn(-1); |
| 168 | + |
| 169 | + String rid1 = extractor.getRid(sr1); |
| 170 | + String rid2 = extractor.getRid(sr2); |
| 171 | + |
150 | 172 | assertThat(rid1).isEqualTo(rid2); |
151 | 173 | } |
152 | 174 |
|
| 175 | + @Test |
| 176 | + void getRidDifferentLinesProduceDifferentRid() { |
| 177 | + ScenarioRuntime sr1 = mockScenarioRuntime(); |
| 178 | + ScenarioRuntime sr2 = mockScenarioRuntime(); |
| 179 | + |
| 180 | + when(sr1.scenario.getLine()).thenReturn(1); |
| 181 | + when(sr2.scenario.getLine()).thenReturn(2); |
| 182 | + |
| 183 | + when(sr1.scenario.getExampleIndex()).thenReturn(-1); |
| 184 | + when(sr2.scenario.getExampleIndex()).thenReturn(-1); |
| 185 | + |
| 186 | + String rid1 = extractor.getRid(sr1); |
| 187 | + String rid2 = extractor.getRid(sr2); |
| 188 | + |
| 189 | + assertThat(rid1).isNotEqualTo(rid2); |
| 190 | + } |
| 191 | + |
| 192 | + @Test |
| 193 | + void getRidIncludesExampleIndex() { |
| 194 | + ScenarioRuntime sr1 = mockScenarioRuntime(); |
| 195 | + ScenarioRuntime sr2 = mockScenarioRuntime(); |
| 196 | + |
| 197 | + when(sr1.scenario.getLine()).thenReturn(10); |
| 198 | + when(sr2.scenario.getLine()).thenReturn(10); |
| 199 | + |
| 200 | + when(sr1.scenario.getExampleIndex()).thenReturn(0); |
| 201 | + when(sr2.scenario.getExampleIndex()).thenReturn(1); |
| 202 | + |
| 203 | + String rid1 = extractor.getRid(sr1); |
| 204 | + String rid2 = extractor.getRid(sr2); |
| 205 | + |
| 206 | + assertThat(rid1).isNotEqualTo(rid2); |
| 207 | + } |
| 208 | + |
| 209 | + @Test |
| 210 | + void getRidDifferentFeatureFilesProduceDifferentRid() { |
| 211 | + ScenarioRuntime sr1 = mockScenarioRuntime(); |
| 212 | + ScenarioRuntime sr2 = mockScenarioRuntime(); |
| 213 | + |
| 214 | + when(sr1.scenario.getLine()).thenReturn(1); |
| 215 | + when(sr2.scenario.getLine()).thenReturn(1); |
| 216 | + |
| 217 | + when(sr1.scenario.getExampleIndex()).thenReturn(-1); |
| 218 | + when(sr2.scenario.getExampleIndex()).thenReturn(-1); |
| 219 | + |
| 220 | + when(sr2.scenario.getFeature() |
| 221 | + .getResource() |
| 222 | + .getRelativePath()) |
| 223 | + .thenReturn("features/Other.feature"); |
| 224 | + |
| 225 | + String rid1 = extractor.getRid(sr1); |
| 226 | + String rid2 = extractor.getRid(sr2); |
| 227 | + |
| 228 | + assertThat(rid1).isNotEqualTo(rid2); |
| 229 | + } |
| 230 | + |
| 231 | + @Test |
| 232 | + void getRidMatchesExpectedUuid() { |
| 233 | + ScenarioRuntime sr = mockScenarioRuntime(); |
| 234 | + |
| 235 | + when(sr.scenario.getLine()).thenReturn(4); |
| 236 | + when(sr.scenario.getExampleIndex()).thenReturn(-1); |
| 237 | + |
| 238 | + String expected = |
| 239 | + UUID.nameUUIDFromBytes( |
| 240 | + "features/KarateTest.feature:4" |
| 241 | + .getBytes(StandardCharsets.UTF_8) |
| 242 | + ).toString(); |
| 243 | + |
| 244 | + String rid = extractor.getRid(sr); |
| 245 | + |
| 246 | + assertThat(rid).isEqualTo(expected); |
| 247 | + } |
| 248 | + |
153 | 249 | private ScenarioRuntime mockScenarioRuntime() { |
154 | 250 | ScenarioRuntime sr = mock(ScenarioRuntime.class); |
155 | 251 |
|
|
0 commit comments