Search in sources :

Example 16 with BaseMatcher

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");
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) StatementProcessor(org.neo4j.bolt.v1.runtime.StatementProcessor)

Example 17 with BaseMatcher

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);
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) JaasAuthenticationFailedEvent(org.springframework.security.authentication.jaas.event.JaasAuthenticationFailedEvent)

Example 18 with BaseMatcher

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);
            }
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) HttpMessage(org.parosproxy.paros.network.HttpMessage)

Example 19 with BaseMatcher

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);
            }
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) HttpMessage(org.parosproxy.paros.network.HttpMessage)

Example 20 with BaseMatcher

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);
            }
        }
    };
}
Also used : HttpHeaderField(org.parosproxy.paros.network.HttpHeaderField) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) HttpMessage(org.parosproxy.paros.network.HttpMessage)

Aggregations

BaseMatcher (org.hamcrest.BaseMatcher)25 Description (org.hamcrest.Description)25 Test (org.junit.Test)6 Bundle (android.os.Bundle)4 List (java.util.List)3 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)3 HttpMessage (org.parosproxy.paros.network.HttpMessage)3 PipelineSelections (com.thoughtworks.go.server.domain.user.PipelineSelections)2 URI (java.net.URI)2 StatementProcessor (org.neo4j.bolt.v1.runtime.StatementProcessor)2 Uri (android.net.Uri)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CreatedRadiator (com.paulhammant.buildradiator.model.CreatedRadiator)1 IOException (java.io.IOException)1 ClassDefinition (java.lang.instrument.ClassDefinition)1 NoRouteToHostException (java.net.NoRouteToHostException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1