public class Matchers extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
Matchers.IsWithin<T extends Number>
Matcher that tests whether the numeric value is within a given difference
another value.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static double |
EPSILON
A small positive value.
|
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends Comparable<T>> |
between(T min,
T max)
Creates a matcher that matches if the examined value is between bounds:
min ≤ value ≤ max. |
static <F,T> org.hamcrest.Matcher<F> |
compose(org.hamcrest.Matcher<T> matcher,
Function<F,T> f)
Creates a matcher by applying a function to a value before calling
another matcher.
|
static org.hamcrest.Matcher<String> |
containsStringLinux(String value)
Creates a matcher that matches when the examined string is equal to the
specified
operand when all Windows-style line endings ("\r\n")
have been converted to Unix-style line endings ("\n"). |
static org.hamcrest.Matcher<String> |
containsWithoutNodeIds(String value)
Creates a
Matcher that matches execution plan and trims , id=123 node ids. |
static <E extends Comparable> |
equalsUnordered(E... lines) |
static org.hamcrest.Matcher<? super Throwable> |
expectThrowable(Throwable expected)
Creates a matcher that matches if the examined value is expected throwable.
|
static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> |
hasFieldNames(String fieldNames)
Creates a Matcher that matches a
RelNode if its field
names, converting to a list, are equal to the given value. |
static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> |
hasHints(String value)
Creates a Matcher that matches a
RelNode if its hints string
representation is equal to the given value. |
static org.hamcrest.Matcher<org.apache.calcite.rex.RexNode> |
hasRex(String value)
Creates a Matcher that matches a
RexNode if its string
representation, after converting Windows-style line endings ("\r\n")
to Unix-style line endings ("\n"), is equal to the given value. |
static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> |
hasTree(String value)
Creates a Matcher that matches a
RelNode if its string
representation, after converting Windows-style line endings ("\r\n")
to Unix-style line endings ("\n"), is equal to the given value. |
static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> |
inTree(String value)
Creates a Matcher that matches a
RelNode if its string
representation, after converting Windows-style line endings ("\r\n")
to Unix-style line endings ("\n"), contains the given value
as a substring. |
static org.hamcrest.Matcher<Double> |
isAlmost(double value)
Creates a matcher that matches when the examined object is within
EPSILON of the specified operand. |
static org.hamcrest.Matcher<Charset> |
isCharset(String charsetName)
Creates a matcher that matches if the examined value has a given name.
|
static org.hamcrest.Matcher<String> |
isLinux(String value)
Creates a Matcher that matches when the examined string is equal to the
specified
value when all Windows-style line endings ("\r\n")
have been converted to Unix-style line endings ("\n"). |
static org.hamcrest.Matcher<com.google.common.collect.RangeSet> |
isRangeSet(String value)
Creates a Matcher that matches a
RangeSet if its string
representation, after changing "ߩ" to " |
static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> |
relIsValid()
Matcher that matches a
RelNode if the RelNode is valid
per RelValidityChecker. |
static org.hamcrest.Matcher<? super ResultSet> |
returnsUnordered(String... lines)
Creates a matcher that matches if the examined result set returns the
given collection of rows in some order.
|
static String |
sanitizeRangeSet(String string)
Changes all '‥' (a unicode symbol denoting a range) to '
|
static <T> org.hamcrest.Matcher<Iterable<T>> |
sortsAs(String value)
Matcher that succeeds for any collection that, when converted to strings
and sorted on those strings, matches the given reference string.
|
static String |
trimNodeIds(String s) |
static <T extends Number> |
within(T value,
double epsilon)
Creates a matcher that matches when the examined object is within
epsilon of the specified value. |
public static final double EPSILON
public static org.hamcrest.Matcher<? super ResultSet> returnsUnordered(String... lines)
Closes the result set after reading.
For example:
assertThat(statement.executeQuery("select empno from emp"),
returnsUnordered("empno=1234", "empno=100"));public static <E extends Comparable> org.hamcrest.Matcher<Iterable<E>> equalsUnordered(E... lines)
public static <T extends Number> org.hamcrest.Matcher<T> within(T value, double epsilon)
epsilon of the specified value.public static org.hamcrest.Matcher<Double> isAlmost(double value)
EPSILON of the specified operand.public static <T extends Comparable<T>> org.hamcrest.Matcher<T> between(T min, T max)
min ≤ value ≤ max.T - value typemin - Lower boundmax - Upper boundpublic static <F,T> org.hamcrest.Matcher<F> compose(org.hamcrest.Matcher<T> matcher,
Function<F,T> f)
public static org.hamcrest.Matcher<String> isLinux(String value)
value when all Windows-style line endings ("\r\n")
have been converted to Unix-style line endings ("\n").
Thus, if foo() is a function that returns "hello{newline}world"
in the current operating system's line endings, then
assertThat(foo(), isLinux("hello\nworld"));
will succeed on all platforms.
Util.toLinux(String)public static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> relIsValid()
RelNode if the RelNode is valid
per RelValidityChecker.public static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> hasTree(String value)
RelNode if its string
representation, after converting Windows-style line endings ("\r\n")
to Unix-style line endings ("\n"), is equal to the given value.public static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> hasFieldNames(String fieldNames)
RelNode if its field
names, converting to a list, are equal to the given value.public static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> inTree(String value)
RelNode if its string
representation, after converting Windows-style line endings ("\r\n")
to Unix-style line endings ("\n"), contains the given value
as a substring.public static org.hamcrest.Matcher<org.apache.calcite.rex.RexNode> hasRex(String value)
RexNode if its string
representation, after converting Windows-style line endings ("\r\n")
to Unix-style line endings ("\n"), is equal to the given value.public static org.hamcrest.Matcher<org.apache.calcite.rel.RelNode> hasHints(String value)
RelNode if its hints string
representation is equal to the given value.public static org.hamcrest.Matcher<com.google.common.collect.RangeSet> isRangeSet(String value)
RangeSet if its string
representation, after changing "ߩ" to "..",
is equal to the given value.
This method is necessary because RangeSet.toString() changed
behavior. Guava 19 - 28 used a unicode symbol; Guava 29 onwards uses "..".
public static String sanitizeRangeSet(String string)
@API(since="1.22",
status=EXPERIMENTAL)
public static org.hamcrest.Matcher<String> containsWithoutNodeIds(String value)
Matcher that matches execution plan and trims , id=123 node ids.
RelOptNode.getId() is not stable across runs, so this matcher enables to trim those.value - execpted execution planpublic static org.hamcrest.Matcher<String> containsStringLinux(String value)
operand when all Windows-style line endings ("\r\n")
have been converted to Unix-style line endings ("\n").
Thus, if foo() is a function that returns "hello{newline}world"
in the current operating system's line endings, then
assertThat(foo(), isLinux("hello\nworld"));
will succeed on all platforms.
Util.toLinux(String)public static org.hamcrest.Matcher<? super Throwable> expectThrowable(Throwable expected)
expected - Throwable to match.public static org.hamcrest.Matcher<Charset> isCharset(String charsetName)
charsetName - Name of character setCharset.forName(java.lang.String)public static <T> org.hamcrest.Matcher<Iterable<T>> sortsAs(String value)
Use it as an alternative to Is.is(org.hamcrest.Matcher<T>) if items in your
list might occur in any order.
For example:
List<Integer> ints = Arrays.asList(2, 500, 12);
assertThat(ints, sortsAs("[12, 2, 500]");
Copyright © 2012-2023 Apache Software Foundation. All Rights Reserved.