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\""));
}
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) {
}
};
}
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");
}
};
}
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"));
}
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));
}
Aggregations