Search in sources :

Example 1 with PluginOption

use of io.cucumber.core.options.PluginOption in project cucumber-jvm by cucumber.

the class PluginFactoryTest method fails_to_instantiate_plugin_that_wants_a_file_without_file_arg.

@Test
void fails_to_instantiate_plugin_that_wants_a_file_without_file_arg() {
    PluginOption option = parse(WantsFile.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$WantsFile. Like so: io.cucumber.core.plugin.PluginFactoryTest$WantsFile: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 2 with PluginOption

use of io.cucumber.core.options.PluginOption in project cucumber-jvm by cucumber.

the class PluginFactoryTest method instantiates_usage_plugin_with_file_arg.

@Test
void instantiates_usage_plugin_with_file_arg() {
    PluginOption option = parse("usage:" + tmp.resolve("out.txt").toAbsolutePath());
    plugin = fc.create(option);
    assertThat(plugin.getClass(), is(equalTo(UsageFormatter.class)));
}
Also used : PluginOption(io.cucumber.core.options.PluginOption) Test(org.junit.jupiter.api.Test)

Example 3 with PluginOption

use of io.cucumber.core.options.PluginOption in project cucumber-jvm by cucumber.

the class PluginFactoryTest method cant_create_plugin_when_parent_directory_is_a_file.

@Test
void cant_create_plugin_when_parent_directory_is_a_file() throws IOException {
    Path htmlReport = tmp.resolve("target/cucumber/reports");
    PluginOption htmlOption = parse("html:" + htmlReport);
    plugin = fc.create(htmlOption);
    Path jsonReport = tmp.resolve("target/cucumber/reports/cucumber.json");
    PluginOption jsonOption = parse("json:" + jsonReport);
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> fc.create(jsonOption));
    assertThat(exception.getMessage(), is(equalTo("Couldn't create parent directories of '" + jsonReport.toFile().getCanonicalPath() + "'.\n" + "Make sure the the parent directory '" + jsonReport.getParent().toFile().getCanonicalPath() + "' isn't a file.\n" + "\n" + "Note: This usually happens when plugins write to colliding paths.\n" + "For example: 'html:target/cucumber, json:target/cucumber/report.json'\n" + "You can fix this by making the paths do no collide.\n" + "For example: 'html:target/cucumber/report.html, json:target/cucumber/report.json'\n" + "The details are in the stack trace below:")));
}
Also used : Path(java.nio.file.Path) PluginOption(io.cucumber.core.options.PluginOption) Test(org.junit.jupiter.api.Test)

Example 4 with PluginOption

use of io.cucumber.core.options.PluginOption in project cucumber-jvm by cucumber.

the class PluginFactoryTest method plugin_does_not_buffer_its_output.

@Test
void plugin_does_not_buffer_its_output() {
    PrintStream previousSystemOut = System.out;
    OutputStream mockSystemOut = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(mockSystemOut));
        // Need to create a new plugin factory here since we need it to pick
        // up the new value of System.out
        fc = new PluginFactory();
        PluginOption option = parse("progress");
        ProgressFormatter plugin = (ProgressFormatter) fc.create(option);
        EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
        plugin.setEventPublisher(bus);
        Result result = new Result(Status.PASSED, ZERO, null);
        TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class), mock(PickleStepTestStep.class), result);
        bus.send(event);
        assertThat(mockSystemOut.toString(), is(not(equalTo(""))));
    } finally {
        System.setOut(previousSystemOut);
    }
}
Also used : PrintStream(java.io.PrintStream) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Result(io.cucumber.plugin.event.Result) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) PluginOption(io.cucumber.core.options.PluginOption) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 5 with PluginOption

use of io.cucumber.core.options.PluginOption in project cucumber-jvm by cucumber.

the class PluginFactoryTest method instantiates_custom_deprecated_appendable_arg_plugin.

@Test
void instantiates_custom_deprecated_appendable_arg_plugin() throws IOException {
    Path tempDirPath = tmp.resolve("out.txt").toAbsolutePath();
    PluginOption option = parse(WantsAppendable.class.getName() + ":" + tempDirPath);
    WantsAppendable plugin = (WantsAppendable) fc.create(option);
    plugin.writeAndClose("hello");
    String written = String.join("", readAllLines(tempDirPath));
    assertThat(written, is(equalTo("hello")));
}
Also used : Path(java.nio.file.Path) PluginOption(io.cucumber.core.options.PluginOption) Test(org.junit.jupiter.api.Test)

Aggregations

PluginOption (io.cucumber.core.options.PluginOption)23 Test (org.junit.jupiter.api.Test)23 CucumberException (io.cucumber.core.exception.CucumberException)5 Path (java.nio.file.Path)4 Executable (org.junit.jupiter.api.function.Executable)4 EventBus (io.cucumber.core.eventbus.EventBus)1 ClockStub (io.cucumber.core.runner.ClockStub)1 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)1 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)1 Result (io.cucumber.plugin.event.Result)1 TestCase (io.cucumber.plugin.event.TestCase)1 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 UUID (java.util.UUID)1