public final void testBrowseFSDialogTableModel() {
// table clean?
assertEquals(0, model.getColumnCount());
assertEquals(0, model.getRowCount());
IBrowseFSDialogEntry data;
// adds row for tests
model.addRow(data = new IBrowseFSDialogEntry() {
@Override
public Object getValue(int xPosition) {
switch (xPosition) {
case 0:
return 0;
case 1:
return 1;
case 2:
return 2;
default:
return null;
}
}
@Override
public String[] getColumnNames() {
return new String[] { "A", "B", "C" };
}
@Override
public File getFile() {
return null;
}
});
// column and row count test
assertEquals(3, model.getColumnCount());
assertEquals(1, model.getRowCount());
// column names test
assertEquals("A", model.getColumnName(0));
assertEquals("B", model.getColumnName(1));
assertEquals("C", model.getColumnName(2));
// value test
assertEquals(0, model.getValueAt(0, 0));
assertEquals(1, model.getValueAt(0, 1));
assertEquals(2, model.getValueAt(0, 2));
// data test
assertEquals(data, model.getData(0));
// adds another row with different column names too the previous
model.addRow(data = new IBrowseFSDialogEntry() {
@Override
public Object getValue(int xPosition) {
switch (xPosition) {
case 0:
return 0;
case 1:
return 1;
default:
return null;
}
}
@Override
public String[] getColumnNames() {
return new String[] { "D", "E" };
}
@Override
public File getFile() {
return null;
}
});
// column and row count test
assertEquals(5, model.getColumnCount());
assertEquals(2, model.getRowCount());
// column names test
assertEquals("A", model.getColumnName(0));
assertEquals("B", model.getColumnName(1));
assertEquals("C", model.getColumnName(2));
assertEquals("D", model.getColumnName(3));
assertEquals("E", model.getColumnName(4));
// value test 1st row
assertEquals(0, model.getValueAt(0, 0));
assertEquals(1, model.getValueAt(0, 1));
assertEquals(2, model.getValueAt(0, 2));
assertEquals(null, model.getValueAt(0, 4));
assertEquals(null, model.getValueAt(0, 4));
// value test 2nd row
assertEquals(null, model.getValueAt(1, 0));
assertEquals(null, model.getValueAt(1, 1));
assertEquals(null, model.getValueAt(1, 2));
assertEquals(0, model.getValueAt(1, 3));
assertEquals(1, model.getValueAt(1, 4));
// data test
assertEquals(data, model.getData(1));
// same data again
model.addRow(data);
// column and row count test
assertEquals(5, model.getColumnCount());
assertEquals(3, model.getRowCount());
// value test 3nd row
assertEquals(null, model.getValueAt(2, 0));
assertEquals(null, model.getValueAt(2, 1));
assertEquals(null, model.getValueAt(2, 2));
assertEquals(0, model.getValueAt(2, 3));
assertEquals(1, model.getValueAt(2, 4));
// data test
assertEquals(data, model.getData(2));
model.addRow(data = new IBrowseFSDialogEntry() {
@Override
public Object getValue(int xPosition) {
switch (xPosition) {
case 0:
return 0;
case 1:
return 1;
case 2:
return 2;
default:
return null;
}
}
@Override
public String[] getColumnNames() {
return new String[] { "A", "C", "E" };
}
@Override
public File getFile() {
return null;
}
});
// column and row count test
assertEquals(5, model.getColumnCount());
assertEquals(4, model.getRowCount());
// value test 3nd row
assertEquals(0, model.getValueAt(3, 0)); // A
assertEquals(null, model.getValueAt(3, 1)); // B
assertEquals(1, model.getValueAt(3, 2)); // C
assertEquals(null, model.getValueAt(3, 3)); // D
assertEquals(2, model.getValueAt(3, 4)); // E
assertEquals(data, model.getData(3));
model.addRow(data = new IBrowseFSDialogEntry() {
@Override
public Object getValue(int xPosition) {
switch (xPosition) {
case 0: