Search in sources :

Example 21 with BaseMatcher

use of org.hamcrest.BaseMatcher in project indy by Commonjava.

the class GroupDataManagerTCK method createAndRetrieveEmptyGroup.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void createAndRetrieveEmptyGroup() throws Exception {
    final Group grp = new Group("test");
    store(grp);
    final Group result = manager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).getByName(grp.getName());
    assertThat(result, notNullValue());
    assertThat(result.getName(), equalTo(grp.getName()));
    assertThat(result.getConstituents(), anyOf(nullValue(), new BaseMatcher<List>() {

        @Override
        public boolean matches(final Object item) {
            return (item instanceof List) && ((List) item).isEmpty();
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("empty list");
        }
    }));
}
Also used : Group(org.commonjava.indy.model.core.Group) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) List(java.util.List) Test(org.junit.Test)

Example 22 with BaseMatcher

use of org.hamcrest.BaseMatcher in project android_frameworks_base by DirtyUnicorns.

the class MockUtils method checkUserRestrictions.

public static Bundle checkUserRestrictions(String... keys) {
    final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys));
    final Matcher<Bundle> m = new BaseMatcher<Bundle>() {

        @Override
        public boolean matches(Object item) {
            if (item == null)
                return false;
            return UserRestrictionsUtils.areEqual((Bundle) item, expected);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("User restrictions=" + getRestrictionsAsString(expected));
        }
    };
    return Mockito.argThat(m);
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) Bundle(android.os.Bundle)

Example 23 with BaseMatcher

use of org.hamcrest.BaseMatcher in project android_frameworks_base by ResurrectionRemix.

the class MockUtils method checkUserRestrictions.

public static Bundle checkUserRestrictions(String... keys) {
    final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys));
    final Matcher<Bundle> m = new BaseMatcher<Bundle>() {

        @Override
        public boolean matches(Object item) {
            if (item == null)
                return false;
            return UserRestrictionsUtils.areEqual((Bundle) item, expected);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("User restrictions=" + getRestrictionsAsString(expected));
        }
    };
    return Mockito.argThat(m);
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) Bundle(android.os.Bundle)

Example 24 with BaseMatcher

use of org.hamcrest.BaseMatcher in project calcite-avatica by apache.

the class AbstractAvaticaHandlerTest method disallowUnauthenticatedUsers.

@Test
public void disallowUnauthenticatedUsers() throws Exception {
    ServletOutputStream os = mock(ServletOutputStream.class);
    when(config.getAuthenticationType()).thenReturn(AuthenticationType.SPNEGO);
    when(request.getRemoteUser()).thenReturn(null);
    when(response.getOutputStream()).thenReturn(os);
    assertFalse(handler.isUserPermitted(config, request, response));
    verify(response).setStatus(HttpURLConnection.HTTP_UNAUTHORIZED);
    // Make sure that the serialized ErrorMessage looks reasonable
    verify(os).write(argThat(new BaseMatcher<byte[]>() {

        @Override
        public void describeTo(Description description) {
            String desc = "A serialized ErrorMessage which contains 'User is not authenticated'";
            description.appendText(desc);
        }

        @Override
        public boolean matches(Object item) {
            String msg = new String((byte[]) item, StandardCharsets.UTF_8);
            return msg.contains("User is not authenticated");
        }

        @Override
        public void describeMismatch(Object item, Description mismatchDescription) {
            mismatchDescription.appendText("The message should contain 'User is not authenticated'");
        }
    }));
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) ServletOutputStream(javax.servlet.ServletOutputStream) Test(org.junit.Test)

Example 25 with BaseMatcher

use of org.hamcrest.BaseMatcher in project android_frameworks_base by crdroidandroid.

the class MockUtils method checkUserRestrictions.

public static Bundle checkUserRestrictions(String... keys) {
    final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys));
    final Matcher<Bundle> m = new BaseMatcher<Bundle>() {

        @Override
        public boolean matches(Object item) {
            if (item == null)
                return false;
            return UserRestrictionsUtils.areEqual((Bundle) item, expected);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("User restrictions=" + getRestrictionsAsString(expected));
        }
    };
    return Mockito.argThat(m);
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) Bundle(android.os.Bundle)

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