Question

For testing purposes (using JemmyFX), I want to check that the content of a TableView is appropriately formatted. For example: one column is of type Double and a cell factory has been applied to show the number as a percent: 20%.

How can I verify that when the value is 0.2d, the cell is showing as 20%?

Ideally I am looking for something along those lines:

TableColumn<VatInvoice, Double> percentVat = ...
assertEquals(percentVat.getTextualRepresentation(), "20%");

Note: I have tried to use the TableCell directly like below but getText() returns null:

TableCell<VatInvoice, Double> tc = percentVat.getCellFactory().call(percentVat);
tc.itemProperty().set(0.2);
assertEquals(tc.getText(), "20%"); //tc.getText() is null
Was it helpful?

Solution

The best I have found so far, using JemmyFX, is the following:

public String getCellDataAsText(TableViewDock table, int row, int column) {
    final TableCellItemDock dock = new TableCellItemDock(table.asTable(), row, column);
    return dock.wrap().waitState(new State<String>() {
        @Override public String reached() {
            return dock.wrap().cellWrap().getControl().getText();
        }
    });
}

OTHER TIPS

You can try editing the cell factory.

tc.setCellFactory(new Callback<TableColumn, TableCell>(){
    @Override
    public TableCell call(TableColumn param){
         return new TableCell(){
             @Override
             public void updateItem(Object item, boolean isEmpty){
                 //...logic to format the text
                 assertEquals(getText(), "20%");
             }
         };
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top