Search in sources :

Example 36 with CucumberException

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

the class DefaultObjectFactory method cacheNewInstance.

private <T> T cacheNewInstance(Class<T> type) {
    try {
        Constructor<T> constructor = type.getConstructor();
        T instance = constructor.newInstance();
        instances.put(type, instance);
        return instance;
    } catch (NoSuchMethodException e) {
        throw new CucumberException(String.format("" + "%s does not have a public zero-argument constructor.\n" + "\n" + "To use dependency injection add an other ObjectFactory implementation such as:\n" + " * cucumber-picocontainer\n" + " * cucumber-spring\n" + " * cucumber-jakarta-cdi\n" + " * ...etc\n", type), e);
    } catch (Exception e) {
        throw new CucumberException(String.format("Failed to instantiate %s", type), e);
    }
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) CucumberException(io.cucumber.core.exception.CucumberException)

Example 37 with CucumberException

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

the class PluginFactoryTest method fails_to_instantiate_plugin_that_declares_two_single_arg_constructors_when_no_argument_specified.

@Test
void fails_to_instantiate_plugin_that_declares_two_single_arg_constructors_when_no_argument_specified() {
    PluginOption option = parse(WantsFileOrURL.class.getName());
    Executable testMethod = () -> fc.create(option);
    CucumberException exception = assertThrows(CucumberException.class, testMethod);
    assertThat(exception.getMessage(), is(equalTo("You must supply an output argument to io.cucumber.core.plugin.PluginFactoryTest$WantsFileOrURL. Like so: io.cucumber.core.plugin.PluginFactoryTest$WantsFileOrURL:DIR|FILE|URL")));
}
Also used : PluginOption(io.cucumber.core.options.PluginOption) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 38 with CucumberException

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

the class PluginFactoryTest method fails_to_instantiate_plugin_that_wants_too_much.

@Test
void fails_to_instantiate_plugin_that_wants_too_much() {
    PluginOption option = parse(WantsTooMuch.class.getName());
    Executable testMethod = () -> fc.create(option);
    CucumberException exception = assertThrows(CucumberException.class, testMethod);
    assertThat(exception.getMessage(), is(equalTo("class io.cucumber.core.plugin.PluginFactoryTest$WantsTooMuch must have at least one empty constructor or a constructor that declares a single parameter of one of: [class java.lang.String, class java.io.File, class java.net.URI, class java.net.URL, class java.io.OutputStream, interface java.lang.Appendable]")));
}
Also used : PluginOption(io.cucumber.core.options.PluginOption) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 39 with CucumberException

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

the class CucumberOptionsAnnotationParserTest method cannot_create_with_glue_and_extra_glue.

@Test
void cannot_create_with_glue_and_extra_glue() {
    Executable testMethod = () -> parser().parse(ClassWithGlueAndExtraGlue.class).build();
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("glue and extraGlue cannot be specified at the same time")));
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

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