Search in sources :

Example 16 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class JRubyBackend method executeStepdef.

void executeStepdef(RubyObject stepdef, I18n i18n, Object[] args) {
    ArrayList<IRubyObject> jrubyArgs = new ArrayList<IRubyObject>();
    // jrubyWorld.@__gherkin_i18n = i18n
    RubyObject jrubyI18n = (RubyObject) JavaEmbedUtils.javaToRuby(stepdef.getRuntime(), i18n);
    currentWorld.callMethod("instance_variable_set", new IRubyObject[] { stepdef.getRuntime().newSymbol("@__gherkin_i18n"), jrubyI18n });
    jrubyArgs.add(currentWorld);
    for (Object o : args) {
        if (o == null) {
            jrubyArgs.add(null);
        } else if (o instanceof DataTable) {
            //Add a datatable as it stands...
            jrubyArgs.add(JavaEmbedUtils.javaToRuby(stepdef.getRuntime(), o));
        } else {
            jrubyArgs.add(stepdef.getRuntime().newString((String) o));
        }
    }
    stepdef.callMethod("execute", jrubyArgs.toArray(new IRubyObject[jrubyArgs.size()]));
}
Also used : DataTable(cucumber.api.DataTable) ArrayList(java.util.ArrayList) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 17 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class TableConverterTest method converts_to_map_of_enum_to_int.

@Test
public void converts_to_map_of_enum_to_int() {
    DataTable table = TableParser.parse("|RED|BLUE|\n|6|7|\n|8|9|\n", null);
    HashMap<Color, Integer> map1 = new HashMap<Color, Integer>() {

        {
            put(Color.RED, 6);
            put(Color.BLUE, 7);
        }
    };
    HashMap<Color, Integer> map2 = new HashMap<Color, Integer>() {

        {
            put(Color.RED, 8);
            put(Color.BLUE, 9);
        }
    };
    List<Map<Color, Integer>> converted = table.asMaps(Color.class, Integer.class);
    assertEquals(asList(map1, map2), converted);
}
Also used : DataTable(cucumber.api.DataTable) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 18 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class TableConverterTest method converts_table_of_single_column_to_list_of_with_string_constructor.

@Test
public void converts_table_of_single_column_to_list_of_with_string_constructor() {
    DataTable table = TableParser.parse("|count|\n|5|\n|6|\n|7|\n", null);
    List<WithStringConstructor> expected = asList(new WithStringConstructor("count"), new WithStringConstructor("5"), new WithStringConstructor("6"), new WithStringConstructor("7"));
    assertEquals(expected, table.asList(WithStringConstructor.class));
}
Also used : DataTable(cucumber.api.DataTable) Test(org.junit.Test)

Example 19 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class TableConverterTest method converts_table_to_list_of_list_of_integers_and_back.

@Test
public void converts_table_to_list_of_list_of_integers_and_back() {
    DataTable table = TableParser.parse("|3|5|\n|6|7|\n", null);
    List<List<Integer>> converted = table.asLists(Integer.class);
    assertEquals(asList(asList(3, 5), asList(6, 7)), converted);
    assertEquals("      | 3 | 5 |\n      | 6 | 7 |\n", table.toTable(converted).toString());
}
Also used : DataTable(cucumber.api.DataTable) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 20 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class TableConverterTest method converts_to_list_of_java_bean_and_almost_back.

@Test
public void converts_to_list_of_java_bean_and_almost_back() {
    DataTable table = TableParser.parse("|Birth Date|Death Cal|\n|1957-05-10|1979-02-02|\n", PARAMETER_INFO);
    List<UserBean> converted = table.asList(UserBean.class);
    assertEquals(sidsBirthday(), converted.get(0).getBirthDate());
    assertEquals(sidsDeathcal(), converted.get(0).getDeathCal());
    assertEquals("      | birthDate  | deathCal   |\n      | 1957-05-10 | 1979-02-02 |\n", table.toTable(converted).toString());
}
Also used : DataTable(cucumber.api.DataTable) Test(org.junit.Test)

Aggregations

DataTable (cucumber.api.DataTable)34 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)10 List (java.util.List)7 DataTableRow (gherkin.formatter.model.DataTableRow)4 Arrays.asList (java.util.Arrays.asList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)3 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)2 Type (java.lang.reflect.Type)2 And (cucumber.api.java.en.And)1 SingleValueConverter (cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter)1 Delta (cucumber.deps.difflib.Delta)1 CucumberException (cucumber.runtime.CucumberException)1 Utils.listItemType (cucumber.runtime.Utils.listItemType)1 Utils.mapKeyType (cucumber.runtime.Utils.mapKeyType)1 Utils.mapValueType (cucumber.runtime.Utils.mapValueType)1 TableConverter (cucumber.runtime.table.TableConverter)1 En (gherkin.lexer.En)1 Lexer (gherkin.lexer.Lexer)1