Search in sources :

Example 11 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class PluginFactoryTest method instantiates_single_custom_appendable_plugin_with_stdout.

@Test
void instantiates_single_custom_appendable_plugin_with_stdout() {
    PluginOption option = parse(WantsOutputStream.class.getName());
    WantsOutputStream plugin = (WantsOutputStream) fc.create(option);
    assertThat(plugin.printStream, is(not(nullValue())));
    CucumberException exception = assertThrows(CucumberException.class, () -> fc.create(option));
    assertThat(exception.getMessage(), is(equalTo("Only one plugin can use STDOUT, now both io.cucumber.core.plugin.PluginFactoryTest$WantsOutputStream " + "and io.cucumber.core.plugin.PluginFactoryTest$WantsOutputStream use it. " + "If you use more than one plugin you must specify output path with io.cucumber.core.plugin.PluginFactoryTest$WantsOutputStream:DIR|FILE|URL")));
}
Also used : PluginOption(io.cucumber.core.options.PluginOption) CucumberException(io.cucumber.core.exception.CucumberException) Test(org.junit.jupiter.api.Test)

Example 12 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class CucumberPropertiesParserTest method should_throw_when_fails_to_parse.

@Test
void should_throw_when_fails_to_parse() {
    properties.put(Constants.OBJECT_FACTORY_PROPERTY_NAME, "garbage");
    CucumberException exception = assertThrows(CucumberException.class, () -> cucumberPropertiesParser.parse(properties).build());
    assertThat(exception.getMessage(), equalTo("Failed to parse 'cucumber.object-factory' with value 'garbage'"));
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) Test(org.junit.jupiter.api.Test)

Example 13 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class AssertionsTest method should_throw_cucumber_exception_when_annotated.

@Test
void should_throw_cucumber_exception_when_annotated() {
    Executable testMethod = () -> Assertions.assertNoCucumberAnnotatedMethods(WithCucumberMethod.class);
    CucumberException expectedThrown = assertThrows(CucumberException.class, testMethod);
    assertThat(expectedThrown.getMessage(), is(equalTo("\n\n" + "Classes annotated with @RunWith(Cucumber.class) must not define any\n" + "Step Definition or Hook methods. Their sole purpose is to serve as\n" + "an entry point for JUnit. Step Definitions and Hooks should be defined\n" + "in their own classes. This allows them to be reused across features.\n" + "Offending class: class io.cucumber.junit.AssertionsTest$WithCucumberMethod\n")));
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 14 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class CucumberTest method no_stepdefs_in_cucumber_runner_invalid.

@Test
void no_stepdefs_in_cucumber_runner_invalid() {
    Executable testMethod = () -> Assertions.assertNoCucumberAnnotatedMethods(Invalid.class);
    CucumberException expectedThrown = assertThrows(CucumberException.class, testMethod);
    assertThat(expectedThrown.getMessage(), is(equalTo("\n\nClasses annotated with @RunWith(Cucumber.class) must not define any\nStep Definition or Hook methods. Their sole purpose is to serve as\nan entry point for JUnit. Step Definitions and Hooks should be defined\nin their own classes. This allows them to be reused across features.\nOffending class: class io.cucumber.junit.CucumberTest$Invalid\n")));
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 15 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class ObjectFactoryServiceLoader method loadSingleObjectFactoryOrDefault.

private static ObjectFactory loadSingleObjectFactoryOrDefault(ServiceLoader<ObjectFactory> loader) {
    Iterator<ObjectFactory> objectFactories = loader.iterator();
    // Find the first non-default object factory,
    // or the default as a side effect.
    ObjectFactory objectFactory = null;
    while (objectFactories.hasNext()) {
        objectFactory = objectFactories.next();
        if (!(objectFactory instanceof DefaultObjectFactory)) {
            break;
        }
    }
    if (objectFactory == null) {
        throw new CucumberException("" + "Could not find any object factory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "This typically happens when using shaded jars. Make sure\n" + "to merge all SPI definitions in META-INF/services correctly");
    }
    // Check if there are no other non-default object factories
    while (objectFactories.hasNext()) {
        ObjectFactory extraObjectFactory = objectFactories.next();
        if (extraObjectFactory instanceof DefaultObjectFactory) {
            continue;
        }
        throw new CucumberException(getMultipleObjectFactoryLogMessage(objectFactory, extraObjectFactory));
    }
    return objectFactory;
}
Also used : DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) ObjectFactory(io.cucumber.core.backend.ObjectFactory) DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) CucumberException(io.cucumber.core.exception.CucumberException)

Aggregations

CucumberException (io.cucumber.core.exception.CucumberException)39 Test (org.junit.jupiter.api.Test)28 Executable (org.junit.jupiter.api.function.Executable)19 StepDefinition (io.cucumber.core.backend.StepDefinition)12 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)12 Feature (io.cucumber.core.gherkin.Feature)11 Step (io.cucumber.core.gherkin.Step)11 Argument (io.cucumber.core.stepexpression.Argument)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)8 PluginOption (io.cucumber.core.options.PluginOption)5 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)4 IOException (java.io.IOException)3 URI (java.net.URI)3 Options (io.cucumber.core.backend.Options)2 DataTableType (io.cucumber.datatable.DataTableType)2 File (java.io.File)2 InputStream (java.io.InputStream)2 URLClassLoader (java.net.URLClassLoader)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2