Search in sources :

Example 16 with TypeSafeMatcher

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));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) View(android.view.View)

Example 17 with TypeSafeMatcher

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));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 18 with TypeSafeMatcher

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;
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) LogRecord(java.util.logging.LogRecord) Level(java.util.logging.Level) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 19 with TypeSafeMatcher

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);
}
Also used : SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Shell(org.eclipse.swt.widgets.Shell) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)

Example 20 with TypeSafeMatcher

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");
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ObjectSchema(org.everit.json.schema.ObjectSchema)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)82 Description (org.hamcrest.Description)79 View (android.view.View)44 ViewParent (android.view.ViewParent)33 ViewGroup (android.view.ViewGroup)30 Espresso.onView (android.support.test.espresso.Espresso.onView)25 TextView (android.widget.TextView)9 Test (org.junit.Test)9 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)7 JsonNode (org.codehaus.jackson.JsonNode)6 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 HTTP (org.neo4j.test.server.HTTP)6 Resources (android.content.res.Resources)5 StringDescription (org.hamcrest.StringDescription)5 AdapterView (android.widget.AdapterView)4 RecyclerView (android.support.v7.widget.RecyclerView)3 Adapter (android.widget.Adapter)3 Espresso.onView (com.google.android.apps.common.testing.ui.espresso.Espresso.onView)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3