Java Code Examples for org.hamcrest.Description

Following code examples demonstrate how to use org.hamcrest.Descriptionfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.hamcrest.Descriptionand various code implementation of this class.

	public void describeTo(Description description) {
		description.appendText(" uma celula contendo ")
				.appendValue(esperado);
	} 


	protected void describeMismatchSafely(Cell cell, Description mismatchDescription) {
		mismatchDescription
			.appendText(" uma celula com ")
			.appendValue(extrator.extrairConteudo(cell));
	} 

    public final boolean matches(Object item, Description mismatch) {
        if (matches(item)) {
            return true;
        } else {
            describeMismatch(item, mismatch);
            return false;
        }
    } 

            public void describeTo(org.hamcrest.Description description) {
                description.appendText("has ");
                description.appendValue(numberOfFailures);
                description.appendText(" failures");
            } 

    }

    static Matcher<EventCollector> hasSingleFailureWithMessage(
            final Matcher<String> messageMatcher) {
        return new TypeSafeMatcher<EventCollector>() {
            @Override
            public boolean matchesSafely(EventCollector item) {
                return hasSingleFailure().matches(item)
                        && messageMatcher.matches(item.fFailures.get(0)
                        .getMessage());
            }

            public void describeTo(org.hamcrest.Description description) {
                description.appendText("has single failure with message ");
                messageMatcher.describeTo(description);
            }

            @Override
            protected void describeMismatchSafely(EventCollector item,
                    org.hamcrest.Description description) {
                description.appendText("was ");
                hasSingleFailure().describeMismatch(item, description);
                description.appendText(": ");
                boolean first= true;
                for (Failure f : item.fFailures) {
                    if (!first) {
                        description.appendText(" ,");
                    }
                    description.appendText("'");
                    description.appendText(f.getMessage());
                    description.appendText("'");
                    first= false;
                }
            }
        };
    } 

    }

    private static Matcher<EventCollector> hasNumberOfAssumptionFailures(
            final int numberOfFailures) {
        return new TypeSafeMatcher<EventCollector>() {
            @Override
            public boolean matchesSafely(EventCollector item) {
                return item.fAssumptionFailures.size() == numberOfFailures;
            }

            public void describeTo(org.hamcrest.Description description) {
                description.appendText("has ");
                description.appendValue(numberOfFailures);
                description.appendText(" assumption failures");
            }
        };
    } 

            @Override
            protected void describeMismatchSafely(EventCollector item,
                    org.hamcrest.Description description) {
                description.appendValue(item.fFailures.size());
                description.appendText(" failures");
            } 

    static Matcher<EventCollector> failureIs(final Matcher<? super Throwable> exceptionMatcher) {
        return new TypeSafeMatcher<EventCollector>() {
            @Override
            public boolean matchesSafely(EventCollector item) {
                for (Failure f : item.fFailures) {
                    return exceptionMatcher.matches(f.getException());
                }
                return false;
            }

            public void describeTo(org.hamcrest.Description description) {
                description.appendText("failure is ");
                exceptionMatcher.describeTo(description);
            }
        };
    } 

    private List<Description> finishedTests() {
        final ArgumentCaptor<Description> captor =
                ArgumentCaptor.forClass(Description.class);
        Mockito.verify(notifier, atLeastOnce())
                .fireTestFinished(captor.capture());
        return captor.getAllValues();
    } 

    protected Matcher<Description> hasDisplayName(final String displayName) {
        return new TypeSafeMatcher<Description>() {
            @Override
            protected boolean matchesSafely(Description item) {
                return displayName.equals(item.getDisplayName()
                        .replaceAll("\\(.*\\)$", ""));
            }

            @Override
            public void describeTo(org.hamcrest.Description description) {
                description.appendText("a Description with displayName=");
                description.appendValue(displayName);
            }

            @Override
            protected void describeMismatchSafely(Description item,
                                                  org.hamcrest.Description mismatchDescription) {
                mismatchDescription.appendText("displayName was ");
                mismatchDescription.appendValue(item.getDisplayName());
            }
        };
    } 

    private List<Description> startedTests() {
        final ArgumentCaptor<Description> captor =
                ArgumentCaptor.forClass(Description.class);
        Mockito.verify(notifier, atLeastOnce())
                .fireTestStarted(captor.capture());
        return captor.getAllValues();
    } 

Advertisement
Javadoc
A description of a Matcher. A Matcher will describe itself to a description which can later be used

for reporting. @see Matcher#describeTo(Description)

Read More
Advertisement