use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.
the class TransactionMatchers method graphContainsDeletedNodes.
public static Matcher<? super HTTP.Response> graphContainsDeletedNodes(final int amount) {
return new TypeSafeMatcher<HTTP.Response>() {
@Override
protected boolean matchesSafely(HTTP.Response response) {
try {
Iterator<JsonNode> nodes = getJsonNodeWithName(response, "graph").get("nodes").iterator();
for (int i = 0; i < amount; ++i) {
assertTrue(nodes.hasNext());
JsonNode node = nodes.next();
assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
}
while (nodes.hasNext()) {
JsonNode node = nodes.next();
assertNull(node.get("deleted"));
}
return true;
} catch (JsonParseException e) {
return false;
}
}
@Override
public void describeTo(Description description) {
}
};
}
use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.
the class StreamMatchers method equalsStream.
public static Matcher<BoltResult> equalsStream(final String[] fieldNames, final Matcher... records) {
return new TypeSafeMatcher<BoltResult>() {
@Override
protected boolean matchesSafely(BoltResult item) {
if (!Arrays.equals(fieldNames, item.fieldNames())) {
return false;
}
final Iterator<Matcher> expected = asList(records).iterator();
final AtomicBoolean matched = new AtomicBoolean(true);
try {
item.accept(new BoltResult.Visitor() {
@Override
public void visit(Record record) {
if (!expected.hasNext() || !expected.next().matches(record)) {
matched.set(false);
}
}
@Override
public void addMetadata(String key, Object value) {
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
// All records matched, and there are no more expected records.
return matched.get() && !expected.hasNext();
}
@Override
public void describeTo(Description description) {
description.appendText("Stream[").appendValueList(" fieldNames=[", ",", "]", fieldNames).appendList(", records=[", ",", "]", asList(records));
}
};
}
use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.
the class MessageMatchers method msgFailure.
public static Matcher<ResponseMessage> msgFailure(final Status status, final String message) {
return new TypeSafeMatcher<ResponseMessage>() {
@Override
protected boolean matchesSafely(ResponseMessage t) {
assertThat(t, instanceOf(FailureMessage.class));
FailureMessage msg = (FailureMessage) t;
assertThat(msg.status(), equalTo(status));
assertThat(msg.message(), containsString(message));
return true;
}
@Override
public void describeTo(Description description) {
description.appendText("FAILURE");
}
};
}
use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.
the class MessageMatchers method msgRecord.
public static Matcher<ResponseMessage> msgRecord(final Matcher<Record> matcher) {
return new TypeSafeMatcher<ResponseMessage>() {
@Override
protected boolean matchesSafely(ResponseMessage t) {
assertThat(t, instanceOf(RecordMessage.class));
RecordMessage msg = (RecordMessage) t;
assertThat(msg.record(), matcher);
return true;
}
@Override
public void describeTo(Description description) {
description.appendText("RECORD ");
description.appendDescriptionOf(matcher);
}
};
}
use of org.hamcrest.TypeSafeMatcher in project wire-android by wireapp.
the class CustomMatchers method otrSwitchWithId.
public static Matcher<View> otrSwitchWithId(final int id) {
return new TypeSafeMatcher<View>() {
Resources resources = null;
@Override
public void describeTo(Description description) {
String idDescription = Integer.toString(id);
if (resources != null) {
try {
idDescription = resources.getResourceName(id);
} catch (Resources.NotFoundException e) {
// No big deal, will just use the int value.
idDescription = String.format("%s (resource name not found)", id);
}
}
description.appendText("with id: " + idDescription);
}
@Override
public boolean matchesSafely(View view) {
resources = view.getResources();
ViewParent parent = view.getParent();
return parent != null && parent instanceof OtrSwitch && id == ((OtrSwitch) parent).getId() && view instanceof SwitchCompat;
}
};
}
Aggregations