Package org.hamcrest.comparator
Class ComparatorMatcherBuilder<T>
- java.lang.Object
-
- org.hamcrest.comparator.ComparatorMatcherBuilder<T>
-
public final class ComparatorMatcherBuilder<T> extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ComparatorMatcherBuilder<T>
comparedBy(java.util.Comparator<T> comparator)
Creates a matcher factory for matchers ofComparators
s ofT
.Matcher<T>
comparesEqualTo(T value)
Creates a matcher ofT
object that matches when the examined object is equal to the specified value, as reported by theComparator
used to create this builder.Matcher<T>
greaterThan(T value)
Creates a matcher ofT
object that matches when the examined object is greater than the specified value, as reported by theComparator
used to create this builder.Matcher<T>
greaterThanOrEqualTo(T value)
Creates a matcher ofT
object that matches when the examined object is greater than or equal to the specified value, as reported by theComparator
used to create this builder.Matcher<T>
lessThan(T value)
Creates a matcher ofT
object that matches when the examined object is less than the specified value, as reported by theComparator
used to create this builder.Matcher<T>
lessThanOrEqualTo(T value)
Creates a matcher ofT
object that matches when the examined object is less than or equal to the specified value, as reported by theComparator
used to create this builder.static <T extends java.lang.Comparable<T>>
ComparatorMatcherBuilder<T>usingNaturalOrdering()
Creates a matcher factory for matchers ofComparable
s.
-
-
-
Method Detail
-
usingNaturalOrdering
public static <T extends java.lang.Comparable<T>> ComparatorMatcherBuilder<T> usingNaturalOrdering()
Creates a matcher factory for matchers ofComparable
s. For example:assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().lessThanOrEqualTo(1))
- Type Parameters:
T
- the matcher type.- Returns:
- The matcher.
-
comparedBy
public static <T> ComparatorMatcherBuilder<T> comparedBy(java.util.Comparator<T> comparator)
Creates a matcher factory for matchers ofComparators
s ofT
. For example:assertThat(5, comparedBy(new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { return -o1.compareTo(o2); } }).lessThan(4))
- Type Parameters:
T
- the matcher type.- Parameters:
comparator
- the comparator for the matcher to use.- Returns:
- The matcher.
-
comparesEqualTo
public Matcher<T> comparesEqualTo(T value)
Creates a matcher ofT
object that matches when the examined object is equal to the specified value, as reported by theComparator
used to create this builder. For example:assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().comparesEqualTo(1))
- Parameters:
value
- the value which, when passed to the Comparator supplied to this builder, should return zero- Returns:
- The matcher.
-
greaterThan
public Matcher<T> greaterThan(T value)
Creates a matcher ofT
object that matches when the examined object is greater than the specified value, as reported by theComparator
used to create this builder. For example:assertThat(2, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().greaterThan(1))
- Parameters:
value
- the value which, when passed to the Comparator supplied to this builder, should return greater than zero- Returns:
- The matcher.
-
greaterThanOrEqualTo
public Matcher<T> greaterThanOrEqualTo(T value)
Creates a matcher ofT
object that matches when the examined object is greater than or equal to the specified value, as reported by theComparator
used to create this builder. For example:assertThat(1, ComparatorMatcherBuilder.<Integer>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- Returns:
- The matcher.
-
lessThan
public Matcher<T> lessThan(T value)
Creates a matcher ofT
object that matches when the examined object is less than the specified value, as reported by theComparator
used to create this builder. For example:assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().lessThan(2))
- Parameters:
value
- the value which, when passed to the Comparator supplied to this builder, should return less than zero- Returns:
- The matcher.
-
lessThanOrEqualTo
public Matcher<T> lessThanOrEqualTo(T value)
Creates a matcher ofT
object that matches when the examined object is less than or equal to the specified value, as reported by theComparator
used to create this builder. For example:assertThat(1, ComparatorMatcherBuilder.<Integer>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- Returns:
- The matcher.
-
-