org.fest.swing.core.matcher
Class NamedComponentMatcherTemplate<T extends Component>

java.lang.Object
  extended by org.fest.swing.core.AbstractComponentMatcher
      extended by org.fest.swing.core.GenericTypeMatcher<T>
          extended by org.fest.swing.core.matcher.NamedComponentMatcherTemplate<T>
Type Parameters:
T - the type of Component supported by this matcher.
All Implemented Interfaces:
ComponentMatcher, ResettableComponentMatcher
Direct Known Subclasses:
DialogMatcher, FrameMatcher, JButtonMatcher, JLabelMatcher, JTextComponentMatcher

public abstract class NamedComponentMatcherTemplate<T extends Component>
extends GenericTypeMatcher<T>

Understands a template for matching components by name. Subclasses are free to add other properties to use as search criteria.

Author:
Alex Ruiz

Field Summary
protected static Object ANY
          Indicates that a property value to use as search criteria has not been set.
protected  Object name
          The component name to match.
 
Constructor Summary
protected NamedComponentMatcherTemplate(Class<T> supportedType)
          Creates a new NamedComponentMatcherTemplate.
protected NamedComponentMatcherTemplate(Class<T> supportedType, Object name)
          Creates a new NamedComponentMatcherTemplate.
 
Method Summary
protected  boolean arePropertyValuesMatching(Object expected, Object actual)
          Indicates whether the given value matches the expected value in this matcher.
protected  boolean isNameMatching(String actual)
          Indicates whether the given value matches the name in this matcher.
protected  Object quoted(Object propertyValue)
          Returns the given property value to match surrounded by double quotes.
protected  Object quotedName()
          Returns the component name to match surrounded by double quotes.
 
Methods inherited from class org.fest.swing.core.GenericTypeMatcher
isMatching, matches, supportedType
 
Methods inherited from class org.fest.swing.core.AbstractComponentMatcher
requireShowing, requireShowing, requireShowingMatches, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANY

protected static final Object ANY
Indicates that a property value to use as search criteria has not been set.


name

protected final Object name
The component name to match.

Constructor Detail

NamedComponentMatcherTemplate

protected NamedComponentMatcherTemplate(Class<T> supportedType)
Creates a new NamedComponentMatcherTemplate.

Parameters:
supportedType - the type supported by this matcher.
Throws:
NullPointerException - if the given type is null.

NamedComponentMatcherTemplate

protected NamedComponentMatcherTemplate(Class<T> supportedType,
                                        Object name)
Creates a new NamedComponentMatcherTemplate.

Parameters:
supportedType - the type supported by this matcher.
name - the component name to match.
Throws:
NullPointerException - if the given type is null.
Method Detail

quotedName

protected final Object quotedName()
Returns the component name to match surrounded by double quotes. If the component name has not been set, it will return ANY. This method is commonly used in implementations of toString.

Returns:
the component name to match surrounded by double quotes, or ANY if the component name has not been set.

quoted

protected final Object quoted(Object propertyValue)
Returns the given property value to match surrounded by double quotes. If the property has not been set, it will return ANY. This method is commonly used in implementations of toString.

Parameters:
propertyValue - the given property value.
Returns:
the given property value to match surrounded by double quotes, or ANY if the property value has not been set.

isNameMatching

protected final boolean isNameMatching(String actual)
Indicates whether the given value matches the name in this matcher. It always returns true if this matcher's name is ANY.

Parameters:
actual - the actual component name.
Returns:
true if this matcher's name is ANY or if both the actual name is equal to the one in this matcher. Otherwise false.

arePropertyValuesMatching

protected final boolean arePropertyValuesMatching(Object expected,
                                                  Object actual)
Indicates whether the given value matches the expected value in this matcher. Matching is performed as follows:
  1. it always returns true if the expected value is ANY
  2. if both the expected and actual values are Strings, it checks for equality first. If this fails, it tries to match the values assuming the expected value can be a regular expression
  3. if the expected value is a Pattern and the actual value is a CharSequence, regular expression matching is performed
  4. otherwise, it checks that both the expected and actual values are equal

Parameters:
expected - the expected value in this matcher.
actual - the actual property value.
Returns:
true if the values match, otherwise false.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.