Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 94   Methods: 6
NCLOC: 40   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LabeledComponentFinder.java 75% 82.4% 83.3% 81.5%
coverage coverage
 1   
 package junit.extensions.jfcunit.finder;
 2   
 
 3   
 import java.awt.Component;
 4   
 
 5   
 import javax.swing.JLabel;
 6   
 import java.awt.Container;
 7   
 
 8   
 
 9   
 /**
 10   
  * Find a component based upon the label attached via JLabel.setLabelFor(Component comp).
 11   
  *
 12   
  * @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
 13   
  */
 14   
 public class LabeledComponentFinder extends Finder {
 15   
     /**
 16   
      * The label Regular expression to be found.
 17   
      */
 18   
     private String m_text = null;
 19   
 
 20   
     /**
 21   
      * Ignore the case of the search.
 22   
      */
 23   
     private boolean m_caseIndependent = true;
 24   
 
 25   
     /**
 26   
      * Constructor accepting all arguments needed to filter the {@link java.awt.Component}.
 27   
      *
 28   
      * @param text Regular expression describing the label to be found.
 29   
      * @param caseIndependent true if the case should be ignored.
 30   
      */
 31  5
     public LabeledComponentFinder(final String text,
 32   
         final boolean caseIndependent) {
 33  5
       setText(text);
 34  5
       m_caseIndependent = caseIndependent;
 35  5
       super.createPatternMatcher(text, caseIndependent);
 36   
     }
 37   
 
 38   
     /**
 39   
      * Set the finder into a case independent mode.
 40   
      * @param ignoreCase true if case should be ignored.
 41   
      */
 42  0
     public void setCaseIndependent(final boolean ignoreCase) {
 43  0
         super.setCaseIndependent(ignoreCase);
 44  0
         m_caseIndependent = ignoreCase;
 45  0
         createPatternMatcher(m_text, m_caseIndependent);
 46   
     }
 47   
 
 48   
     /**
 49   
      * Set the text to be matched against the label.
 50   
      * @param text String to be matched.
 51   
      */
 52  5
     public final void setText(final String text) {
 53  5
         m_text = text;
 54  5
         createPatternMatcher(m_text, m_caseIndependent);
 55   
     }
 56   
 
 57   
     /**
 58   
      * Get the text to be matched against the label.
 59   
      * @return String text to be matched.
 60   
      */
 61  6
     public final String getText() {
 62  6
         return m_text;
 63   
     }
 64   
 
 65   
     /**
 66   
      * Method that returns true if the given {@link java.awt.Component} matches the search
 67   
      * criteria.
 68   
      *
 69   
      * @param comp   The component to test
 70   
      * @return true if this component is a match
 71   
      */
 72  27
     public boolean testComponent(final Component comp) {
 73  27
         if (comp != null && comp instanceof JLabel) {
 74  6
             JLabel lbl = (JLabel) comp;
 75  6
             return super.evaluate(getText(), lbl.getText());
 76   
         }
 77  21
         return false;
 78   
     }
 79   
 
 80   
     /**
 81   
      * Find the component in the container at the given index.
 82   
      * @param conts Containers to be searched.
 83   
      * @param index Index of the component to find.
 84   
      * @return Component which was found or null.
 85   
      */
 86  5
     public Component find(final Container[] conts, final int index) {
 87  5
       Component c = super.find(conts, index);
 88  5
       if (c != null) {
 89  5
         c = ((JLabel) c).getLabelFor();
 90   
       }
 91  5
       return c;
 92   
     }
 93   
 }
 94