Search in sources :

Example 1 with StepDefinitionMatch

use of cucumber.runtime.StepDefinitionMatch in project cucumber-jvm by cucumber.

the class UsageFormatterTest method resultWithNullDuration.

@Test
public void resultWithNullDuration() {
    Appendable out = mock(Appendable.class);
    UsageFormatter usageFormatter = new UsageFormatter(out);
    StepDefinitionMatch match = mockStepDefinitionMatch();
    usageFormatter.match(match);
    Result result = mock(Result.class);
    when(result.getDuration()).thenReturn(null);
    when(result.getStatus()).thenReturn(Result.PASSED);
    usageFormatter.result(result);
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertEquals(usageMap.size(), 1);
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertEquals(durationEntries.size(), 1);
    assertEquals(durationEntries.get(0).name, "step");
    assertEquals(durationEntries.get(0).durations.size(), 1);
    assertEquals(durationEntries.get(0).durations.get(0).duration, BigDecimal.ZERO);
}
Also used : List(java.util.List) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 2 with StepDefinitionMatch

use of cucumber.runtime.StepDefinitionMatch in project cucumber-jvm by cucumber.

the class UsageFormatterTest method resultWithStep.

@Test
public void resultWithStep() {
    Appendable out = mock(Appendable.class);
    UsageFormatter usageFormatter = new UsageFormatter(out);
    StepDefinitionMatch match = mockStepDefinitionMatch();
    usageFormatter.match(match);
    Result result = mock(Result.class);
    when(result.getDuration()).thenReturn(12345L);
    when(result.getStatus()).thenReturn(Result.PASSED);
    usageFormatter.result(result);
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertEquals(usageMap.size(), 1);
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertEquals(durationEntries.size(), 1);
    assertEquals(durationEntries.get(0).name, "step");
    assertEquals(durationEntries.get(0).durations.size(), 1);
    assertEquals(durationEntries.get(0).durations.get(0).duration, BigDecimal.valueOf(12345));
}
Also used : List(java.util.List) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 3 with StepDefinitionMatch

use of cucumber.runtime.StepDefinitionMatch in project cucumber-jvm by cucumber.

the class FromDataTableTest method runStepDef.

private StepDefs runStepDef(Method method, List<DataTableRow> rows) throws Throwable {
    StepDefs stepDefs = new StepDefs();
    StepDefinition stepDefinition = new StubStepDefinition(stepDefs, method, "some pattern");
    Step stepWithRows = new Step(NO_COMMENTS, "Given ", "something", 10, rows, null);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(NO_ARGS, stepDefinition, "some.feature", stepWithRows, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(new I18n("en"));
    return stepDefs;
}
Also used : StubStepDefinition(cucumber.runtime.StubStepDefinition) StepDefinition(cucumber.runtime.StepDefinition) StubStepDefinition(cucumber.runtime.StubStepDefinition) Step(gherkin.formatter.model.Step) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) I18n(gherkin.I18n)

Example 4 with StepDefinitionMatch

use of cucumber.runtime.StepDefinitionMatch in project cucumber-jvm by cucumber.

the class UsageFormatterTest method resultWithZeroDuration.

@Test
public void resultWithZeroDuration() {
    Appendable out = mock(Appendable.class);
    UsageFormatter usageFormatter = new UsageFormatter(out);
    StepDefinitionMatch match = mockStepDefinitionMatch();
    usageFormatter.match(match);
    Result result = mock(Result.class);
    when(result.getDuration()).thenReturn(0L);
    when(result.getStatus()).thenReturn(Result.PASSED);
    usageFormatter.result(result);
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertEquals(usageMap.size(), 1);
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertEquals(durationEntries.size(), 1);
    assertEquals(durationEntries.get(0).name, "step");
    assertEquals(durationEntries.get(0).durations.size(), 1);
    assertEquals(durationEntries.get(0).durations.get(0).duration, BigDecimal.ZERO);
}
Also used : List(java.util.List) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 5 with StepDefinitionMatch

use of cucumber.runtime.StepDefinitionMatch in project cucumber-jvm by cucumber.

the class UsageFormatterTest method mockStepDefinitionMatch.

private StepDefinitionMatch mockStepDefinitionMatch() {
    StepDefinitionMatch match = mock(StepDefinitionMatch.class, Mockito.RETURNS_MOCKS);
    when(match.getPattern()).thenReturn("stepDef");
    when(match.getStepLocation()).thenReturn(new StackTraceElement("x", "y", "z", 3));
    when(match.getStepName()).thenReturn("step");
    return match;
}
Also used : StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch)

Aggregations

StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)6 Result (gherkin.formatter.model.Result)3 List (java.util.List)3 Test (org.junit.Test)3 Step (gherkin.formatter.model.Step)2 StepDefinition (cucumber.runtime.StepDefinition)1 StubStepDefinition (cucumber.runtime.StubStepDefinition)1 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)1 I18n (gherkin.I18n)1