下面列出了org.hamcrest.Matchers#equalTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void readsFromCharSequenceWithCharsetName() throws Exception {
final String content = "Simple content";
new Assertion<>(
"Can't read from char sequence with charset name",
new TextOf(
new InputStreamOf(
content,
StandardCharsets.UTF_8.name()
)
).asString(),
Matchers.equalTo(content)
);
}
/** A Matcher that tests that the URI has a path equal to the given path. */
private static Matcher<URI> hasPath(final String path) {
return new FeatureMatcher<URI, String>(Matchers.equalTo(path), "path", "path") {
@Override
protected String featureValueOf(final URI actual) {
return actual.getPath();
}
};
}
@Test
public void readsFromCharSequenceWithCharset() throws Exception {
final String content = "Another simple content";
new Assertion<>(
"Can't read from char sequence with charset",
new TextOf(
new InputStreamOf(
content,
StandardCharsets.UTF_8
)
).asString(),
Matchers.equalTo(content)
);
}
@Test
public void readsFileContent() throws Exception {
final File file = this.folder.newFile("readFileContent.txt-2");
final String content = "Content in a file";
new LengthOf(
new TeeInput(content, file)
).intValue();
new Assertion<>(
"Can't read from file",
new TextOf(new InputStreamOf(file)).asString(),
Matchers.equalTo(content)
);
}
private static <T> boolean matchesPrimitive(String path, T expected, T actual, Description mismatchDescription) {
Matcher<Object> matcher = Matchers.equalTo(expected);
if (!matcher.matches(actual)) {
appendPath(mismatchDescription, path);
matcher.describeMismatch(actual, mismatchDescription);
return false;
} else {
return true;
}
}
@Test
public void readsBytesArray() throws Exception {
final String content = "Bytes array content";
final byte[] bytes = new BytesOf(content).asBytes();
new Assertion<>(
"Can't read from byte array",
new TextOf(new InputStreamOf(bytes)).asString(),
Matchers.equalTo(content)
);
}
@Test
public void readsFromReaderWithCharsetWithMax() throws Exception {
final String content = "Reading with charset and buffer size";
new Assertion<>(
"Can't read from reader with charset and buffer size",
new TextOf(
new InputStreamOf(
new StringReader(content),
StandardCharsets.UTF_8,
1
)
).asString(),
Matchers.equalTo(content)
);
}
public static Matcher<TimeWindow> timeWindow(long start, long end) {
return Matchers.equalTo(new TimeWindow(start, end));
}
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue(
Matcher<? super T> valueMatcher, long timestamp) {
return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), Matchers.anything());
}
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue(
Matcher<? super T> valueMatcher, long timestamp, W window) {
return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), Matchers.equalTo(window));
}
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue(
Matcher<? super T> valueMatcher, long timestamp, Matcher<? super W> windowMatcher) {
return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), windowMatcher);
}
public static Matcher<TimeWindow> timeWindow(long start, long end) {
return Matchers.equalTo(new TimeWindow(start, end));
}
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue(
Matcher<? super T> valueMatcher, long timestamp, Matcher<? super W> windowMatcher) {
return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), windowMatcher);
}
public static Matcher<QueryPredicate> equivalentTo(@Nonnull QueryComponent component) {
return Matchers.equalTo(component.normalizeForPlanner(BlankSource.INSTANCE));
}
@Nonnull
public ElementPredicateMatcher equalsValue(@Nonnull Object comparand) {
return new ElementPredicateMatcher(this,
Matchers.equalTo(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, comparand)));
}
@Nonnull
public ElementPredicateMatcher notEquals(@Nonnull Object comparand) {
return new ElementPredicateMatcher(this,
Matchers.equalTo(new Comparisons.SimpleComparison(Comparisons.Type.NOT_EQUALS, comparand)));
}
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue(
Matcher<? super T> valueMatcher, long timestamp, W window) {
return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), Matchers.equalTo(window));
}
public static <T, W extends Window> Matcher<StreamRecord<? extends WindowedValue<? extends T, ? extends W>>> isWindowedValue(
Matcher<? super T> valueMatcher, long timestamp, Matcher<? super W> windowMatcher) {
return new WindowedValueMatcher<>(valueMatcher, Matchers.equalTo(timestamp), windowMatcher);
}
/**
* Ctor with equalTo matcher and default charset.
* @param expected String to test against
*/
public HmRqTextBody(final String expected) {
this(Matchers.equalTo(expected));
}
/**
* Create matcher using HTTP code.
* @param val HTTP code value
* @since 0.17
*/
public HmRsStatus(final int val) {
this(Matchers.equalTo(val));
}