package info.javaspec.console.helpers;

import info.javaspec.MockSpecReporter;
import info.javaspec.SpecCollection;
import info.javaspec.lang.lambda.FunctionalDslFactory;
import info.javaspec.lang.lambda.SpecCollectionFactory;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class SpecCollectionHelper {
  private final SpecHelper specHelper;

  private SpecCollection rootCollection;
  private SpecCollection selectedCollection;

  public SpecCollectionHelper(SpecHelper specHelper) {
    this.specHelper = specHelper;
  }

  public SpecCollection findCollectionWithDescription(String description) {
    this.selectedCollection = getRootCollection().subCollections().stream()
      .filter(x -> description.equals(x.description()))
      .findFirst()
      .orElseThrow(() -> new RuntimeException(String.format("Collection not found: %s", description)));

    return this.selectedCollection;
  }

  public void loadSpecsFromClass() {
    List<Class<?>> specClasses = Collections.singletonList(this.specHelper.getDeclaringClass());
    List<String> specClassNames = specClasses.stream()
      .map(Class::getName)
      .collect(Collectors.toList());
    SpecCollectionFactory factory = new FunctionalDslFactory(specClassNames);
    this.rootCollection = factory.declareSpecs();
  }

  public void runThatCollection() {
    runner().run(getSelectedCollection());
  }

  public SpecCollection getSelectedCollection() {
    if(this.selectedCollection != null)
      return this.selectedCollection;

    SpecCollection rootCollection = getRootCollection();
    if(rootCollection != null)
      return rootCollection;

    throw new RuntimeException("No collection has been defined");
  }

  private SpecCollection getRootCollection() {
    return this.rootCollection;
  }

  private SpecCollectionRunner runner() {
    return collection -> collection.runSpecs(new MockSpecReporter());
  }

  @FunctionalInterface
  interface SpecCollectionRunner {
    void run(SpecCollection collection);
  }
}

@@ -1371,21 +1371,8 @@
     
-runner().run(
 getS
@@ -1390,16 +1390,48 @@
 ection()
+.runSpecs(new MockSpecReporter()
 );%0A  %7D%0A%0A
@@ -1834,228 +1834,7 @@
 %0A  %7D
-%0A%0A  private SpecCollectionRunner runner() %7B%0A    return collection -%3E collection.runSpecs(new MockSpecReporter());%0A  %7D%0A%0A  @FunctionalInterface%0A  interface SpecCollectionRunner %7B%0A    void run(SpecCollection collection);%0A  %7D
 %0A%7D%0A

Remove unnecessary interface