Java Code Examples for org.hamcrest.StringDescription

Following code examples demonstrate how to use org.hamcrest.StringDescriptionfrom 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.StringDescriptionand various code implementation of this class.

  
  public StringBuffer describeTo(StringBuffer buffer)
  {
    hamcrestMatcher.describeTo(new StringDescription(buffer));
    return buffer;
  } 


    public static <T> void checkMatch(String reason, T actual, Matcher<? super T> matcher, MismatchAction action) {
        if (!matcher.matches(actual)) {
            Description description = new StringDescription();
            description.appendText(reason)
                       .appendText("\nExpected: ")
                       .appendDescriptionOf(matcher)
                       .appendText("\n     but: ");
            matcher.describeMismatch(actual, description);
            
            action.mismatch(description.toString());
        }
    } 

  static <T> String mismatchDescriptionOf(Matcher<? super T> matcher, T value) {
    StringDescription description = new StringDescription();
    matcher.describeMismatch(value, description);
    return description.toString();
  } 

  static String descriptionOf(Matcher<?> matcher) {
    StringDescription description = new StringDescription();
    matcher.describeTo(description);
    return description.toString();
  } 

    public static <T> Function1<T, String> describeMismatch(final Matcher<? super T> matcher) {
        if (matcher instanceof DiagnosingMatcher)
            return diagnoseMismatch((DiagnosingMatcher) matcher);
        return returns1(StringDescription.asString(matcher));
    } 

  public void test4()  throws Throwable  {
      Same same0 = new Same("");
      StringDescription stringDescription0 = new StringDescription();
      Object[] objectArray0 = new Object[8];
      objectArray0[2] = (Object) same0;
      Description description0 = stringDescription0.appendValueList("", "", "", objectArray0);
      assertSame(description0, stringDescription0);
  } 

   }

   public void describe(final StringDescription stringDescription)
   {
      stringDescription.appendValue(string);
   } 

    public static String describe( final Matcher<?> matcher ) {
        final Description description = new StringDescription( );
        matcher.describeTo( description );
        return description.toString( );
    } 

    public static <T> String describeMismatch( final Matcher<? super T> matcher, final T item ) {
        final Description description = new StringDescription( );
        matcher.describeMismatch( item, description );
        return description.toString( );
    } 

    public String buildError(T actual, M matcher) {
        final StringDescription descriptionBuilder = new StringDescription();
        descriptionBuilder.appendText("Expected ").appendText(name).appendText(" ");
        matcher.describeTo(descriptionBuilder);
        descriptionBuilder.appendText(" but ");
        matcher.describeMismatch(actual, descriptionBuilder);

        final String description = descriptionBuilder.toString().replaceAll("[.\\n]+$", "");
        return description + ".\n";
    } 

    public static <T> void checkThat(T actual, Matcher<? super T> matcher) {
        if(!verifyThat(actual, matcher)){
            Description description = new StringDescription();
            description.appendText("Expected: ")
                .appendDescriptionOf(matcher)
                .appendText("\n     but: ");
            matcher.describeMismatch(actual, description);

            throw new IllegalStateException(description.toString() );
        }
    } 

    public static <T> String mismatchOf(T mismatch, Matcher<? super T> matcher) {
        Description mismatchDescription = new StringDescription();
        matcher.describeMismatch(mismatch, mismatchDescription);
        return mismatchDescription.toString();
    } 

Advertisement
Javadoc
A Description that is stored as a string.
Advertisement