Search in sources :

Example 1 with Match

use of gherkin.formatter.model.Match in project cucumber-jvm by cucumber.

the class JavaStepDefinitionTest method does_not_throw_ambiguous_when_nothing_is_ambiguous.

@Test
public void does_not_throw_ambiguous_when_nothing_is_ambiguous() throws Throwable {
    backend.addStepDefinition(THREE_DISABLED_MICE.getAnnotation(Given.class), THREE_DISABLED_MICE);
    Reporter reporter = new Reporter() {

        @Override
        public void before(Match match, Result result) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void result(Result result) {
            if (result.getError() != null) {
                throw new RuntimeException(result.getError());
            }
        }

        @Override
        public void after(Match match, Result result) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void match(Match match) {
        }

        @Override
        public void embedding(String mimeType, byte[] data) {
        }

        @Override
        public void write(String text) {
        }
    };
    runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), mock(Scenario.class));
    Tag tag = new Tag("@foo", 0);
    Set<Tag> tags = asSet(tag);
    runtime.runBeforeHooks(reporter, tags);
    Step step = new Step(NO_COMMENTS, "Given ", "three blind mice", 1, null, null);
    runtime.runStep("some.feature", step, reporter, ENGLISH);
    assertTrue(defs.foo);
    assertFalse(defs.bar);
}
Also used : Given(cucumber.api.java.en.Given) Reporter(gherkin.formatter.Reporter) Tag(gherkin.formatter.model.Tag) Step(gherkin.formatter.model.Step) Match(gherkin.formatter.model.Match) Result(gherkin.formatter.model.Result) Scenario(gherkin.formatter.model.Scenario) Test(org.junit.Test)

Example 2 with Match

use of gherkin.formatter.model.Match in project cucumber-jvm by cucumber.

the class Runtime method runHookIfTagsMatch.

private void runHookIfTagsMatch(HookDefinition hook, Reporter reporter, Set<Tag> tags, boolean isBefore) {
    if (hook.matches(tags)) {
        String status = Result.PASSED;
        Throwable error = null;
        Match match = new Match(Collections.<Argument>emptyList(), hook.getLocation(false));
        stopWatch.start();
        try {
            hook.execute(scenarioResult);
        } catch (Throwable t) {
            error = t;
            status = isPending(t) ? "pending" : Result.FAILED;
            addError(t);
            skipNextStep = true;
        } finally {
            long duration = stopWatch.stop();
            Result result = new Result(status, duration, error, DUMMY_ARG);
            addHookToCounterAndResult(result);
            if (isBefore) {
                reporter.before(match, result);
            } else {
                reporter.after(match, result);
            }
        }
    }
}
Also used : DocString(gherkin.formatter.model.DocString) Match(gherkin.formatter.model.Match) Result(gherkin.formatter.model.Result)

Example 3 with Match

use of gherkin.formatter.model.Match in project cucumber-jvm by cucumber.

the class JUnitReporterTest method after_with_pending_exception_non_strict.

@Test
public void after_with_pending_exception_non_strict() {
    createNonStrictReporter();
    createDefaultRunNotifier();
    Result result = mock(Result.class);
    Match match = mock(Match.class);
    when(result.getStatus()).thenReturn("Pending");
    when(result.getError()).thenReturn(new PendingException());
    EachTestNotifier executionUnitNotifier = mock(EachTestNotifier.class);
    jUnitReporter.executionUnitNotifier = executionUnitNotifier;
    jUnitReporter.after(match, result);
    jUnitReporter.finishExecutionUnit();
    verify(executionUnitNotifier).fireTestIgnored();
}
Also used : EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) PendingException(cucumber.api.PendingException) Result(gherkin.formatter.model.Result) Match(gherkin.formatter.model.Match) Test(org.junit.Test)

Example 4 with Match

use of gherkin.formatter.model.Match in project cucumber-jvm by cucumber.

the class JUnitReporterTest method forward_calls_to_reporter_interface_methods.

@Test
public void forward_calls_to_reporter_interface_methods() throws Exception {
    Match match = mock(Match.class);
    Result result = mockResult();
    ExecutionUnitRunner executionUnitRunner = mockExecutionUnitRunner();
    String mimeType = "mimeType";
    byte[] data = new byte[] { 1 };
    String text = "text";
    Reporter reporter = mock(Reporter.class);
    jUnitReporter = new JUnitReporter(reporter, mock(Formatter.class), false, new JUnitOptions(Collections.<String>emptyList()));
    jUnitReporter.startExecutionUnit(executionUnitRunner, mock(RunNotifier.class));
    jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
    jUnitReporter.before(match, result);
    jUnitReporter.step(mockStep());
    jUnitReporter.match(match);
    jUnitReporter.embedding(mimeType, data);
    jUnitReporter.write(text);
    jUnitReporter.result(result);
    jUnitReporter.after(match, result);
    verify(reporter).before(match, result);
    verify(reporter).match(match);
    verify(reporter).embedding(mimeType, data);
    verify(reporter).write(text);
    verify(reporter).result(result);
    verify(reporter).after(match, result);
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Reporter(gherkin.formatter.Reporter) Match(gherkin.formatter.model.Match) Result(gherkin.formatter.model.Result) Scenario(gherkin.formatter.model.Scenario) Test(org.junit.Test)

Example 5 with Match

use of gherkin.formatter.model.Match in project cucumber-jvm by cucumber.

the class JUnitReporterTest method before_with_pending_exception_strict.

@Test
public void before_with_pending_exception_strict() {
    createStrictReporter();
    createDefaultRunNotifier();
    Result result = mock(Result.class);
    Match match = mock(Match.class);
    when(result.getStatus()).thenReturn("Pending");
    when(result.getError()).thenReturn(new PendingException());
    EachTestNotifier executionUnitNotifier = mock(EachTestNotifier.class);
    jUnitReporter.executionUnitNotifier = executionUnitNotifier;
    jUnitReporter.before(match, result);
    verifyAddFailureWithPendingException(executionUnitNotifier);
}
Also used : EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) PendingException(cucumber.api.PendingException) Result(gherkin.formatter.model.Result) Match(gherkin.formatter.model.Match) Test(org.junit.Test)

Aggregations

Match (gherkin.formatter.model.Match)7 Result (gherkin.formatter.model.Result)7 Test (org.junit.Test)5 PendingException (cucumber.api.PendingException)3 Reporter (gherkin.formatter.Reporter)3 EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)3 Scenario (gherkin.formatter.model.Scenario)2 Given (cucumber.api.java.en.Given)1 DocString (gherkin.formatter.model.DocString)1 Step (gherkin.formatter.model.Step)1 Tag (gherkin.formatter.model.Tag)1 RunNotifier (org.junit.runner.notification.RunNotifier)1 Test (org.testng.annotations.Test)1