|
5 | 5 | import java.util.ArrayList; |
6 | 6 | import java.util.Arrays; |
7 | 7 | import java.util.List; |
| 8 | +import java.util.Set; |
8 | 9 | import java.util.function.Function; |
9 | 10 | import org.testng.Assert; |
10 | 11 | import org.testng.ITestListener; |
|
23 | 24 | import test.dependent.github1380.GitHub1380Sample4; |
24 | 25 | import test.dependent.issue2658.FailingClassSample; |
25 | 26 | import test.dependent.issue2658.PassingClassSample; |
| 27 | +import test.dependent.issue893.DependencyTrackingListener; |
| 28 | +import test.dependent.issue893.MultiLevelDependenciesTestClassSample; |
| 29 | +import test.dependent.issue893.TestClassSample; |
26 | 30 |
|
27 | 31 | public class DependentTest extends SimpleBaseTest { |
28 | 32 |
|
@@ -218,6 +222,64 @@ public void testMethodDependencyAmidstInheritance() { |
218 | 222 | assertThat(listener.getSkippedMethodNames()).containsExactly("failingMethod"); |
219 | 223 | } |
220 | 224 |
|
| 225 | + @Test(description = "GITHUB-893", dataProvider = "getTestData") |
| 226 | + public void testDownstreamDependencyRetrieval( |
| 227 | + Class<?> clazz, String independentMethod, String[] dependentMethods) { |
| 228 | + TestNG testng = create(clazz); |
| 229 | + DependencyTrackingListener listener = new DependencyTrackingListener(); |
| 230 | + testng.addListener(listener); |
| 231 | + testng.run(); |
| 232 | + String cls = clazz.getCanonicalName(); |
| 233 | + String key = cls + "." + independentMethod; |
| 234 | + Set<String> downstream = listener.getDownstreamDependencies().get(key); |
| 235 | + dependentMethods = |
| 236 | + Arrays.stream(dependentMethods).map(each -> cls + "." + each).toArray(String[]::new); |
| 237 | + assertThat(downstream).containsExactly(dependentMethods); |
| 238 | + } |
| 239 | + |
| 240 | + @DataProvider(name = "getTestData") |
| 241 | + public Object[][] getTestData() { |
| 242 | + return new Object[][] { |
| 243 | + { |
| 244 | + TestClassSample.class, |
| 245 | + "independentTest", |
| 246 | + new String[] {"anotherDependentTest", "dependentTest"} |
| 247 | + }, |
| 248 | + {MultiLevelDependenciesTestClassSample.class, "father", new String[] {"child"}}, |
| 249 | + { |
| 250 | + MultiLevelDependenciesTestClassSample.class, |
| 251 | + "grandFather", |
| 252 | + new String[] {"father", "mother"} |
| 253 | + }, |
| 254 | + {MultiLevelDependenciesTestClassSample.class, "child", new String[] {}} |
| 255 | + }; |
| 256 | + } |
| 257 | + |
| 258 | + @Test(description = "GITHUB-893", dataProvider = "getUpstreamTestData") |
| 259 | + public void testUpstreamDependencyRetrieval( |
| 260 | + Class<?> clazz, String independentMethod, String[] dependentMethods) { |
| 261 | + TestNG testng = create(clazz); |
| 262 | + DependencyTrackingListener listener = new DependencyTrackingListener(); |
| 263 | + testng.addListener(listener); |
| 264 | + testng.run(); |
| 265 | + String cls = clazz.getCanonicalName(); |
| 266 | + String key = cls + "." + independentMethod; |
| 267 | + Set<String> upstream = listener.getUpstreamDependencies().get(key); |
| 268 | + dependentMethods = |
| 269 | + Arrays.stream(dependentMethods).map(each -> cls + "." + each).toArray(String[]::new); |
| 270 | + assertThat(upstream).containsExactly(dependentMethods); |
| 271 | + } |
| 272 | + |
| 273 | + @DataProvider(name = "getUpstreamTestData") |
| 274 | + public Object[][] getUpstreamTestData() { |
| 275 | + return new Object[][] { |
| 276 | + {TestClassSample.class, "dependentTest", new String[] {"independentTest"}}, |
| 277 | + {MultiLevelDependenciesTestClassSample.class, "father", new String[] {"grandFather"}}, |
| 278 | + {MultiLevelDependenciesTestClassSample.class, "child", new String[] {"father", "mother"}}, |
| 279 | + {MultiLevelDependenciesTestClassSample.class, "grandFather", new String[] {}} |
| 280 | + }; |
| 281 | + } |
| 282 | + |
221 | 283 | public static class MethodNameCollector implements ITestListener { |
222 | 284 |
|
223 | 285 | private static final Function<ITestResult, String> asString = |
|
0 commit comments