Search in sources :

Example 51 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project linkki by linkki-framework.

the class OkCancelDialogTest method displayingMessage.

private Matcher<OkCancelDialog> displayingMessage(String text) {
    return new TypeSafeMatcher<OkCancelDialog>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("an OkCancelDialog displaying a message with the text '");
            description.appendText(text);
            description.appendText("'");
        }

        @Override
        protected boolean matchesSafely(OkCancelDialog dialog) {
            @NonNull HorizontalLayout layout = dialog.getButtonArea();
            LinkkiText message = (LinkkiText) layout.getComponentAt(0);
            return text.contentEquals(message.getText());
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) LinkkiText(org.linkki.core.vaadin.component.base.LinkkiText) NonNull(edu.umd.cs.findbugs.annotations.NonNull) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 52 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project firefox-tv by mozilla-mobile.

the class PinTileTests 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) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView) RootMatchers.withDecorView(androidx.test.espresso.matcher.RootMatchers.withDecorView)

Example 53 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 54 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project goodies by sonatype.

the class FileMatchers method containsEntry.

public static Matcher<ZipFile> containsEntry(final String entryName) {
    return new TypeSafeMatcher<ZipFile>() {

        @Override
        protected boolean matchesSafely(ZipFile item) {
            Enumeration<? extends ZipEntry> entries = item.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.getName().equals(entryName)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("zip archive contains entry named ");
            description.appendValue(entryName);
        }

        @Override
        protected void describeMismatchSafely(ZipFile item, Description mismatchDescription) {
            mismatchDescription.appendText(" archive contained these entries:\n");
            Enumeration<? extends ZipEntry> entries = item.entries();
            while (entries.hasMoreElements()) {
                mismatchDescription.appendValue(entries.nextElement().getName());
                if (entries.hasMoreElements()) {
                    mismatchDescription.appendText("\n");
                }
            }
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry)

Example 55 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project data-access by pentaho.

the class DatasourceResourceIT method testImportZipFile.

private void testImportZipFile(String filePath, final String expectedSchemaName, boolean annotated) throws Exception {
    FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
    File f = new File(filePath);
    when(schemaFileInfo.getFileName()).thenReturn(f.getName());
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    if (annotated) {
        mockery.checking(new Expectations() {

            {
                exactly(2).of(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                    public boolean matchesSafely(IPlatformImportBundle bundle) {
                        return true;
                    }

                    public void describeTo(Description description) {
                        description.appendText("bundle with zipped mondrian schema");
                    }
                })));
            }
        });
    } else {
        mockery.checking(new Expectations() {

            {
                oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                    public boolean matchesSafely(IPlatformImportBundle bundle) {
                        return bundle.getProperty("domain-id").equals(expectedSchemaName);
                    }

                    public void describeTo(Description description) {
                        description.appendText("bundle with zipped mondrian schema");
                    }
                })));
            }
        });
    }
    AnalysisService service = new AnalysisService();
    FileInputStream in = new FileInputStream(filePath);
    try {
        service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
        mockery.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)141 Description (org.hamcrest.Description)136 View (android.view.View)72 ViewParent (android.view.ViewParent)49 ViewGroup (android.view.ViewGroup)47 Espresso.onView (android.support.test.espresso.Espresso.onView)26 Espresso.onView (androidx.test.espresso.Espresso.onView)17 Test (org.junit.Test)11 Resources (android.content.res.Resources)10 TextView (android.widget.TextView)10 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 ViewMatchers.withContentDescription (androidx.test.espresso.matcher.ViewMatchers.withContentDescription)8 ArrayList (java.util.ArrayList)6 JsonNode (org.codehaus.jackson.JsonNode)6 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 HTTP (org.neo4j.test.server.HTTP)6 List (java.util.List)5 Matcher (org.hamcrest.Matcher)5 StringDescription (org.hamcrest.StringDescription)5