Skip to content

Instantly share code, notes, and snippets.

@torakiki
Created November 30, 2018 15:33
Show Gist options
  • Select an option

  • Save torakiki/6b1e3d5a6090bca33c6720e81b367765 to your computer and use it in GitHub Desktop.

Select an option

Save torakiki/6b1e3d5a6090bca33c6720e81b367765 to your computer and use it in GitHub Desktop.
Failing TableViewMatchers.hasTableCell
import static javafx.collections.FXCollections.observableArrayList;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.testfx.api.FxAssert;
import org.testfx.framework.junit.ApplicationTest;
import org.testfx.matcher.control.TableViewMatchers;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.MapValueFactory;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class UnitTest extends ApplicationTest {
TableView<Map> tableView;
TableColumn<Map, String> tableColumn0;
@Override
public void start(Stage stage) {
tableView = new TableView<>();
tableColumn0 = new TableColumn<>("name");
tableColumn0.setId("tableColumn0");
tableColumn0.setCellValueFactory(new MapValueFactory<>("name"));
TableColumn<Map, Integer> tableColumn1 = new TableColumn<>("age");
tableColumn1.setCellValueFactory(new MapValueFactory<>("age"));
tableView.getColumns().setAll(tableColumn0, tableColumn1);
Scene scene = new Scene(new StackPane(tableView));
stage.setScene(scene);
stage.show();
}
@Test
public void hasTableCell() {
Map<String, Object> row1 = new HashMap<>(2);
row1.put("name", "alice");
row1.put("age", 30);
Map<String, Object> row2 = new HashMap<>(2);
row2.put("name", "bob");
row2.put("age", 31);
Map<String, Object> row3 = new HashMap<>(1);
row3.put("name", "carol");
Map<String, Object> row4 = new HashMap<>(1);
row4.put("name", "dave");
tableView.setItems(observableArrayList(row1, row2, row3, row4));
FxAssert.verifyThat(tableView, TableViewMatchers.hasTableCell("alice"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment