1 package com.tonbeller.wcf.table; 2 3 import junit.framework.TestCase; 4 5 import com.tonbeller.wcf.controller.TestContext; 6 import com.tonbeller.wcf.selection.SelectionModel; 7 8 public class TableModelDecoratorTest extends TestCase { 9 10 class My extends TableModelDecorator { 11 int changeCount = 0; 12 public My(TableModel model) { 13 super(model); 14 } 15 public void tableModelChanged(TableModelChangeEvent event) { 16 changeCount += 1; 17 } 18 } 19 20 public TableModelDecoratorTest(String arg0) { 21 super(arg0); 22 } 23 24 public void testEvents() { 25 TableColumn tc = new TableColumn(0); 26 RowComparator comp = new RowComparator(tc); 27 28 TableModel model = new TestModel(); 29 SortedTableModel sorter = new SortedTableModel(model); 30 My my = new My(sorter); 31 32 assertEquals("Hello World: 0", my.getRow(0).getValue(0)); 33 tc.setDescending(false); 34 sorter.sort(comp); 35 assertEquals("Hello World: 0", my.getRow(0).getValue(0)); 36 tc.setDescending(true); 37 sorter.sort(comp); 38 assertEquals("Hello World: 9", my.getRow(0).getValue(0)); 39 model.fireModelChanged(false); 40 assertEquals("Hello World: 0", my.getRow(0).getValue(0)); 41 assertEquals("change count", 1, my.changeCount); 42 } 43 44 public void testSelectionCleared() throws Exception { 45 TableModel model = new TestModel(); 46 TableComponent comp = new TableComponent("id", null, model); 47 comp.initialize(new TestContext()); 48 49 SelectionModel sm = comp.getSelectionModel(); 50 sm.add(model.getRow(0)); 51 model.fireModelChanged(false); 52 assertTrue(!sm.isEmpty()); 53 model.fireModelChanged(true); 54 assertTrue(sm.isEmpty()); 55 } 56 } 57 | Popular Tags |