Top Inners Fields Constructors Methods
org.hamcrest.comparator

public final Class ComparatorMatcherBuilder<T>

extends Object
Class Inheritance
Imports
org.hamcrest.Description, .Matcher, .TypeSafeMatcher, java.util.Comparator

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final Comparator<T>
private final boolean

Constructor Summary

AccessConstructor and Description
private
ComparatorMatcherBuilder(Comparator<T> comparator, boolean includeComparatorInDescription)

Method Summary

Modifier and TypeMethod and Description
public static <T> ComparatorMatcherBuilder<T>
comparedBy(Comparator<T> comparator)

Creates a matcher factory for matchers of Comparatorss of T.

public Matcher<T>
comparesEqualTo(T
the value which, when passed to the Comparator supplied to this builder, should return zero
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.

public Matcher<T>
greaterThan(T
the value which, when passed to the Comparator supplied to this builder, should return greater than zero
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.

public Matcher<T>
greaterThanOrEqualTo(T
the value which, when passed to the Comparator supplied to this builder, should return greater than or equal to zero
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.

public Matcher<T>
lessThan(T
the value which, when passed to the Comparator supplied to this builder, should return less than zero
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.

public Matcher<T>
lessThanOrEqualTo(T
the value which, when passed to the Comparator supplied to this builder, should return less than or equal to zero
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.

public static <T extends Comparable<T>> ComparatorMatcherBuilder<T>
usingNaturalOrdering()

Creates a matcher factory for matchers of Comparables.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

comparatorback to summary
private final Comparator<T> comparator
includeComparatorInDescriptionback to summary
private final boolean includeComparatorInDescription

Constructor Detail

ComparatorMatcherBuilderback to summary
private ComparatorMatcherBuilder(Comparator<T> comparator, boolean includeComparatorInDescription)

Method Detail

comparedByback to summary
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<Integer>() {
public int compare(Integer o1, Integer o2) {
return -o1.compareTo(o2);
}
}).lessThan(4))
comparesEqualToback to summary
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.<Integer>usingNaturalOrdering().comparesEqualTo(1))
Parameters
value:T

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

greaterThanback to summary
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.<Integer>usingNaturalOrdering().greaterThan(1))
Parameters
value:T

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

greaterThanOrEqualToback to summary
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.<Integer>usingNaturalOrdering().greaterThanOrEqualTo(1))
Parameters
value:T

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

lessThanback to summary
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.<Integer>usingNaturalOrdering().lessThan(2))
Parameters
value:T

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

lessThanOrEqualToback to summary
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.<Integer>usingNaturalOrdering().lessThanOrEqualTo(1))
Parameters
value:T

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

usingNaturalOrderingback to summary
public static <T extends Comparable<T>> ComparatorMatcherBuilder<T> usingNaturalOrdering()

Creates a matcher factory for matchers of Comparables. For example:

assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().lessThanOrEqualTo(1))
org.hamcrest.comparator back to summary

private final Class ComparatorMatcherBuilder.ComparatorMatcher<T>

extends TypeSafeMatcher<T>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Comparator<T>
private static final String[]
private static final int
private final T
private static final int
private final boolean
private static final int
private final int
private final int

Constructor Summary

AccessConstructor and Description
private
ComparatorMatcher(Comparator<T> comparator, T expected, int minCompare, int maxCompare, boolean includeComparatorInDescription)

Method Summary

Modifier and TypeMethod and Description
private static String
asText(int comparison)

public void
describeMismatchSafely(T actual, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this.
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public boolean
matchesSafely(T actual)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this.
Inherited from org.hamcrest.TypeSafeMatcher:
describeMismatchmatches

Field Detail

comparatorback to summary
private final Comparator<T> comparator
comparisonDescriptionsback to summary
private static final String[] comparisonDescriptions
EQUALback to summary
private static final int EQUAL
expectedback to summary
private final T expected
GREATER_THANback to summary
private static final int GREATER_THAN
includeComparatorInDescriptionback to summary
private final boolean includeComparatorInDescription
LESS_THANback to summary
private static final int LESS_THAN
maxCompareback to summary
private final int maxCompare
minCompareback to summary
private final int minCompare

Constructor Detail

ComparatorMatcherback to summary
private ComparatorMatcher(Comparator<T> comparator, T expected, int minCompare, int maxCompare, boolean includeComparatorInDescription)

Method Detail

asTextback to summary
private static String asText(int comparison)
describeMismatchSafelyback to summary
public void describeMismatchSafely(T actual, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Doc from org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override
describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
matchesSafelyback to summary
public boolean matchesSafely(T actual)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override