Clover coverage report - angkor - 0.4
Coverage timestamp: ti okt 15 2002 22:32:48 CEST
file stats: LOC: 144   Methods: 6
NCLOC: 98   Classes: 1
Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
TableTest.java 100% 100% 100% 100%
 1   
 /*
 2   
  * Angkor Web Framework
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at gnu.org.
 6   
  */
 7   
 
 8   
 package com.tirsen.angkor.test.unit.widget;
 9   
 
 10   
 import com.tirsen.angkor.table.*;
 11   
 import com.tirsen.angkor.event.Action;
 12   
 import com.tirsen.angkor.widget.TextLabel;
 13   
 import com.tirsen.angkor.test.unit.MockPipeline;
 14   
 import junit.framework.TestCase;
 15   
 
 16   
 import java.text.Format;
 17   
 
 18   
 /**
 19   
  * TODO document TableTest.
 20   
  *
 21   
  * <!-- $Id: TableTest.java,v 1.1 2002/10/07 19:49:23 tirsen Exp $ -->
 22   
  * <!-- $Author: tirsen $ -->
 23   
  *
 24   
  * @author Jon Tirs&acute;n (tirsen@users.sourceforge.net)
 25   
  * @version $Revision: 1.1 $
 26   
  */
 27   
 public class TableTest extends TestCase
 28   
 {
 29   
     private int rowCount = 10;
 30   
     private MockPipeline pipeline = new MockPipeline();
 31   
 
 32  2
     public TableTest(String s)
 33   
     {
 34  2
         super(s);
 35   
     }
 36   
 
 37  2
     protected void setUp() throws Exception
 38   
     {
 39  2
         pipeline.start();
 40  2
         pipeline.getRenderContext().getEventQueue().setPostponeEvents(false);
 41   
     }
 42   
 
 43  2
     protected void tearDown() throws Exception
 44   
     {
 45  2
         pipeline.end();
 46   
     }
 47   
 
 48  6
     private void load(DefaultTableModel model) throws Exception
 49   
     {
 50  6
         for(int i = model.getStart(); i <= model.getEnd(); i++)
 51   
         {
 52  28
             model.setRow(i, new Object[] { new Integer(i), "Text " + i });
 53   
         }
 54  6
         model.setRowCount(rowCount);
 55   
     }
 56   
 
 57  1
     public void testScroller() throws Exception
 58   
     {
 59  1
         Table table = new Table();
 60  1
         DefaultTableModel model = (DefaultTableModel) table.getTableModel();
 61  1
         table.setReadOnly(true);
 62  1
         model.addColumn("Row Number");
 63  1
         model.addColumn("Row Text");
 64  1
         model.setRowCount(rowCount);
 65  1
         table.setModel(model);
 66   
 
 67  1
         load(model);
 68  1
         assertTrue("incorrect number of rows loaded", model.getRowCount() == rowCount);
 69   
 
 70  1
         TableScroller scroller = new TableScroller();
 71  1
         table.setNumberOfScrollRows(4);
 72  1
         scroller.setTable(table);
 73   
 
 74  1
         Action next = scroller.getNextAction();
 75  1
         Action previous = scroller.getPreviousAction();
 76   
 
 77  1
         assertTrue("previous enabled at beginning of table", !previous.isEnabled());
 78  1
         assertTrue("next disabled at beginning of table", next.isEnabled());
 79   
 
 80  1
         load(model);
 81   
 
 82  1
         assertTrue("incorrect number of rows loaded", model.getEnd() - model.getStart() + 1 == 4);
 83   
 
 84  1
         while(next.isEnabled())
 85   
         {
 86  2
             System.out.println("forward");
 87  2
             next.actionPerformed(null);
 88  2
             System.out.println("table.getStartRow() = " + table.getStartRow());
 89  2
             System.out.println("table.getEndRow() = " + table.getEndRow());
 90   
 
 91  2
             assertTrue("previous still disabled after forward scroll", previous.isEnabled());
 92   
 
 93  2
             load(model);
 94   
 
 95  2
             int rowToCheck = table.getStartRow();
 96  2
             int number = Integer.parseInt(((TextLabel) table.getCellView(rowToCheck, 0)).getFormattedText());
 97   
             //int number = ((Integer) model.getValueAt(rowToCheck, 0).getValue()).intValue();
 98  2
             assertTrue("wrong number is displayed at (" + rowToCheck + ",0) cell", number == rowToCheck);
 99   
         }
 100   
 
 101  1
         while(previous.isEnabled())
 102   
         {
 103  2
             System.out.println("backward");
 104  2
             previous.actionPerformed(null);
 105  2
             System.out.println("table.getStartRow() = " + table.getStartRow());
 106  2
             System.out.println("table.getEndRow() = " + table.getEndRow());
 107   
 
 108  2
             assertTrue("next still disabled after backward scroll", next.isEnabled());
 109   
 
 110  2
             load(model);
 111   
 
 112  2
             int rowToCheck = table.getStartRow();
 113  2
             int number = ((Integer) model.getValueAt(rowToCheck, 0).getValue()).intValue();
 114  2
             assertTrue("wrong number is displayed at (" + rowToCheck + ",0) cell", number == rowToCheck);
 115   
         }
 116   
     }
 117   
 
 118  1
     public void testModelChange() throws Exception
 119   
     {
 120  1
         DefaultTableModel model = new DefaultTableModel();
 121  1
         model.addColumn("Number");
 122  1
         Integer firstvalue = new Integer(1);
 123  1
         model.addRow(new Object[] { firstvalue });
 124   
 
 125  1
         Table table = new Table();
 126  1
         table.setReadOnly(true);
 127  1
         table.setModel(model);
 128   
 
 129  1
         TextLabel firstview = (TextLabel) table.getCellView(0, 0);
 130  1
         assertSame("views are reinstantiated", firstview, table.getCellView(0, 0));
 131   
 
 132  1
         Format format = firstview.getFormat();
 133  1
         assertTrue("view didn't display correct value before change", format.format(new Object[] { firstvalue }).equals(firstview.getFormattedText()));
 134   
 
 135  1
         Integer newvalue = new Integer(4711);
 136  1
         model.setRow(0, new Object[] { newvalue });
 137   
 
 138  1
         TextLabel newview = (TextLabel) table.getCellView(0, 0);
 139  1
         format = newview.getFormat();
 140  1
         assertTrue("views were not recreated", firstview != newview);
 141  1
         assertTrue("view didn't display correct value after change", format.format(new Object[] { newvalue }).equals(newview.getFormattedText()));
 142   
     }
 143   
 }
 144