|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| NamedComponentFinder.java | - | 64.3% | 62.5% | 63.6% |
|
||||||||||||||
| 1 |
package junit.extensions.jfcunit.finder;
|
|
| 2 |
|
|
| 3 |
import java.awt.Component;
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
/**
|
|
| 7 |
* This is a 'breakaway' from the ComponentFinder in which the component to be
|
|
| 8 |
* tested is assumed to have a name and so the name passed in is compared to the comp.name
|
|
| 9 |
* The pattern syntax can be found at the Jakarta RegExp API Documentation in {@link org.apache.regexp.RE}.
|
|
| 10 |
*
|
|
| 11 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
| 12 |
*/
|
|
| 13 |
public class NamedComponentFinder extends Finder { |
|
| 14 |
/**
|
|
| 15 |
* The type of the component.
|
|
| 16 |
*/
|
|
| 17 |
private Class m_compCls = null; |
|
| 18 |
|
|
| 19 |
/**
|
|
| 20 |
* The pattern for the name of the component.
|
|
| 21 |
*/
|
|
| 22 |
private String m_name = null; |
|
| 23 |
|
|
| 24 |
/**
|
|
| 25 |
* A boolean specifying whether the filtration
|
|
| 26 |
* is case insensitive.
|
|
| 27 |
*/
|
|
| 28 |
private boolean m_caseIndependent = false; |
|
| 29 |
|
|
| 30 |
/**
|
|
| 31 |
* Constructor accepting all arguments needed to
|
|
| 32 |
* filter component.
|
|
| 33 |
*
|
|
| 34 |
* @param cls The desired type of the component.
|
|
| 35 |
* @param name The desired pattern for the name of the component.
|
|
| 36 |
*/
|
|
| 37 | 22 |
public NamedComponentFinder(final Class cls, final String name) {
|
| 38 | 22 |
this(cls, name, false); |
| 39 |
} |
|
| 40 |
|
|
| 41 |
/**
|
|
| 42 |
* Constructor accepting all arguments needed to filter
|
|
| 43 |
* component.
|
|
| 44 |
*
|
|
| 45 |
* @param cls The desired type of the component.
|
|
| 46 |
* @param name The desired pattern for the name of the component.
|
|
| 47 |
* @param caseIndependent Whether the match should be case independent (true) or not (false)
|
|
| 48 |
*/
|
|
| 49 | 24 |
public NamedComponentFinder(final Class cls, final String name,
|
| 50 |
final boolean caseIndependent) {
|
|
| 51 | 24 |
setComponentClass(cls); |
| 52 | 24 |
setName(name); |
| 53 | 24 |
this.m_caseIndependent = caseIndependent;
|
| 54 | 24 |
recreatePatternMatcher(m_name, caseIndependent); |
| 55 |
} |
|
| 56 |
|
|
| 57 |
/**
|
|
| 58 |
* Set the component class.
|
|
| 59 |
* @param cls Class to be found by the finder.
|
|
| 60 |
*/
|
|
| 61 | 24 |
public final void setComponentClass(final Class cls) { |
| 62 | 24 |
m_compCls = cls; |
| 63 |
} |
|
| 64 |
|
|
| 65 |
/**
|
|
| 66 |
* Get the component class to be found by the finder.
|
|
| 67 |
* @return Class to be found.
|
|
| 68 |
*/
|
|
| 69 | 0 |
public final Class getComponentClass() {
|
| 70 | 0 |
return m_compCls;
|
| 71 |
} |
|
| 72 |
|
|
| 73 |
/**
|
|
| 74 |
* Set the name of the component to be found.
|
|
| 75 |
* @param name String name of the component.
|
|
| 76 |
*/
|
|
| 77 | 24 |
public final void setName(final String name) { |
| 78 | 24 |
m_name = name; |
| 79 | 24 |
recreatePatternMatcher(m_name, m_caseIndependent); |
| 80 |
} |
|
| 81 |
|
|
| 82 |
/**
|
|
| 83 |
* Set the finder into a case independent mode.
|
|
| 84 |
* @param ignoreCase true if case should be ignored.
|
|
| 85 |
*/
|
|
| 86 | 0 |
public void setCaseIndependent(final boolean ignoreCase) { |
| 87 | 0 |
super.setCaseIndependent(ignoreCase);
|
| 88 | 0 |
m_caseIndependent = ignoreCase; |
| 89 | 0 |
recreatePatternMatcher(m_name, m_caseIndependent); |
| 90 |
} |
|
| 91 |
|
|
| 92 |
|
|
| 93 |
/**
|
|
| 94 |
* Get the name of the component to be found.
|
|
| 95 |
* @return String name of the component.
|
|
| 96 |
*/
|
|
| 97 | 0 |
public final String getName() {
|
| 98 | 0 |
return m_name;
|
| 99 |
} |
|
| 100 |
|
|
| 101 |
/**
|
|
| 102 |
* Method that returns true if the given component matches the search
|
|
| 103 |
* criteria.
|
|
| 104 |
*
|
|
| 105 |
* @param comp The component to test.
|
|
| 106 |
* @return true if this component is a match.
|
|
| 107 |
*/
|
|
| 108 | 154 |
public boolean testComponent(final Component comp) { |
| 109 | 154 |
return ((comp != null) |
| 110 |
&& ((m_compCls == null) || isValidForProcessing(comp, m_compCls))
|
|
| 111 |
&& evaluate( |
|
| 112 |
comp.getName(), |
|
| 113 |
m_name)); |
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
|
|
||||||||||