Search in sources :

Example 46 with Description

use of org.hamcrest.Description in project cactoos by yegor256.

the class TextHasStringTest method hasClearDescriptionForFailedTest.

@Test
public void hasClearDescriptionForFailedTest() throws Exception {
    final HexOf hex = new HexOf(new Md5DigestOf(new InputOf("Hello World!")));
    final Description description = new StringDescription();
    final TextHasString matcher = new TextHasString("ed076287532e86365e841e92bfc50d8c6");
    matcher.matchesSafely(hex);
    matcher.describeMismatchSafely(hex, description);
    MatcherAssert.assertThat("Description is not clear ", description.toString(), new StringContains("Text with \"ed076287532e86365e841e92bfc50d8c\""));
}
Also used : Md5DigestOf(org.cactoos.io.Md5DigestOf) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) HexOf(org.cactoos.text.HexOf) StringDescription(org.hamcrest.StringDescription) InputOf(org.cactoos.io.InputOf) StringContains(org.hamcrest.core.StringContains) Test(org.junit.Test)

Example 47 with Description

use of org.hamcrest.Description in project gocd by gocd.

the class PipelineSelectionsServiceTest method isAPipelineSelectionsInstanceWith.

private Matcher<PipelineSelections> isAPipelineSelectionsInstanceWith(final boolean isBlacklist, final String... pipelineSelectionsInInstance) {
    return new BaseMatcher<PipelineSelections>() {

        public boolean matches(Object o) {
            PipelineSelections pipelineSelections = (PipelineSelections) o;
            assertThat(pipelineSelections.isBlacklist(), is(isBlacklist));
            List<String> expectedSelectionsAsList = Arrays.asList(pipelineSelectionsInInstance);
            assertEquals(pipelineSelections.getSelections(), StringUtils.join(expectedSelectionsAsList, ","));
            return true;
        }

        public void describeTo(Description description) {
        }
    };
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher)

Example 48 with Description

use of org.hamcrest.Description in project gocd by gocd.

the class RemoteRegistrationRequesterTest method hasAllParams.

private TypeSafeMatcher<HttpRequestBase> hasAllParams(final String uuid, final String elasticAgentId, final String elasticPluginId) {
    return new TypeSafeMatcher<HttpRequestBase>() {

        @Override
        public boolean matchesSafely(HttpRequestBase item) {
            try {
                HttpEntityEnclosingRequestBase postMethod = (HttpEntityEnclosingRequestBase) item;
                List<NameValuePair> params = URLEncodedUtils.parse(postMethod.getEntity());
                assertThat(getParameter(params, "hostname"), is("cruise.com"));
                assertThat(getParameter(params, "uuid"), is(uuid));
                String workingDir = SystemUtil.currentWorkingDirectory();
                assertThat(getParameter(params, "location"), is(workingDir));
                assertThat(getParameter(params, "operatingSystem"), not(nullValue()));
                assertThat(getParameter(params, "agentAutoRegisterKey"), is("t0ps3cret"));
                assertThat(getParameter(params, "agentAutoRegisterResources"), is("linux, java"));
                assertThat(getParameter(params, "agentAutoRegisterEnvironments"), is("uat, staging"));
                assertThat(getParameter(params, "agentAutoRegisterHostname"), is("agent01.example.com"));
                assertThat(getParameter(params, "elasticAgentId"), is(elasticAgentId));
                assertThat(getParameter(params, "elasticPluginId"), is(elasticPluginId));
                assertThat(getParameter(params, "token"), is("token-from-server"));
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        private String getParameter(List<NameValuePair> params, String paramName) {
            for (NameValuePair param : params) {
                if (param.getName().equals(paramName)) {
                    return param.getValue();
                }
            }
            return null;
        }

        public void describeTo(Description description) {
            description.appendText("params containing");
        }
    };
}
Also used : NameValuePair(org.apache.http.NameValuePair) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) List(java.util.List) IOException(java.io.IOException)

Example 49 with Description

use of org.hamcrest.Description in project JsonPath by jayway.

the class IsJsonFileTest method shouldDescribeMismatchOfInvalidJson.

@Test
public void shouldDescribeMismatchOfInvalidJson() {
    Matcher<File> matcher = isJsonFile(withPathEvaluatedTo(true));
    Description description = new StringDescription();
    matcher.describeMismatch(INVALID_JSON, description);
    assertThat(description.toString(), containsString("invalid.json"));
    assertThat(description.toString(), containsString("invalid-json"));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) File(java.io.File) JsonPathMatchers.isJsonFile(com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile) ResourceHelpers.resourceAsFile(com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile) Test(org.junit.Test)

Example 50 with Description

use of org.hamcrest.Description in project JsonPath by jayway.

the class IsJsonFileTest method shouldBeDescriptive.

@Test
public void shouldBeDescriptive() {
    Matcher<File> matcher = isJsonFile(withPathEvaluatedTo(true));
    Description description = new StringDescription();
    matcher.describeTo(description);
    assertThat(description.toString(), startsWith("is json"));
    assertThat(description.toString(), containsString(MATCH_TRUE_TEXT));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) File(java.io.File) JsonPathMatchers.isJsonFile(com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile) ResourceHelpers.resourceAsFile(com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile) Test(org.junit.Test)

Aggregations

Description (org.hamcrest.Description)122 Test (org.junit.Test)38 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)29 BaseMatcher (org.hamcrest.BaseMatcher)27 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6