Skip to content
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

(feat) hasTableCell(): Match the string value of cell item. #210

Merged
merged 1 commit into from
Mar 30, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -78,7 +78,12 @@ private static boolean hasItems(TableView tableView,

private static boolean hasCellValue(Cell cell,
Object value) {
return !cell.isEmpty() && Objects.equals(cell.getItem(), value);
return !cell.isEmpty() && hasItemValue(cell.getItem(), value);
}

private static boolean hasItemValue(Object item,
Object value) {
return Objects.equals(item, value) || Objects.equals(item.toString(), value);
}

}
Expand Up @@ -59,14 +59,16 @@ public void setup() throws Exception {
FxToolkit.setupSceneRoot(() -> {
tableView = new TableView<>();
tableView.setItems(observableArrayList(
ImmutableMap.of("name", "alice"),
ImmutableMap.of("name", "bob"),
ImmutableMap.of("name", "carol"),
ImmutableMap.of("name", "dave")
));
ImmutableMap.of("name", "alice", "age", 30),
ImmutableMap.of("name", "bob", "age", 31),
ImmutableMap.of("name", "carol"),
ImmutableMap.of("name", "dave")
));
TableColumn<Map, String> tableColumn0 = new TableColumn<>("name");
tableColumn0.setCellValueFactory(new MapValueFactory<>("name"));
tableView.getColumns().add(tableColumn0);
TableColumn<Map, Integer> tableColumn1 = new TableColumn<>("age");
tableColumn1.setCellValueFactory(new MapValueFactory<>("age"));
tableView.getColumns().setAll(tableColumn0, tableColumn1);
return new StackPane(tableView);
});
FxToolkit.showStage();
Expand All @@ -80,24 +82,34 @@ public void setup() throws Exception {
public void hasTableCell() {
// expect:
assertThat(tableView, TableViewMatchers.hasTableCell("alice"));
assertThat(tableView, TableViewMatchers.hasTableCell("bob"));
}

@Test
public void hasTableCell_with_null_fails() {
public void hasTableCell_fails() {
// expect:
exception.expect(AssertionError.class);
exception.expectMessage("Expected: TableView has table cell \"null\"\n");
exception.expectMessage("Expected: TableView has table cell \"foobar\"\n");

assertThat(tableView, TableViewMatchers.hasTableCell(null));
assertThat(tableView, TableViewMatchers.hasTableCell("foobar"));
}

@Test
public void hasTableCell_fails() {
public void hasTableCell_with_toString() {
// expect:
assertThat(tableView, TableViewMatchers.hasTableCell("30"));

// and:
assertThat(tableView, TableViewMatchers.hasTableCell(31));
}

@Test
public void hasTableCell_with_null_fails() {
// expect:
exception.expect(AssertionError.class);
exception.expectMessage("Expected: TableView has table cell \"foobar\"\n");
exception.expectMessage("Expected: TableView has table cell \"null\"\n");

assertThat(tableView, TableViewMatchers.hasTableCell("foobar"));
assertThat(tableView, TableViewMatchers.hasTableCell(null));
}

@Test
Expand Down