use of org.hamcrest.BaseMatcher in project neo4j by neo4j.
the class BoltMatchers method hasNoTransaction.
public static Matcher<BoltStateMachine> hasNoTransaction() {
return new BaseMatcher<BoltStateMachine>() {
@Override
public boolean matches(final Object item) {
final BoltStateMachine machine = (BoltStateMachine) item;
final StatementProcessor statementProcessor = machine.statementProcessor();
return statementProcessor == null || !statementProcessor.hasTransaction();
}
@Override
public void describeTo(Description description) {
description.appendText("no transaction");
}
};
}
use of org.hamcrest.BaseMatcher in project spring-security by spring-projects.
the class DefaultJaasAuthenticationProviderTests method verifyFailedLogin.
private void verifyFailedLogin() {
verify(publisher).publishEvent(argThat(new BaseMatcher<JaasAuthenticationFailedEvent>() {
public void describeTo(Description desc) {
desc.appendText("isA(org.springframework.security.authentication.jaas.event.JaasAuthenticationFailedEvent)");
desc.appendText(" && event.getException() != null");
}
public boolean matches(Object arg) {
JaasAuthenticationFailedEvent e = (JaasAuthenticationFailedEvent) arg;
return e.getException() != null;
}
}));
verifyNoMoreInteractions(publisher);
}
use of org.hamcrest.BaseMatcher in project zaproxy by zaproxy.
the class VariantCookieUnitTest method containsCookieHeader.
private static Matcher<HttpMessage> containsCookieHeader(final String cookies) {
return new BaseMatcher<HttpMessage>() {
@Override
public boolean matches(Object actualValue) {
HttpMessage message = (HttpMessage) actualValue;
Vector<String> cookieLines = message.getRequestHeader().getHeaders(HttpHeader.COOKIE);
if (cookieLines == null || cookieLines.size() != 1) {
return false;
}
return cookies.equals(cookieLines.get(0));
}
@Override
public void describeTo(Description description) {
description.appendText("cookie header ").appendValue(cookies);
}
public void describeMismatch(Object item, Description description) {
HttpMessage message = (HttpMessage) item;
Vector<String> cookieLines = message.getRequestHeader().getHeaders(HttpHeader.COOKIE);
if (cookieLines == null) {
description.appendText("has no cookie headers");
} else if (cookieLines.size() == 1) {
description.appendText("was ").appendValue(cookieLines.get(0));
} else {
description.appendText("has multiple cookie headers ").appendValue(cookieLines);
}
}
};
}
use of org.hamcrest.BaseMatcher in project zaproxy by zaproxy.
the class VariantCookieUnitTest method hasNoCookieHeaders.
private static Matcher<HttpMessage> hasNoCookieHeaders() {
return new BaseMatcher<HttpMessage>() {
@Override
public boolean matches(Object actualValue) {
HttpMessage message = (HttpMessage) actualValue;
Vector<String> cookieLines = message.getRequestHeader().getHeaders(HttpHeader.COOKIE);
if (cookieLines == null || cookieLines.isEmpty()) {
return true;
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("no cookie header");
}
public void describeMismatch(Object item, Description description) {
HttpMessage message = (HttpMessage) item;
Vector<String> cookieLines = message.getRequestHeader().getHeaders(HttpHeader.COOKIE);
if (cookieLines.size() == 1) {
description.appendText("has one cookie header ").appendValue(cookieLines.get(0));
} else {
description.appendText("has multiple cookie headers ").appendValue(cookieLines);
}
}
};
}
use of org.hamcrest.BaseMatcher in project zaproxy by zaproxy.
the class VariantHeaderUnitTest method containsHeader.
private static Matcher<HttpMessage> containsHeader(final String name, final String value) {
return new BaseMatcher<HttpMessage>() {
@Override
public boolean matches(Object actualValue) {
HttpMessage message = (HttpMessage) actualValue;
List<HttpHeaderField> headers = message.getRequestHeader().getHeaders();
if (headers.isEmpty()) {
return false;
}
for (HttpHeaderField header : headers) {
if (name.equals(header.getName()) && value.equals(header.getValue())) {
return true;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("header ").appendValue(name + ": " + value);
}
public void describeMismatch(Object item, Description description) {
HttpMessage message = (HttpMessage) item;
List<HttpHeaderField> headers = message.getRequestHeader().getHeaders();
if (headers.isEmpty()) {
description.appendText("has no headers");
} else {
description.appendText("was ").appendValue(headers);
}
}
};
}
Aggregations