Search in sources :

Example 1 with Parameters

use of org.jbehave.core.steps.Parameters in project javaparser by javaparser.

the class CommentParsingSteps method thenTheBlockCommentsHaveTheFollowingPositions.

@Then("the block comments have the following positions: $table")
public void thenTheBlockCommentsHaveTheFollowingPositions(ExamplesTable examplesTable) {
    int index = 0;
    for (Parameters exampleRow : examplesTable.getRowsAsParameters()) {
        Comment expectedLineComment = toComment(exampleRow, new BlockComment());
        Comment lineCommentUnderTest = getCommentAt(commentsCollection.getBlockComments(), index);
        Range underTestRange = lineCommentUnderTest.getRange().get();
        Range expectedRange = expectedLineComment.getRange().get();
        assertThat(underTestRange.begin.line, is(expectedRange.begin.line));
        assertThat(underTestRange.begin.column, is(expectedRange.begin.column));
        assertThat(underTestRange.end.line, is(expectedRange.end.line));
        assertThat(underTestRange.end.column, is(expectedRange.end.column));
        index++;
    }
}
Also used : Parameters(org.jbehave.core.steps.Parameters) Range(com.github.javaparser.Range) Then(org.jbehave.core.annotations.Then)

Example 2 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class TraderSteps method theTradersActivityIs.

@Then("the current trader activity is: $activityTable")
public void theTradersActivityIs(ExamplesTable activityTable) {
    for (int i = 0; i < activityTable.getRowCount(); i++) {
        Parameters row = activityTable.withDefaults(this.ranksTable.getRowAsParameters(i)).getRowAsParameters(i);
        System.out.println(row.valueAs("name", Trader.class) + " (" + row.valueAs("rank", String.class, "N/A") + ") has done " + row.valueAs("trades", Integer.class) + " trades");
    }
}
Also used : Parameters(org.jbehave.core.steps.Parameters) Then(org.jbehave.core.annotations.Then)

Example 3 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldThrowExceptionIfValuesOrRowsAreNotFound.

@Test
public void shouldThrowExceptionIfValuesOrRowsAreNotFound() throws Exception {
    // Given
    ExamplesTableFactory factory = createFactory();
    // When
    String tableAsString = "|one|two|\n|11|22|\n";
    ExamplesTable examplesTable = factory.createExamplesTable(tableAsString);
    // Then
    Parameters integers = examplesTable.getRowAsParameters(0);
    assertThat(integers.<Integer>valueAs("one", Integer.class), equalTo(11));
    try {
        integers.valueAs("unknown", Integer.class);
        throw new AssertionError("Exception was not thrown");
    } catch (ValueNotFound e) {
        assertThat(e.getMessage(), equalTo("unknown"));
    }
    try {
        examplesTable.getRowAsParameters(1);
        throw new AssertionError("Exception was not thrown");
    } catch (RowNotFound e) {
        assertThat(e.getMessage(), equalTo("1"));
    }
}
Also used : RowNotFound(org.jbehave.core.model.ExamplesTable.RowNotFound) AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) ValueNotFound(org.jbehave.core.steps.ConvertedParameters.ValueNotFound) Test(org.junit.Test)

Example 4 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldReplaceNamedParameterValuesInValuePart.

@Test
public void shouldReplaceNamedParameterValuesInValuePart() throws Exception {
    // Given
    ExamplesTableFactory factory = createFactory();
    // When
    String tableAsString = "|Name|Value|\n|name1|foo-<value>-bar|";
    Map<String, String> namedParameters = new HashMap<>();
    namedParameters.put("value", "value1");
    ExamplesTable table = factory.createExamplesTable(tableAsString).withNamedParameters(namedParameters);
    // Then
    Parameters firstRow = table.getRowsAsParameters(true).get(0);
    Map<String, String> firstRowValues = firstRow.values();
    assertThat(firstRowValues.containsKey("Value"), is(true));
    assertThat(firstRow.<String>valueAs("Value", String.class), is("foo-value1-bar"));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) Test(org.junit.Test)

Example 5 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldParseTableWithUntrimmedCommentsInValues.

@Test
public void shouldParseTableWithUntrimmedCommentsInValues() {
    String tableWithEmptyValues = "{commentSeparator=#, trim=false}\n|one #comment|two|\n |11 #comment|12 #comment|\n |21|22|\n";
    ExamplesTable table = new ExamplesTable(tableWithEmptyValues);
    assertThat(table.getRowCount(), equalTo(2));
    for (Parameters row : table.getRowsAsParameters()) {
        Map<String, String> values = row.values();
        assertThat(values.size(), equalTo(2));
        for (String column : values.keySet()) {
            assertThat(values.get(column), not(containsString("#comment")));
        }
    }
    assertThat(table.asString(), equalTo("{commentSeparator=#, trim=false}\n|one |two|\n|11 |12 |\n|21|22|\n"));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) Test(org.junit.Test)

Aggregations

Parameters (org.jbehave.core.steps.Parameters)17 AsParameters (org.jbehave.core.annotations.AsParameters)10 Test (org.junit.Test)10 Then (org.jbehave.core.annotations.Then)6 Range (com.github.javaparser.Range)3 OutcomesTable (org.jbehave.core.model.OutcomesTable)2 MethodReturningConverter (org.jbehave.core.steps.ParameterConverters.MethodReturningConverter)2 Locale (java.util.Locale)1 Given (org.jbehave.core.annotations.Given)1 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)1 RowNotFound (org.jbehave.core.model.ExamplesTable.RowNotFound)1 ValueNotFound (org.jbehave.core.steps.ConvertedParameters.ValueNotFound)1 Organization (org.jbehave.example.spring.security.domain.Organization)1 UserBuilder (org.jbehave.example.spring.security.domain.UserBuilder)1