org.hamcrest.comparator
Class ComparatorMatcherBuilder<T>

java.lang.Object
  extended by org.hamcrest.comparator.ComparatorMatcherBuilder<T>

public final class ComparatorMatcherBuilder<T>
extends Object


Method Summary
static
<T> ComparatorMatcherBuilder<T>
comparedBy(Comparator<T> comparator)
          Creates a matcher factory for matchers of Comparatorss of T.
 Matcher<T> comparesEqualTo(T value)
          Creates a matcher of T object that matches when the examined object is equal to the specified value, as reported by the Comparator used to create this builder.
 Matcher<T> greaterThan(T value)
          Creates a matcher of T object that matches when the examined object is greater than the specified value, as reported by the Comparator used to create this builder.
 Matcher<T> greaterThanOrEqualTo(T value)
          Creates a matcher of T object that matches when the examined object is greater than or equal to the specified value, as reported by the Comparator used to create this builder.
 Matcher<T> lessThan(T value)
          Creates a matcher of T object that matches when the examined object is less than the specified value, as reported by the Comparator used to create this builder.
 Matcher<T> lessThanOrEqualTo(T value)
          Creates a matcher of T object that matches when the examined object is less than or equal to the specified value, as reported by the Comparator used to create this builder.
static
<T extends Comparable<T>>
ComparatorMatcherBuilder<T>
usingNaturalOrdering()
          Creates a matcher factory for matchers of Comparables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

usingNaturalOrdering

public static <T extends Comparable<T>> ComparatorMatcherBuilder<T> usingNaturalOrdering()
Creates a matcher factory for matchers of Comparables.

For example:

assertThat(1, ComparatorMatcherBuilder.usingNaturalOrdering().lessThanOrEqualTo(1))


comparedBy

public static <T> ComparatorMatcherBuilder<T> comparedBy(Comparator<T> comparator)
Creates a matcher factory for matchers of Comparatorss of T.

For example:

assertThat(5, comparedBy(new Comparator() {
 public int compare(Integer o1, Integer o2) {
 return -o1.compareTo(o2);
 }
 }).lessThan(4))


comparesEqualTo

public Matcher<T> comparesEqualTo(T value)
Creates a matcher of T object that matches when the examined object is equal to the specified value, as reported by the Comparator used to create this builder.

For example:

assertThat(1, ComparatorMatcherBuilder.usingNaturalOrdering().comparesEqualTo(1))

Parameters:
value - the value which, when passed to the Comparator supplied to this builder, should return zero

greaterThan

public Matcher<T> greaterThan(T value)
Creates a matcher of T object that matches when the examined object is greater than the specified value, as reported by the Comparator used to create this builder.

For example:

assertThat(2, ComparatorMatcherBuilder.usingNaturalOrdering().greaterThan(1))

Parameters:
value - the value which, when passed to the Comparator supplied to this builder, should return greater than zero

greaterThanOrEqualTo

public Matcher<T> greaterThanOrEqualTo(T value)
Creates a matcher of T object that matches when the examined object is greater than or equal to the specified value, as reported by the Comparator used to create this builder.

For example:

assertThat(1, ComparatorMatcherBuilder.usingNaturalOrdering().greaterThanOrEqualTo(1))

Parameters:
value - the value which, when passed to the Comparator supplied to this builder, should return greater than or equal to zero

lessThan

public Matcher<T> lessThan(T value)
Creates a matcher of T object that matches when the examined object is less than the specified value, as reported by the Comparator used to create this builder.

For example:

assertThat(1, ComparatorMatcherBuilder.usingNaturalOrdering().lessThan(2))

Parameters:
value - the value which, when passed to the Comparator supplied to this builder, should return less than zero

lessThanOrEqualTo

public Matcher<T> lessThanOrEqualTo(T value)
Creates a matcher of T object that matches when the examined object is less than or equal to the specified value, as reported by the Comparator used to create this builder.

For example:

assertThat(1, ComparatorMatcherBuilder.usingNaturalOrdering().lessThanOrEqualTo(1))

Parameters:
value - the value which, when passed to the Comparator supplied to this builder, should return less than or equal to zero


Copyright © 2014. All rights reserved.