@Factory
@Deprecated
/**
* Please avoid using as the hamcrest way of reporting error wraps a multi-line
* text into a single line and makes hard to understand the problem.
* Instead, please try to use the spock/groovy assert and {@link #containsLine(String, String)}
*/
public static Matcher<String> containsLine(final String line) {
return new BaseMatcher<String>() {
public boolean matches(Object o) {
return containsLine(equalTo(line)).matches(o);
}
public void describeTo(Description description) {
description.appendText("a String that contains line ").appendValue(line);
}
};
}
java类org.hamcrest.Factory的实例源码
Matchers.java 文件源码
项目:Reer
阅读 40
收藏 0
点赞 0
评论 0
Matchers.java 文件源码
项目:Reer
阅读 35
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Object> isSerializable() {
return new BaseMatcher<Object>() {
public boolean matches(Object o) {
try {
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(o);
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
public void describeTo(Description description) {
description.appendText("is serializable");
}
};
}
Matchers.java 文件源码
项目:PACE
阅读 22
收藏 0
点赞 0
评论 0
/**
* Matches the set of entries against the given set of values. The full combinatorial of values passed in is expected in the output set.
*
* @param rows
* Rows to check for.
* @param colFs
* Column families to check for.
* @param colQs
* Column qualifiers to check for.
* @param colVs
* Column visibilities to check for.
* @param values
* Values to check for.
* @return Hamcrest matcher.
*/
@Factory
@SuppressWarnings("unchecked")
public static Matcher<Iterable<Entry<Key,Value>>> hasData(Collection<String> rows, Collection<String> colFs, Collection<String> colQs,
Collection<String> colVs, Collection<String> values) {
int size = rows.size() * colFs.size() * colQs.size() * colVs.size() * values.size();
ArrayList<Matcher<? super Iterable<Entry<Key,Value>>>> matchers = new ArrayList<>(size + 1);
matchers.add(IsIterableWithSize.iterableWithSize(size));
for (String row : rows) {
for (String colF : colFs) {
for (String colQ : colQs) {
for (String colV : colVs) {
for (String value : values) {
matchers.add(hasItems(equalToRow(row, colF, colQ, colV, value)));
}
}
}
}
}
return allOf(matchers);
}
StructureMatchers.java 文件源码
项目:gralog
阅读 23
收藏 0
点赞 0
评论 0
/**
* @param v The expected vertex.
* @return A matcher that compares an actual vertex with the expected
* vertex. Two vertices are considered equal if all their fields are equal.
*/
@Factory
public static Matcher equalsVertex(Vertex v) {
return new TypeSafeMatcher<Vertex>() {
@Override
protected boolean matchesSafely(Vertex w) {
return v.label.equals(w.label)
&& Double.doubleToLongBits(v.radius) == Double.doubleToLongBits(w.radius)
&& v.fillColor.equals(w.fillColor)
&& v.strokeWidth == w.strokeWidth
&& v.textHeight == w.textHeight
&& v.strokeColor.equals(w.strokeColor)
&& v.coordinates.equals(w.coordinates);
}
@Override
public void describeTo(Description d) {
d.appendText("Vertex equality");
}
};
}
AdditionalTableViewMatchers.java 文件源码
项目:chvote-1-0
阅读 22
收藏 0
点赞 0
评论 0
@Factory
public static <T> Matcher<Node> cellWithValue(final Matcher<T> contentsMatcher) {
return new TypeSafeMatcher<Node>(Cell.class) {
@Override
protected boolean matchesSafely(Node item) {
return contentsMatcher.matches(((Cell) item).getItem());
}
@Override
public void describeTo(Description description) {
description.appendText(Cell.class.getSimpleName())
.appendText(" ")
.appendText("with value")
.appendDescriptionOf(contentsMatcher);
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 47
收藏 0
点赞 0
评论 0
@Factory
@Deprecated
/**
* Please avoid using as the hamcrest way of reporting error wraps a multi-line
* text into a single line and makes hard to understand the problem.
* Instead, please try to use the spock/groovy assert and {@link #containsLine(String, String)}
*/
public static Matcher<String> containsLine(final String line) {
return new BaseMatcher<String>() {
public boolean matches(Object o) {
return containsLine(equalTo(line)).matches(o);
}
public void describeTo(Description description) {
description.appendText("a String that contains line ").appendValue(line);
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 43
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Object> isSerializable() {
return new BaseMatcher<Object>() {
public boolean matches(Object o) {
try {
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(o);
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
public void describeTo(Description description) {
description.appendText("is serializable");
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 24
收藏 0
点赞 0
评论 0
/**
* A reimplementation of hamcrest's isA() but without the broken generics.
*/
@Factory
public static Matcher<Object> isA(final Class<?> type) {
return new BaseMatcher<Object>() {
public boolean matches(Object item) {
return type.isInstance(item);
}
public void describeTo(Description description) {
description.appendText("instanceof ").appendValue(type);
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 24
收藏 0
点赞 0
评论 0
@Factory
public static <T extends CharSequence> Matcher<T> matchesRegexp(final String pattern) {
return new BaseMatcher<T>() {
public boolean matches(Object o) {
return Pattern.compile(pattern, Pattern.DOTALL).matcher((CharSequence) o).matches();
}
public void describeTo(Description description) {
description.appendText("a CharSequence that matches regexp ").appendValue(pattern);
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 23
收藏 0
点赞 0
评论 0
@Factory
public static <T extends CharSequence> Matcher<T> matchesRegexp(final Pattern pattern) {
return new BaseMatcher<T>() {
public boolean matches(Object o) {
return pattern.matcher((CharSequence) o).matches();
}
public void describeTo(Description description) {
description.appendText("a CharSequence that matches regexp ").appendValue(pattern);
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 40
收藏 0
点赞 0
评论 0
@Factory
public static <T extends CharSequence> Matcher<T> containsText(final String pattern) {
return new BaseMatcher<T>() {
public boolean matches(Object o) {
return ((String) o).contains(pattern);
}
public void describeTo(Description description) {
description.appendText("a CharSequence that contains text ").appendValue(pattern);
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 39
收藏 0
点赞 0
评论 0
@Factory
public static <T> Matcher<T> strictlyEqual(final T other) {
return new BaseMatcher<T>() {
public boolean matches(Object o) {
return strictlyEquals(o, other);
}
public void describeTo(Description description) {
description.appendText("an Object that strictly equals ").appendValue(other);
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 25
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<String> containsLine(final Matcher<? super String> matcher) {
return new BaseMatcher<String>() {
public boolean matches(Object o) {
String str = (String) o;
return containsLine(str, matcher);
}
public void describeTo(Description description) {
description.appendText("a String that contains line that is ").appendDescriptionOf(matcher);
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 38
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Iterable<?>> isEmpty() {
return new BaseMatcher<Iterable<?>>() {
public boolean matches(Object o) {
Iterable<?> iterable = (Iterable<?>) o;
return iterable != null && !iterable.iterator().hasNext();
}
public void describeTo(Description description) {
description.appendText("an empty Iterable");
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 22
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Map<?, ?>> isEmptyMap() {
return new BaseMatcher<Map<?, ?>>() {
public boolean matches(Object o) {
Map<?, ?> map = (Map<?, ?>) o;
return map != null && map.isEmpty();
}
public void describeTo(Description description) {
description.appendText("an empty map");
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 22
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Throwable> hasMessage(final Matcher<String> matcher) {
return new BaseMatcher<Throwable>() {
public boolean matches(Object o) {
Throwable t = (Throwable) o;
return matcher.matches(t.getMessage());
}
public void describeTo(Description description) {
description.appendText("an exception with message that is ").appendDescriptionOf(matcher);
}
};
}
Matchers.java 文件源码
项目:Reer
阅读 22
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<String> normalizedLineSeparators(final Matcher<String> matcher) {
return new BaseMatcher<String>() {
public boolean matches(Object o) {
String string = (String) o;
return matcher.matches(string.replace(SystemProperties.getInstance().getLineSeparator(), "\n"));
}
public void describeTo(Description description) {
matcher.describeTo(description);
description.appendText(" (normalize line separators)");
}
};
}
ThrowableTranslatorTest.java 文件源码
项目:reactive-ms-example
阅读 21
收藏 0
点赞 0
评论 0
@Factory
private static DiagnosingMatcher<Object> translateTo(HttpStatus status) {
return new DiagnosingMatcher<Object>() {
private static final String EXCEPTION = "EXCEPTION";
@Override
public void describeTo(final Description description) {
description.appendText("does not translate to ").appendText(status.toString());
}
@SuppressWarnings("unchecked")
protected boolean matches(final Object item, final Description mismatch) {
if (item instanceof Class) {
if (((Class) item).getClass().isInstance(Throwable.class)) {
Class<? extends Throwable> type = (Class<? extends Throwable>) item;
try {
Throwable exception = type.getConstructor(String.class).newInstance(EXCEPTION);
Mono.just(exception).transform(ThrowableTranslator::translate).subscribe(translator -> {
assertThat(translator.getMessage(), is(EXCEPTION));
assertThat(translator.getHttpStatus(), is(status));
});
} catch (InstantiationException | IllegalAccessException |
InvocationTargetException | NoSuchMethodException cause) {
throw new AssertionError("This exception class has not constructor with a String", cause);
}
return true;
}
}
mismatch.appendText(item.toString());
return false;
}
};
}
PredicateMatcher.java 文件源码
项目:ContentPal
阅读 25
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Predicate> absentBackReferences(int noOfPredicateArguments)
{
Matcher[] matchers = new Matcher[noOfPredicateArguments];
Arrays.fill(matchers, isAbsent());
return new ArgumentBackReferences(Absent.<TransactionContext>absent(), matchers);
}
PredicateMatcher.java 文件源码
项目:ContentPal
阅读 22
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Predicate> absentBackReferences(TransactionContext tc, int noOfPredicateArguments)
{
Matcher[] matchers = new Matcher[noOfPredicateArguments];
Arrays.fill(matchers, isAbsent());
return new ArgumentBackReferences(new Present<>(tc), matchers);
}
RingBufferEventMatcher.java 文件源码
项目:disruptor-code-analysis
阅读 24
收藏 0
点赞 0
评论 0
@Factory
public static RingBufferEventMatcher ringBufferWithEvents(final Object... values)
{
Matcher<?>[] valueMatchers = new Matcher[values.length];
for (int i = 0; i < values.length; i++)
{
final Object value = values[i];
valueMatchers[i] = is(value);
}
return new RingBufferEventMatcher(valueMatchers);
}
BattleModelMatchers.java 文件源码
项目:harenacapsa
阅读 25
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<BattleModel> monsterIsAlive() {
return new FeatureMatcher<BattleModel, Boolean>( is( true ), "monster alive", "monster alive" ) {
@Override
protected Boolean featureValueOf(BattleModel actual) {
return actual.monsterAlive();
}
};
}
HasAttribute.java 文件源码
项目:canfactory-html
阅读 22
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<HtmlElement> hasAttributes(String... nameValues) {
if (nameValues.length % 2 != 0) throw new RuntimeException("The last attr was missing a value");
List<Attribute> expectedAttrs = new ArrayList<Attribute>();
for (int i = 0; i < nameValues.length; i += 2) {
expectedAttrs.add(new Attribute(nameValues[i], nameValues[i + 1]));
}
return new HasAttribute(expectedAttrs);
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 32
收藏 0
点赞 0
评论 0
/**
* A reimplementation of hamcrest's isA() but without the broken generics.
*/
@Factory
public static Matcher<Object> isA(final Class<?> type) {
return new BaseMatcher<Object>() {
public boolean matches(Object item) {
return type.isInstance(item);
}
public void describeTo(Description description) {
description.appendText("instanceof ").appendValue(type);
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 33
收藏 0
点赞 0
评论 0
@Factory
public static <T extends CharSequence> Matcher<T> containsText(final String pattern) {
return new BaseMatcher<T>() {
public boolean matches(Object o) {
return Pattern.compile(pattern).matcher((CharSequence) o).find();
}
public void describeTo(Description description) {
description.appendText("a CharSequence that contains text ").appendValue(pattern);
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 31
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<String> containsLine(final Matcher<? super String> matcher) {
return new BaseMatcher<String>() {
public boolean matches(Object o) {
String str = (String) o;
return containsLine(str, matcher);
}
public void describeTo(Description description) {
description.appendText("a String that contains line that is ").appendDescriptionOf(matcher);
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 22
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Iterable<?>> isEmpty() {
return new BaseMatcher<Iterable<?>>() {
public boolean matches(Object o) {
Iterable<?> iterable = (Iterable<?>) o;
return iterable != null && !iterable.iterator().hasNext();
}
public void describeTo(Description description) {
description.appendText("an empty Iterable");
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 38
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<Throwable> hasMessage(final Matcher<String> matcher) {
return new BaseMatcher<Throwable>() {
public boolean matches(Object o) {
Throwable t = (Throwable) o;
return matcher.matches(t.getMessage());
}
public void describeTo(Description description) {
description.appendText("an exception with message that is ").appendDescriptionOf(matcher);
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 30
收藏 0
点赞 0
评论 0
@Factory
public static Matcher<String> normalizedLineSeparators(final Matcher<String> matcher) {
return new BaseMatcher<String>() {
public boolean matches(Object o) {
String string = (String) o;
return matcher.matches(string.replace(SystemProperties.getLineSeparator(), "\n"));
}
public void describeTo(Description description) {
matcher.describeTo(description);
description.appendText(" (normalize line separators)");
}
};
}
Matchers.java 文件源码
项目:Pushjet-Android
阅读 33
收藏 0
点赞 0
评论 0
/**
* A reimplementation of hamcrest's isA() but without the broken generics.
*/
@Factory
public static Matcher<Object> isA(final Class<?> type) {
return new BaseMatcher<Object>() {
public boolean matches(Object item) {
return type.isInstance(item);
}
public void describeTo(Description description) {
description.appendText("instanceof ").appendValue(type);
}
};
}