use of org.hamcrest.TypeSafeMatcher in project ARD by MobileApplicationsClub.
the class THC method childAtPosition.
public static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
use of org.hamcrest.TypeSafeMatcher in project AndelaMedManager by jumaallan.
the class AuthActivityTest method childAtPosition.
private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
use of org.hamcrest.TypeSafeMatcher in project vsphere-cloud-plugin by jenkinsci.
the class CloudProvisioningStateTest method logMessage.
private static Matcher<LogRecord> logMessage(final Matcher<String> messageMatcher, final Level expectedLevel, final Object... expectedArgs) {
final Matcher<Level> levelMatcher = equalTo(expectedLevel);
final Matcher<Object[]> parametersMatcher = arrayContaining(expectedArgs);
final Matcher<LogRecord> itemMatcher = new TypeSafeMatcher<LogRecord>(LogRecord.class) {
@Override
public boolean matchesSafely(LogRecord actual) {
final String actualMessage = actual.getMessage();
final Level actualLevel = actual.getLevel();
final Object[] actualParameters = actual.getParameters();
return messageMatcher.matches(actualMessage) && levelMatcher.matches(actualLevel) && parametersMatcher.matches(actualParameters);
}
@Override
public void describeTo(Description description) {
description.appendText("LogRecord(");
description.appendText("message ").appendDescriptionOf(messageMatcher);
description.appendText(" && level ").appendDescriptionOf(levelMatcher);
description.appendText(" && parameters ").appendDescriptionOf(parametersMatcher);
description.appendText(")");
}
@Override
protected void describeMismatchSafely(LogRecord actual, Description description) {
final String actualMessage = actual.getMessage();
final Level actualLevel = actual.getLevel();
final Object[] actualParameters = actual.getParameters();
description.appendText("was LogRecord(");
description.appendText("message=\"").appendValue(actualMessage);
description.appendText("\", level ").appendValue(actualLevel);
description.appendText(", parameters ").appendValueList("[", ",", "]", actualParameters);
description.appendText(")");
}
};
return itemMatcher;
}
use of org.hamcrest.TypeSafeMatcher in project egit by eclipse.
the class TestUtil method botForShellStartingWith.
public static SWTBotShell botForShellStartingWith(final String titlePrefix) {
SWTWorkbenchBot bot = new SWTWorkbenchBot();
Matcher<Shell> matcher = new TypeSafeMatcher<Shell>() {
@Override
protected boolean matchesSafely(Shell item) {
String title = item.getText();
return title != null && title.startsWith(titlePrefix);
}
@Override
public void describeTo(Description description) {
description.appendText("Shell with title starting with '" + titlePrefix + "'");
}
};
Shell shell = bot.widget(matcher);
return new SWTBotShell(shell);
}
use of org.hamcrest.TypeSafeMatcher in project microservice_framework by CJSCommonPlatform.
the class JsonSchemaPropertyMatcher method hasRequiredProperty.
/**
* Matcher to validate if a given property is a required (non-optional) property in the given json schema
*
* @param jsonpathToRequiredProperty json path of the property that should be a required property in the schema (i.e. case.offences.offenceId)
* @return matcher
*/
public static Matcher<String> hasRequiredProperty(final String jsonpathToRequiredProperty) {
return new TypeSafeMatcher<String>() {
private String pathToJsonFile = null;
@Override
protected boolean matchesSafely(final String pathToJsonFile) {
this.pathToJsonFile = pathToJsonFile;
final JsonPath jsonPath = JsonPath.of(jsonpathToRequiredProperty);
final ObjectSchema parentObjectSchema = getObjectSchemaFromFile(pathToJsonFile);
return getObjectSchemaWithPath(parentObjectSchema, jsonPath).getRequiredProperties().contains(jsonPath.getProperty());
}
@Override
public void describeTo(final Description description) {
description.appendText("property ").appendValue(jsonpathToRequiredProperty).appendText(" should be a required property in JSON Schema ").appendValue(pathToJsonFile);
}
@Override
protected void describeMismatchSafely(final String pathToJsonFile, final Description mismatchDescription) {
mismatchDescription.appendText("property ").appendValue(jsonpathToRequiredProperty).appendText(" is not a required property");
}
};
}
Aggregations