Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 121   Methods: 9
NCLOC: 98   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
AbstractButtonTesterTest.java 66.7% 83.9% 88.9% 78.9%
coverage coverage
 1   
 package abbot.tester;
 2   
 
 3   
 import java.awt.*;
 4   
 import java.awt.event.*;
 5   
 
 6   
 import javax.swing.*;
 7   
 
 8   
 import junit.extensions.abbot.*;
 9   
 import junit.extensions.abbot.Timer;
 10   
 import junit.framework.*;
 11   
 
 12   
 /** Unit test to verify the AbstractButtonTester class.<p>
 13   
     
 14   
     <ul>
 15   
     <li>Test all exported actions.
 16   
     </ul>
 17   
  */
 18   
 
 19   
 public class AbstractButtonTesterTest extends ComponentTestFixture {
 20   
 
 21   
     private AbstractButtonTester tester;
 22   
 
 23   
     /** Create a new test case with the given name. */
 24  1
     public AbstractButtonTesterTest(String name) {
 25  1
         super(name);
 26   
     }
 27   
 
 28  1
     protected void setUp() {
 29  1
         tester = (AbstractButtonTester)
 30   
             ComponentTester.getTester(AbstractButton.class);
 31   
     }
 32   
 
 33  23
     private JButton findButton(Component comp, String text) {
 34  23
         if (comp instanceof JButton) {
 35  2
             if (((JButton)comp).getText().equals(text)) 
 36  1
                 return (JButton)comp;
 37   
         }
 38  21
         else if (comp instanceof Container) {
 39  21
             Component[] children = ((Container)comp).getComponents();
 40  21
             for (int i=0;i < children.length;i++) {
 41  21
                 JButton b = findButton(children[i], text);
 42  21
                 if (b != null)
 43  6
                     return b;
 44   
             }
 45   
         }
 46  16
         return null;
 47   
     }
 48   
 
 49  1
     private JButton findButton(String text) {
 50  1
         Frame[] frames = Frame.getFrames();
 51  2
         for (int i=0;i < frames.length;i++) {
 52  2
             if (frames[i].isShowing()) {
 53  1
                 JButton button = findButton(frames[i], text);
 54  1
                 if (button != null)
 55  0
                     return button;
 56   
             }
 57  2
             Window[] subs = frames[i].getOwnedWindows();
 58  2
             for (int j=0;j < subs.length;j++) {
 59  2
                 if (subs[j].isShowing()) {
 60  1
                     JButton button = findButton(subs[j], text);
 61  1
                     if (button != null)
 62  1
                         return button;
 63   
                 }
 64   
             }
 65   
         }
 66  0
         return null;
 67   
     }
 68   
 
 69   
     private class ButtonWatcher implements ActionListener {
 70   
         public boolean gotAction = false;
 71  2
         public void actionPerformed(ActionEvent ev) {
 72  2
             gotAction = true;
 73   
         }
 74   
     }
 75  1
     public void testClick() {
 76  1
         final JButton button = new JButton("Hit me");
 77  1
         String[] values = { "one", "two", "three" };
 78  1
         final JList list = new JList(values);
 79  1
         ButtonWatcher bw = new ButtonWatcher() {
 80  1
             public void actionPerformed(ActionEvent ev) {
 81  1
                 super.actionPerformed(ev);
 82  1
                 JOptionPane.showInputDialog(button, list);
 83   
             }
 84   
         };
 85  1
         button.addActionListener(bw);
 86  1
         showFrame(button);
 87  1
         tester.actionClick(button);
 88  1
         assertTrue("Button not pressed", bw.gotAction);
 89  1
         Timer timer = new Timer();
 90  1
         while (!isShowing("Input")) {
 91  0
             if (timer.elapsed() > EVENT_GENERATION_DELAY)
 92  0
                 fail("Timed out waiting for input dialog");
 93  0
             tester.sleep();
 94   
         }
 95  1
         tester.actionClick(list);
 96  1
         tester.reset();
 97  1
         JButton ok = findButton("OK");
 98  1
         assertNotNull("Couldn't find OK button", ok);
 99  1
         ButtonWatcher bw2 = new ButtonWatcher();
 100  1
         ok.addActionListener(bw2);
 101  1
         tester.actionClick(ok);
 102  1
         timer.reset();
 103  1
         while (isShowing("Input")) {
 104  0
             if (timer.elapsed() > EVENT_GENERATION_DELAY)
 105  0
                 fail("Timed out waiting for dialog to close");
 106  0
             tester.sleep();
 107   
         }
 108  1
         assertTrue("OK button not pressed", bw2.gotAction);
 109   
     }
 110   
 
 111   
     /** Return the default test suite. */
 112  1
     public static Test suite() {
 113  1
         return new TestSuite(AbstractButtonTesterTest.class);
 114   
     }
 115   
 
 116  0
     public static void main(String[] args) {
 117  0
         RepeatHelper.runTests(args, AbstractButtonTesterTest.class);
 118   
     }
 119   
 }
 120   
 
 121