use of org.hamcrest.TypeSafeDiagnosingMatcher in project hippo by NHS-digital-website.
the class ImagePairSection method getMatcher.
public Matcher<? super SectionWidget> getMatcher() {
return new TypeSafeDiagnosingMatcher<SectionWidget>(ImagePairSectionWidget.class) {
@Override
protected boolean matchesSafely(SectionWidget item, Description desc) {
ImagePairSectionWidget widget = (ImagePairSectionWidget) item;
List<ImageSectionWidget> imageSectionWidgets = widget.getImageSectionWidgets();
// pad with nulls for the 2 slots we could have had images in
while (imageSectionWidgets.size() < 2) {
imageSectionWidgets.add(null);
}
return compare(first.getMatcher(), imageSectionWidgets.get(0), desc) && compare(second == null ? nullValue() : second.getMatcher(), imageSectionWidgets.get(1), desc);
}
@Override
public void describeTo(Description description) {
description.appendValue(ImagePairSection.this);
}
};
}
use of org.hamcrest.TypeSafeDiagnosingMatcher in project microservice_framework by CJSCommonPlatform.
the class JsonSchemaValidationMatcher method isValidJsonEnvelopeForSchema.
/**
* Validates a JsonEnvelope against the correct schema for the action name provided in the
* metadata. Expects to find the schema on the class path in package
* 'json/schema/{action.name}.json' or 'raml/json/schema/{action.name}.json'.
*
* @return matcher
*/
public static Matcher<JsonEnvelope> isValidJsonEnvelopeForSchema() {
return new TypeSafeDiagnosingMatcher<JsonEnvelope>() {
private ValidationException validationException = null;
@Override
protected boolean matchesSafely(final JsonEnvelope jsonEnvelope, final Description description) {
if (null == validationException) {
try {
final String pathToJsonSchema = format(JSON_SCHEMA_TEMPLATE, jsonEnvelope.metadata().name());
getJsonSchemaFor(pathToJsonSchema).validate(new JSONObject(jsonEnvelope.payloadAsJsonObject().toString()));
} catch (final IllegalArgumentException | IOException e) {
try {
final String pathToJsonSchema = format(RAML_JSON_SCHEMA_TEMPLATE, jsonEnvelope.metadata().name());
getJsonSchemaFor(pathToJsonSchema).validate(new JSONObject(jsonEnvelope.payloadAsJsonObject().toString()));
} catch (final IOException ioe) {
throw new IllegalArgumentException(ioe);
}
} catch (final ValidationException e) {
validationException = e;
return false;
}
return true;
} else {
description.appendText("Schema validation failed with message: ").appendValue(validationException.getMessage());
return false;
}
}
@Override
public void describeTo(final Description description) {
description.appendText("JsonEnvelope validated against schema found on classpath at 'raml/json/schema/' ");
}
};
}
use of org.hamcrest.TypeSafeDiagnosingMatcher in project atlasdb by palantir.
the class CassandraSchemaLockTest method doesNotContainTheColumnFamilyIdMismatchError.
private static Matcher<File> doesNotContainTheColumnFamilyIdMismatchError() {
return new TypeSafeDiagnosingMatcher<File>() {
@Override
protected boolean matchesSafely(File file, Description mismatchDescription) {
Path path = Paths.get(file.getAbsolutePath());
try (Stream<String> lines = Files.lines(path, StandardCharsets.ISO_8859_1)) {
List<String> badLines = lines.filter(line -> line.contains("Column family ID mismatch")).collect(Collectors.toList());
mismatchDescription.appendText("file called " + file.getAbsolutePath() + " which contains lines").appendValueList("\n", "\n", "", badLines);
return badLines.isEmpty();
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
@Override
public void describeTo(Description description) {
description.appendText("a file with no column family ID mismatch errors");
}
};
}
use of org.hamcrest.TypeSafeDiagnosingMatcher in project flink by apache.
the class SavepointITCase method hasEntropyInFileStateHandlePaths.
private static Matcher<File> hasEntropyInFileStateHandlePaths() {
return new TypeSafeDiagnosingMatcher<File>() {
@Override
protected boolean matchesSafely(final File savepointDir, final Description mismatchDescription) {
if (savepointDir == null) {
mismatchDescription.appendText("savepoint dir must not be null");
return false;
}
final List<Path> filesWithoutEntropy = listRecursively(savepointDir.toPath().resolve(EntropyInjectingTestFileSystem.ENTROPY_INJECTION_KEY));
final Path savepointDirWithEntropy = savepointDir.toPath().resolve(EntropyInjectingTestFileSystem.ENTROPY);
final List<Path> filesWithEntropy = listRecursively(savepointDirWithEntropy);
if (!filesWithoutEntropy.isEmpty()) {
mismatchDescription.appendText("there are savepoint files with unresolved entropy placeholders");
return false;
}
if (!Files.exists(savepointDirWithEntropy) || filesWithEntropy.isEmpty()) {
mismatchDescription.appendText("there are no savepoint files with added entropy");
return false;
}
return true;
}
@Override
public void describeTo(final Description description) {
description.appendText("all savepoint files should have added entropy");
}
};
}
Aggregations