Skip to content

More precise handling of the XStream errors #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ private <T> List<T> toListOfComplexType(DataTable dataTable, Class<T> itemType)
return Collections.unmodifiableList((List<T>) xStream.unmarshal(reader));
} catch (AbstractReflectionConverter.UnknownFieldException e) {
throw new CucumberException(e.getShortMessage());
} catch (AbstractReflectionConverter.DuplicateFieldException e) {
throw new CucumberException(e.getShortMessage());
} catch (ConversionException e) {
throw new CucumberException(String.format("Can't assign null value to one of the primitive fields in %s. Please use boxed types.", e.get("class")));
if (e.getCause() instanceof NullPointerException) {
throw new CucumberException(String.format("Can't assign null value to one of the primitive fields in %s. Please use boxed types.", e.get("class")));
} else {
throw new CucumberException(e);
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions core/src/test/java/cucumber/runtime/table/ToDataTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ public void gives_a_nice_error_message_when_primitive_field_is_null() {
}
}

@Test
public void gives_a_meaningfull_error_message_when_field_is_repeated() {
try {
tc.toList(UserPojo.class, TableParser.parse("" +
"| credits | credits |\n" +
"| 5 | 5 |\n" +
"", PARAMETER_INFO)
);
fail();
} catch (CucumberException e) {
assertEquals("Duplicate field credits", e.getMessage());
}
}

@Test
public void converts_list_of_beans_to_table_with_explicit_columns() {
List<UserPojo> users = tc.toList(UserPojo.class, personTable());
Expand Down