org.testinfected.hamcrest.dom
Class DomMatchers

java.lang.Object
  extended by org.testinfected.hamcrest.dom.DomMatchers

public class DomMatchers
extends java.lang.Object

A collection of hamcrest matchers to validate DOM elements (objects of type Element).


Method Summary
static org.hamcrest.Matcher<org.w3c.dom.Element> anElement(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementMatchers)
          Combines a group of matchers for matching an Element.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasAttribute(java.lang.String name, org.hamcrest.Matcher<? super java.lang.String> valueMatcher)
          Checks that an Element has an attribute whose value matches the specified matcher.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasAttribute(java.lang.String name, java.lang.String value)
          Checks that an Element has an attribute with the specified value.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasBlankText()
          Checks that an Element content contains only blank characters.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasChild(org.hamcrest.Matcher<? super org.w3c.dom.Element> childMatcher)
          Checks that at least one child of an Element is matched against the given matcher.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasChildren(org.hamcrest.Matcher<? super org.w3c.dom.Element>... childrenMatchers)
          Checks that children of an Element match in order the specified matchers.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasChildren(org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> childrenMatcher)
          Checks that children of an Element match in order the specified matchers.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasClassName(java.lang.String className)
          Checks that an Element has the specified CSS class.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasId(java.lang.String id)
          Checks that an Element has an id attribute with the specified value.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasName(java.lang.String name)
          Checks that an Element has the specified attribute, whatever its value.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasNoSelector(java.lang.String selector)
          Checks that an Element is not matched by the specified CSS3 selector expression.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasSelector(java.lang.String selector, org.hamcrest.Matcher<? super org.w3c.dom.Element>... subjectsMatchers)
          Checks that an Element matches a CSS3 selector with the specified matchers matching the subjects of the selector in any order.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasSelector(java.lang.String selector, org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> subjectsMatcher)
          Checks that an Element matches a CSS3 selector with the specified matchers matching the subjects of the selector.
static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> hasSize(int size)
          Checks that a collection of Elementa is of a specified size.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasTag(java.lang.String tagName)
          Checks that an Element has the specified tag.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasText(org.hamcrest.Matcher<? super java.lang.String> contentMatcher)
          Checks that an Element content text matches the specified matcher.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasText(java.lang.String contentText)
          Checks that an Element content is equal to the specified text.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasUniqueSelector(java.lang.String selector)
          Checks that an Element matches a CSS3 selector and that the selector represents a single child element.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasUniqueSelector(java.lang.String selector, org.hamcrest.Matcher<? super org.w3c.dom.Element>... subjectMatchers)
          Checks that an Element matches a CSS3 selector and that the single element represented by the selector is matched by all specified matchers.
static org.hamcrest.Matcher<org.w3c.dom.Element> hasUniqueSelector(java.lang.String selector, org.hamcrest.Matcher<? super org.w3c.dom.Element> subjectMatcher)
          Checks that an Element matches a CSS3 selector with the specified matcher matching the only subject of the selector.
static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> includes(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementsMatchers)
          Checks that a collection of Elements contains, in any order, at least one matched element for each specified matcher.
static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matches(java.util.List<org.hamcrest.Matcher<? super org.w3c.dom.Element>> elementsMatcher)
           Checks that a collection contains Elements that are matched in order by the specified list of matchers.
static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matches(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementsMatchers)
          Checks that a collection contains Elements that are matched in order by the specified matchers.
static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matchesInAnyOrder(java.util.List<org.hamcrest.Matcher<? super org.w3c.dom.Element>> elementsMatcher)
          Checks that a collection contains Elements that are matched in any order by the specified list of matchers.
static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matchesInAnyOrder(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementsMatchers)
          Checks that a collection contains Elements that are matched in any order by the specified matchers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasSelector

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasSelector(java.lang.String selector,
                                                                    org.hamcrest.Matcher<? super org.w3c.dom.Element>... subjectsMatchers)
Checks that an Element matches a CSS3 selector with the specified matchers matching the subjects of the selector in any order. This is equivalent to hasSelector(selector, matchesInAnyOrder(subjectsMatchers)).

Parameters:
selector - the CSS3 selector expression to match against the element
subjectsMatchers - matchers to match the elements represented by the selector

hasSelector

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasSelector(java.lang.String selector,
                                                                    org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> subjectsMatcher)
Checks that an Element matches a CSS3 selector with the specified matchers matching the subjects of the selector.

Parameters:
selector - the CSS3 selector expression to match against the element
subjectsMatcher - matchers to match the elements represented by the selector

hasSize

public static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> hasSize(int size)
Checks that a collection of Elementa is of a specified size.

Parameters:
size - the expected number of elements

hasUniqueSelector

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasUniqueSelector(java.lang.String selector)
Checks that an Element matches a CSS3 selector and that the selector represents a single child element.

Parameters:
selector - the CSS3 selector expression to match against the element

hasUniqueSelector

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasUniqueSelector(java.lang.String selector,
                                                                          org.hamcrest.Matcher<? super org.w3c.dom.Element> subjectMatcher)
Checks that an Element matches a CSS3 selector with the specified matcher matching the only subject of the selector.

Parameters:
selector - the CSS3 selector expression to match against the element
subjectMatcher - the matcher to match the single element represented by the selector

hasUniqueSelector

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasUniqueSelector(java.lang.String selector,
                                                                          org.hamcrest.Matcher<? super org.w3c.dom.Element>... subjectMatchers)
Checks that an Element matches a CSS3 selector and that the single element represented by the selector is matched by all specified matchers. This is a equivalent to hasUniqueSelector(selector, anElement(subjectMatchers)).

Parameters:
selector - the CSS3 selector expression to match against the element
subjectMatchers - the matchers to match the single element represented by the selector

hasNoSelector

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasNoSelector(java.lang.String selector)
Checks that an Element is not matched by the specified CSS3 selector expression.

Parameters:
selector - the CSS3 selector expression

matches

public static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matches(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementsMatchers)
Checks that a collection contains Elements that are matched in order by the specified matchers.

Each element in the collection must be matched and each specified matcher must match an element. Matching occurs in order, so the first element in the collection is matched against the first specified matcher, the second element is matched by second matcher argument, and so on.

Parameters:
elementsMatchers - the matchers to match the collection of Elements
See Also:
matches(java.util.List)

matches

public static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matches(java.util.List<org.hamcrest.Matcher<? super org.w3c.dom.Element>> elementsMatcher)

Checks that a collection contains Elements that are matched in order by the specified list of matchers.

Each element in the collection must be matched and each specified matcher must match an element. Matching occurs in order, so the first element in the collection is matched against the first matcher in the list, the second element is matched by second matcher, and so on.

Note: As of hamcrest 1.3, the hasItems family of matchers return Matcher<Iterable<? extends T>> whereas the contains family of matchers return Iterable<Matcher<T>>. Unfortunately, this makes them impossible to combine as arguments to hasSelector(String, org.hamcrest.Matcher) without this method.

Parameters:
elementsMatcher - the list fo matchers to match the collection of Elements

matchesInAnyOrder

public static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matchesInAnyOrder(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementsMatchers)
Checks that a collection contains Elements that are matched in any order by the specified matchers.

Each element in the collection must be matched and each specified matcher must match an element. Matching can occur in any order.

Parameters:
elementsMatchers - the matchers to match the collection of Elements
See Also:
matchesInAnyOrder(java.util.List)

matchesInAnyOrder

public static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> matchesInAnyOrder(java.util.List<org.hamcrest.Matcher<? super org.w3c.dom.Element>> elementsMatcher)
Checks that a collection contains Elements that are matched in any order by the specified list of matchers.

Each element in the collection must be matched and each specified matcher must match an element. Matching can occur in any order.

Note: As of hamcrest 1.3, the hasItems family of matchers return Matcher<Iterable<? extends T>> whereas the contains family of matchers return Iterable<Matcher<T>>. Unfortunately, this makes them impossible to combine as arguments to hasSelector(String, org.hamcrest.Matcher) without this method.

Parameters:
elementsMatcher - the list fo matchers to match the collection of Elements

includes

public static org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> includes(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementsMatchers)
Checks that a collection of Elements contains, in any order, at least one matched element for each specified matcher.

Parameters:
elementsMatchers - matchers to match Elements in the collection

hasTag

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasTag(java.lang.String tagName)
Checks that an Element has the specified tag.


hasText

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasText(java.lang.String contentText)
Checks that an Element content is equal to the specified text.


hasText

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasText(org.hamcrest.Matcher<? super java.lang.String> contentMatcher)
Checks that an Element content text matches the specified matcher.


hasBlankText

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasBlankText()
Checks that an Element content contains only blank characters.


hasAttribute

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasAttribute(java.lang.String name,
                                                                     java.lang.String value)
Checks that an Element has an attribute with the specified value.

Parameters:
name - the name of the attribute.
value - the expected value of the attribute

hasAttribute

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasAttribute(java.lang.String name,
                                                                     org.hamcrest.Matcher<? super java.lang.String> valueMatcher)
Checks that an Element has an attribute whose value matches the specified matcher.

Parameters:
name - the name of the attribute to match
valueMatcher - matcher for matching the attribute's value.

hasName

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasName(java.lang.String name)
Checks that an Element has the specified attribute, whatever its value.

Parameters:
name - the name of the attribute

hasId

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasId(java.lang.String id)
Checks that an Element has an id attribute with the specified value.

Parameters:
id - the expected value of the id attribute

hasClassName

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasClassName(java.lang.String className)
Checks that an Element has the specified CSS class. Note that the element can have other classes as well.

Parameters:
className - the expected class the element

hasChildren

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasChildren(org.hamcrest.Matcher<? super org.w3c.dom.Element>... childrenMatchers)
Checks that children of an Element match in order the specified matchers. The number of matchers must be the same as the number of children.

Matching occurs in order, so the first child is matched against the first matcher, the second child against second matcher, and so on.


hasChildren

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasChildren(org.hamcrest.Matcher<java.lang.Iterable<org.w3c.dom.Element>> childrenMatcher)
Checks that children of an Element match in order the specified matchers. The number of matchers must be the same as the number of children.

Matching occurs in order, so the first child is matched against the first matcher, the second child against second matcher, and so on.


hasChild

public static org.hamcrest.Matcher<org.w3c.dom.Element> hasChild(org.hamcrest.Matcher<? super org.w3c.dom.Element> childMatcher)
Checks that at least one child of an Element is matched against the given matcher.


anElement

public static org.hamcrest.Matcher<org.w3c.dom.Element> anElement(org.hamcrest.Matcher<? super org.w3c.dom.Element>... elementMatchers)
Combines a group of matchers for matching an Element.



Copyright © 2012. All Rights Reserved.