1

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
assylias
  • 321,522
  • 82
  • 660
  • 783

2 Answers2

1

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();
        }
    });
}
assylias
  • 321,522
  • 82
  • 660
  • 783
  • I've developed treeTableViewWrap recently for jemmyfx, and did some fixes for jemmy. I'm an sqe engineer of jfx. What I can say: jemmy is not supposed to do everything what can be imagined. It is supposed to do basic things. So your approach is an appropriate. If you have ideas about testing functionality, which can be added (like, format checkers, or smth like that) - you can file an issue(RFE) in jira under jemmy project, and discuss that with Shura Iline, for instance. – Alexander Kirov Sep 05 '13 at 20:21
  • @AlexanderKirov Good to know - I have started using JemmyFX extensively recently and the learning curve is quite steep + I often need to find workarounds. I'll try to file issues with proposed solution as I find them. – assylias Sep 05 '13 at 20:24
-1

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%");
             }
         };
    }
});
damat-perdigannat
  • 5,780
  • 1
  • 17
  • 33