@Test public void testGetNextRowDown() { JTable jTable = new JTable(10, 1); NextRowProvider nextRowProvider = NextRowProviderFactory.getNextFilteredTableRow(jTable); for (int i = 0; i < 10; i++) { assertEquals(i, nextRowProvider.getNextRow()); } assertEquals(-1, nextRowProvider.getNextRow()); }
@Test public void testGetNextRowUp() { JTable jTable = new JTable(10, 1); NextRowProvider nextRowProvider = NextRowProviderFactory.getPreviousFilteredTableRow(jTable); for (int i = 9; i >= 0; i--) { int nextRow = nextRowProvider.getNextRow(); // assertEquals(i, nextRow); } assertEquals(-1, nextRowProvider.getNextRow()); }
@Test public void testGetNextRowFromMiddleUp() { JTable jTable = new JTable(10, 1); jTable.getSelectionModel().setSelectionInterval(4, 4); NextRowProvider nextRowProvider = NextRowProviderFactory.getPreviousFilteredTableRow(jTable); for (int i = 3; i >= 0; i--) { assertEquals(i, nextRowProvider.getNextRow()); } for (int i = 9; i > 3; i--) { assertEquals(i, nextRowProvider.getNextRow()); } assertEquals(-1, nextRowProvider.getNextRow()); }
@Test public void testGetNextRowFromMiddleDown() { JTable jTable = new JTable(10, 1); jTable.getSelectionModel().setSelectionInterval(4, 4); NextRowProvider nextRowProvider = NextRowProviderFactory.getNextFilteredTableRow(jTable); for (int i = 5; i < 10; i++) { assertEquals(i, nextRowProvider.getNextRow()); } for (int i = 0; i < 5; i++) { assertEquals(i, nextRowProvider.getNextRow()); } assertEquals(-1, nextRowProvider.getNextRow()); }
@Test public void testFilteredTable() { JTable jTable = new JTable(10, 1); TableRowSorter rowSorter = new TableRowSorter(jTable.getModel()); jTable.setRowSorter(rowSorter); RowFilter<TableModel, Integer> rowFilter = new RowFilter<TableModel, Integer>() { public boolean include(Entry<? extends TableModel, ? extends Integer> entry) { return entry.getIdentifier().intValue() % 2 == 0; } }; rowSorter.setRowFilter(rowFilter); NextRowProvider nextRowProvider = NextRowProviderFactory.getNextFilteredTableRow(jTable); for (int i = 0; i < 5; i++) { int nextRow = nextRowProvider.getNextRow(); assertEquals(i * 2, nextRow); } assertEquals(-1, nextRowProvider.getNextRow()); }