1import net.serenitybdd.junit.finder.TestMethodFinder;2import org.junit.runner.Description;3import org.junit.runner.notification.RunNotifier;4import org.junit.runners.ParentRunner;5import org.junit.runners.model.InitializationError;6import java.util.List;7import java.util.stream.Collectors;8public class Runner extends ParentRunner<Runner.TestClass> {9 private TestMethodFinder testMethodFinder;10 private List<TestClass> testClasses;11 public Runner(Class<?> klass) throws InitializationError {12 super(klass);13 this.testMethodFinder = new TestMethodFinder();14 this.testClasses = testMethodFinder.findTestMethods(klass).stream()15 .map(TestClass::new)16 .collect(Collectors.toList());17 }18 protected List<TestClass> getChildren() {19 return testClasses;20 }21 protected Description describeChild(TestClass child) {22 return Description.createTestDescription(getTestClass().getJavaClass(), child.getName());23 }24 protected void runChild(TestClass child, RunNotifier notifier) {25 child.run(notifier);26 }27 public static class TestClass extends ParentRunner<Runner.TestMethod> {28 private final String name;29 private final List<TestMethod> testMethods;30 public TestClass(TestMethodFinder.TestClass testClass) {31 super(testClass.getTestClass());32 this.name = testClass.getName();33 this.testMethods = testClass.getTestMethods().stream()34 .map(TestMethod::new)35 .collect(Collectors.toList());36 }37 protected List<TestMethod> getChildren() {38 return testMethods;39 }40 protected Description describeChild(TestMethod child) {41 return Description.createTestDescription(getTestClass().getJavaClass(), child.getName());42 }43 protected void runChild(TestMethod child, RunNotifier notifier) {44 child.run(notifier);45 }46 public String getName() {47 return name;48 }49 public static class TestMethod {50 private final String name;51 private final List<String> tags;52 public TestMethod(TestMethodFinder.TestMethod testMethod) {53 this.name = testMethod.getName();54 this.tags = testMethod.getTags();55 }56 public String getName() {57 return name;58 }59 public List<String> getTags() {60 return tags;61 }62 public void run(RunNotifier notifier) {63 System.out.println("Running test method: