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()]));
}
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);
}
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));
}
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());
}
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());
}
Aggregations