Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 118   Methods: 8
NCLOC: 95   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
JListTesterTest.java 25% 83.3% 87.5% 77.1%
coverage coverage
 1   
 package abbot.tester;
 2   
 
 3   
 import java.awt.event.*;
 4   
 
 5   
 import javax.swing.*;
 6   
 
 7   
 import junit.extensions.abbot.*;
 8   
 import junit.extensions.abbot.Timer;
 9   
 import junit.framework.*;
 10   
 import abbot.util.ExtendedComparator;
 11   
 
 12   
 /** Unit test to verify the JListTester class.<p> */
 13   
 
 14   
 public class JListTesterTest extends ComponentTestFixture {
 15   
 
 16   
     private JListTester tester;
 17   
     private JList list;
 18   
     private JScrollPane scrollPane;
 19   
 
 20   
     private String[] data = { "zero", "one", "two", "three", "four", 
 21   
                               "five", "six", "seven", "eight"};
 22   
 
 23  4
     protected void setUp() {
 24  4
         tester = new JListTester();
 25  4
         list = new JList(data);
 26   
     }
 27   
 
 28  1
     public void testContents() {
 29  1
         showFrame(list);
 30  1
         assertTrue("Wrong contents returned", 
 31   
                    ExtendedComparator.equals(data, tester.getContents(list)));
 32   
     }
 33   
 
 34   
     private class MouseWatcher extends MouseAdapter {
 35   
         public volatile int clickCount = 0;
 36  2
         public void mouseClicked(MouseEvent ev) {
 37  2
             clickCount = ev.getClickCount();
 38   
         }
 39   
     }
 40   
 
 41  1
     public void testSelectFirstValue() {
 42  1
         list.setSelectedIndex(1);
 43  1
         MouseWatcher mw = new MouseWatcher();
 44  1
         list.addMouseListener(mw);
 45  1
         showFrame(list);
 46  1
         tester.actionSelectRow(list, new JListLocation(data[0]));
 47  1
         assertEquals("Wrong item selected", 0, list.getSelectedIndex());
 48  1
         Timer timer = new Timer();
 49  1
         while (mw.clickCount == 0) {
 50  0
             if (timer.elapsed() > EVENT_GENERATION_DELAY)
 51  0
                 throw new RuntimeException("Timed out waiting for clicks");
 52  0
             tester.sleep();
 53   
         }
 54  1
         assertEquals("Too many clicks", 1, mw.clickCount);
 55   
     }
 56   
 
 57  1
     public void testSelectFirstIndex() {
 58  1
         list.setSelectedIndex(1);
 59  1
         MouseWatcher mw = new MouseWatcher();
 60  1
         list.addMouseListener(mw);
 61  1
         showFrame(list);
 62  1
         tester.actionSelectIndex(list, 0);
 63  1
         assertEquals("Wrong item selected", 0, list.getSelectedIndex());
 64  1
         Timer timer = new Timer();
 65  1
         while (mw.clickCount == 0) {
 66  0
             if (timer.elapsed() > EVENT_GENERATION_DELAY)
 67  0
                 throw new RuntimeException("Timed out waiting for clicks");
 68  0
             tester.sleep();
 69   
         }
 70  1
         assertEquals("Too many clicks", 1, mw.clickCount);
 71   
     }
 72   
 
 73   
     /**
 74   
      * Uses a JList in a JScrollPane to test the scrollToVisible feature of
 75   
      * JComponentTester.
 76   
      */
 77  1
     public void testScrollToVisibleIndex()
 78   
     {
 79  1
         list.setVisibleRowCount(4);
 80  1
         scrollPane = new JScrollPane(list);
 81  1
         showFrame(scrollPane);
 82  1
         tester.actionSelectIndex(list, 0);
 83  1
         assertEquals("Wrong Cell Selected", list.getSelectedIndex(), 0);
 84  1
         tester.actionSelectIndex(list, 7);
 85  1
         assertEquals("Wrong Cell Selected", list.getSelectedIndex(), 7);
 86  1
         tester.actionSelectIndex(list, 6);
 87  1
         assertEquals("Wrong Cell Selected", list.getSelectedIndex(), 6);
 88  1
         tester.actionSelectIndex(list, 2);
 89  1
         assertEquals("Wrong Cell Selected", list.getSelectedIndex(), 2);
 90  1
         tester.actionSelectIndex(list, 8);
 91  1
         assertEquals("Wrong Cell Selected", list.getSelectedIndex(), 8);
 92  1
         tester.actionSelectIndex(list, 5);
 93  1
         assertEquals("Wrong Cell Selected", list.getSelectedIndex(), 5);
 94  1
         tester.actionSelectIndex(list, 1);
 95  1
         assertEquals("Wrong Cell Selected", list.getSelectedIndex(), 1);
 96  1
         try {
 97  1
             tester.actionSelectIndex(list, -1);
 98  0
             fail("Action with out-of-bounds index should fail");
 99   
         }
 100   
         catch(ActionFailedException a) { }
 101  1
         try {
 102  1
             tester.actionSelectIndex(list, data.length);
 103  0
             fail("Action with out-of-bounds index should fail");
 104   
         }
 105   
         catch(ActionFailedException a) { }
 106   
     }
 107   
         
 108   
     /** Create a new test case with the given name. */
 109  4
     public JListTesterTest(String name) {
 110  4
         super(name);
 111   
     }
 112   
 
 113  0
     public static void main(String[] args) {
 114  0
         RepeatHelper.runTests(args, JListTesterTest.class);
 115   
     }
 116   
 }
 117   
 
 118