Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 102   Methods: 6
NCLOC: 47   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JFileChooserFinder.java 60% 60% 66.7% 61.1%
coverage coverage
 1   
 package junit.extensions.jfcunit.finder;
 2   
 
 3   
 import java.awt.Component;
 4   
 import javax.swing.JFileChooser;
 5   
 import java.util.List;
 6   
 import java.awt.Container;
 7   
 import java.awt.Window;
 8   
 import java.util.ArrayList;
 9   
 
 10   
 /**
 11   
  * This class locates the JFileChooser with the given title.
 12   
  *
 13   
  * The container may be the window which owns the JFileChooser.
 14   
  * Owned windows will be explored.
 15   
  *
 16   
  * @author Kevin L Wilson
 17   
  */
 18   
 public class JFileChooserFinder extends ComponentFinder {
 19   
 
 20   
     /** Title to be compared. */
 21   
     private String m_title;
 22   
 
 23   
     /**
 24   
      * Constructor accepting all arguments needed to filter component.
 25   
      *
 26   
      * @param title    The desired pattern for the title of the component.
 27   
      */
 28  1
     public JFileChooserFinder(final String title) {
 29  1
         super(JFileChooser.class);
 30  1
         setTitle(title);
 31   
     }
 32   
 
 33   
     /**
 34   
      * Set the title to be matched.
 35   
      * @param title to be matched.
 36   
      */
 37  1
     public final void setTitle(final String title) {
 38  1
         m_title = title;
 39   
     }
 40   
 
 41   
     /**
 42   
      * Get the title to be matched.
 43   
      * @return title to be found.
 44   
      */
 45  0
     public final String getTitle() {
 46  0
         return m_title;
 47   
     }
 48   
 
 49   
     /**
 50   
      * Method that returns true if the given {@link java.awt.Component} matches the search
 51   
      * criteria.
 52   
      *
 53   
      * @param comp   The component to test
 54   
      * @return true if this component is a match
 55   
      */
 56  190
     public boolean testComponent(final Component comp) {
 57  190
         if (!super.testComponent(comp)) {
 58  181
             return false;
 59   
         }
 60  9
         if (m_title == null) {
 61  9
             return true;
 62   
         }
 63  0
         JFileChooser chooser = (JFileChooser) comp;
 64  0
         String title = chooser.getDialogTitle();
 65  0
         return this.evaluate(m_title, title);
 66   
     }
 67   
 
 68   
     /**
 69   
      * Find all of the components under the specified containers.
 70   
      * owned windows will also be explored.
 71   
      * @param conts Container[] to be searched.
 72   
      * @param index int index of chooser to return.
 73   
      * @return Component JFileChooser located.
 74   
      */
 75  0
     public Component find(final Container[] conts, final int index) {
 76  0
         List lst = findAll(conts, new ArrayList());
 77  0
         if (lst.size() < index) {
 78  0
             return null;
 79   
         }
 80  0
         return (Component) lst.get(index);
 81   
     }
 82   
 
 83   
     /**
 84   
      * This findAll will also explore the owned windows
 85   
      * if a container is a window.
 86   
      *
 87   
      * @param cont Containers to be explored.
 88   
      * @param results items which have been found.
 89   
      * @return List result items.
 90   
      */
 91  14
     protected List findAll(final Container[] cont, final List results) {
 92  14
         for (int i = 0; i < cont.length; i++) {
 93  12
             findComponentList(this, cont[i], results, Integer.MAX_VALUE);
 94  12
             if (cont[i] instanceof Window) {
 95  12
                 findAll(((Window) cont[i]).getOwnedWindows(), results);
 96   
             }
 97   
         }
 98  14
         return results;
 99   
     }
 100   
 
 101   
 }
 102