-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Add a matcher for validating mime-types, e. g. (here: inner class):
private static class IsValidMimeType extends CustomTypeSafeMatcher<String> {
private final String defaultMimeType;
private IsValidMimeType(final String defaultMimeType) {
super("valid mimetype");
this.defaultMimeType = defaultMimeType;
}
@Override
protected void describeMismatchSafely(final String item, final Description mismatchDescription) {
super.describeMismatchSafely(item, mismatchDescription);
mismatchDescription.appendText("raising ");
try {
new MimeType(item);
} catch (MimeTypeParseException e) {
mismatchDescription.appendValue(e);
}
}
@Override
protected boolean matchesSafely(final String item) {
try {
new MimeType(defaultMimeType);
} catch (MimeTypeParseException ignored) {
return false;
}
return true;
}
}