/**
* Test the {@link ColumnSortList} class.
*/
public void testSortList() {
// Create a new list
ColumnSortList sortList = new ColumnSortList();
assertEquals(0, sortList.size());
// Add one item
sortList.add(new ColumnSortInfo(4, false));
assertEquals(1, sortList.size());
assertEquals(4, sortList.getPrimaryColumn());
assertFalse(sortList.isPrimaryAscending());
assertTrue(sortList.getPrimaryColumnSortInfo().equals(new ColumnSortInfo(4, false)));
// Add more items
sortList.add(new ColumnSortInfo(6, false));
sortList.add(new ColumnSortInfo(8, true));
sortList.add(new ColumnSortInfo(10, true));
assertEquals(4, sortList.size());
assertEquals(10, sortList.getPrimaryColumn());
assertTrue(sortList.isPrimaryAscending());
// Check all of the entries in the sort lise
int count = 0;
for (ColumnSortInfo info : sortList) {
switch (count) {
case 0:
assertTrue(info.equals(new ColumnSortInfo(10, true)));
break;
case 1:
assertTrue(info.equals(new ColumnSortInfo(8, true)));
break;
case 2:
assertTrue(info.equals(new ColumnSortInfo(6, false)));
break;
case 3:
assertTrue(info.equals(new ColumnSortInfo(4, false)));
break;
}
count++;
}
// Add an existing item
sortList.add(new ColumnSortInfo(6, false));
assertEquals(4, sortList.size());
assertEquals(6, sortList.getPrimaryColumn());
assertFalse(sortList.isPrimaryAscending());
// Add an existing column, different order
sortList.add(new ColumnSortInfo(8, false));
assertEquals(4, sortList.size());
assertEquals(8, sortList.getPrimaryColumn());
assertFalse(sortList.isPrimaryAscending());
// Compare two lists
ColumnSortList sortList1 = new ColumnSortList();
sortList1.add(new ColumnSortInfo(1, true));
sortList1.add(new ColumnSortInfo(2, false));
sortList1.add(new ColumnSortInfo(3, true));
ColumnSortList sortList2 = new ColumnSortList();
sortList2.add(new ColumnSortInfo(1, true));
sortList2.add(new ColumnSortInfo(2, false));
sortList2.add(new ColumnSortInfo(3, true));
ColumnSortList sortList3 = new ColumnSortList();
sortList3.add(new ColumnSortInfo(1, true));
sortList3.add(new ColumnSortInfo(4, false));
sortList3.add(new ColumnSortInfo(3, true));
ColumnSortList sortList4 = new ColumnSortList();
sortList4.add(new ColumnSortInfo(1, true));
sortList4.add(new ColumnSortInfo(2, true));
sortList4.add(new ColumnSortInfo(3, true));
assertTrue(sortList1.equals(sortList2));
assertFalse(sortList1.equals(sortList3));
assertFalse(sortList1.equals(sortList4));
assertFalse(sortList3.equals(sortList4));
}