Search in sources :

Example 16 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class Main method run.

/**
     * Launches the Cucumber-JVM command line.
     *
     * @param argv        runtime options. See details in the {@code cucumber.api.cli.Usage.txt} resource.
     * @param classLoader classloader used to load the runtime
     * @return 0 if execution was successful, 1 if it was not (test failures)
     * @throws IOException if resources couldn't be loaded during the run.
     */
public static byte run(String[] argv, ClassLoader classLoader) throws IOException {
    RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)));
    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
    runtime.run();
    return runtime.exitStatus();
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) Runtime(cucumber.runtime.Runtime) MultiLoader(cucumber.runtime.io.MultiLoader) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) ClassFinder(cucumber.runtime.ClassFinder) RuntimeOptions(cucumber.runtime.RuntimeOptions)

Example 17 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class RuntimeTest method createRuntime.

private Runtime createRuntime(String... runtimeArgs) {
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    return createRuntime(resourceLoader, classLoader, runtimeArgs);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader)

Example 18 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class RuntimeTest method createRuntimeWithMockedGlue.

private Runtime createRuntimeWithMockedGlue(StepDefinitionMatch match, boolean isAmbiguous, HookDefinition hook, boolean isBefore, String... runtimeArgs) {
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    ClassLoader classLoader = mock(ClassLoader.class);
    RuntimeOptions runtimeOptions = new RuntimeOptions(asList(runtimeArgs));
    Backend backend = mock(Backend.class);
    RuntimeGlue glue = mock(RuntimeGlue.class);
    mockMatch(glue, match, isAmbiguous);
    mockHook(glue, hook, isBefore);
    Collection<Backend> backends = Arrays.asList(backend);
    return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, glue);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader)

Example 19 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class MethodScannerTest method loadGlue_registers_the_methods_declaring_class_in_the_object_factory.

@Test
public void loadGlue_registers_the_methods_declaring_class_in_the_object_factory() throws NoSuchMethodException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    MethodScanner methodScanner = new MethodScanner(new ResourceLoaderClassFinder(resourceLoader, classLoader));
    ObjectFactory factory = Mockito.mock(ObjectFactory.class);
    Glue world = Mockito.mock(Glue.class);
    JavaBackend backend = new JavaBackend(factory);
    Whitebox.setInternalState(backend, "glue", world);
    // this delegates to methodScanner.scan which we test
    methodScanner.scan(backend, BaseStepDefs.class.getMethod("m"), BaseStepDefs.class);
    verify(factory, times(1)).addClass(BaseStepDefs.class);
    verifyNoMoreInteractions(factory);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) ObjectFactory(cucumber.api.java.ObjectFactory) Glue(cucumber.runtime.Glue) MultiLoader(cucumber.runtime.io.MultiLoader) Test(org.junit.Test)

Example 20 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class CucumberFeatureTest method logs_message_if_no_feature_paths_are_given.

@Test
public void logs_message_if_no_feature_paths_are_given() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    CucumberFeature.load(resourceLoader, Collections.<String>emptyList(), emptyList(), new PrintStream(baos));
    assertEquals(String.format("Got no path to feature directory or feature file%n"), baos.toString());
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ResourceLoader (cucumber.runtime.io.ResourceLoader)26 Test (org.junit.Test)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 PrintStream (java.io.PrintStream)11 MultiLoader (cucumber.runtime.io.MultiLoader)7 Matchers.anyString (org.mockito.Matchers.anyString)7 RuntimeOptions (cucumber.runtime.RuntimeOptions)5 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)4 ClassFinder (cucumber.runtime.ClassFinder)3 Runtime (cucumber.runtime.Runtime)3 ResourceLoaderClassFinder (cucumber.runtime.io.ResourceLoaderClassFinder)3 ObjectFactory (cucumber.api.java.ObjectFactory)2 JavaBackend (cucumber.runtime.java.JavaBackend)2 CucumberFeature (cucumber.runtime.model.CucumberFeature)2 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1 Backend (cucumber.runtime.Backend)1 CucumberException (cucumber.runtime.CucumberException)1