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);
}
}
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")));
}
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]")));
}
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")));
}
Aggregations