Java Code Examples for org.hamcrest.Description#appendValue()

The following examples show how to use org.hamcrest.Description#appendValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EspRecyclerViewMatcher.java    From espresso-macchiato with MIT License 6 votes vote down vote up
public static Matcher<View> withMinimalAdapterItemCount(final int minimalCount) {
    return new TypeSafeMatcher<View>() {

        @Override
        protected boolean matchesSafely(View item) {
            //noinspection SimplifiableIfStatement - for more readable code
            if (!(item instanceof RecyclerView)) {
                return false;
            }
            return ((RecyclerView) item).getAdapter().getItemCount() >= minimalCount;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Adapter has minimal ");
            description.appendValue(minimalCount);
            description.appendText(" items (to access requested index ");
            description.appendValue(minimalCount - 1);
            description.appendText(")");
        }
    };
}
 
Example 2
Source File: FloatLabelMatchers.java    From AndroidFloatLabel with Apache License 2.0 5 votes vote down vote up
/**
 * @param floatLabelHint
 * @return View Matcher for the child EditText
 */
public static Matcher<View> withFloatLabelHint(final String floatLabelHint) {
    return new BoundedMatcher<View, EditText>(EditText.class) {

        @Override
        public void describeTo(Description description) {
            description.appendText("has floatlabel hint ");
            description.appendValue(floatLabelHint);

            if (null != floatLabelHint) {
                description.appendText("[");
                description.appendText(floatLabelHint);
                description.appendText("]");
            }

            if (null != floatLabelHint) {
                description.appendText(" value: ");
                description.appendText(floatLabelHint);
            }
        }

        @Override
        protected boolean matchesSafely(EditText editText) {
            if (!(editText instanceof EditText)) {
                return false;
            }

            String hint = ((EditText) editText).getHint().toString();

            return floatLabelHint.equals(hint);
        }
    };
}
 
Example 3
Source File: TtlValueMatchers.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean matchesSafely(TtlValue<T> item, Description mismatchDescription) {
	mismatchDescription.appendText("TtlValue with value ");
	mismatchDescription.appendValue(item.getUserValue());
	mismatchDescription.appendText(" with timestamp ");
	mismatchDescription.appendValue(item.getLastAccessTimestamp());
	return valueMatcher.matches(item.getUserValue()) &&
			timestampMatcher.matches(item.getLastAccessTimestamp());
}
 
Example 4
Source File: JSONMatcher.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void describeTo(final Description description) {
    try {
        Object expectedJsonAsPrettyJson = JSONParser.parseJSON(expectedJson);
        description.appendValue(expectedJsonAsPrettyJson);
    } catch (final JSONException e) {
        throw new RuntimeException(String.format("Error parsing expected JSON string %s. Got Exception %s",
                                                 expectedJson, e.toString()));
    }
}
 
Example 5
Source File: IsOptional.java    From jtwig-core with Apache License 2.0 5 votes vote down vote up
@Override
public void describeTo(Description description) {
    if (!someExpected) {
        description.appendText("<Absent>");
    } else if (expected.isPresent()) {
        description.appendValue(expected);// "a Some with " +
        // expected.some());
    } else if (matcher.isPresent()) {
        description.appendText("a present value matching ");
        matcher.get().describeTo(description);
    } else {
        description.appendText("<Present>");
    }
}
 
Example 6
Source File: Invoice_Test.java    From estatio with Apache License 2.0 5 votes vote down vote up
private Matcher<InvoiceAttributesVM> viewModelFor(final InvoiceForLease invoice) {
    return new TypeSafeMatcher<InvoiceAttributesVM>() {
        @Override protected boolean matchesSafely(final InvoiceAttributesVM invoiceAttributesVM) {
            return invoiceAttributesVM.getInvoice() == invoice;
        }

        @Override public void describeTo(final Description description) {
            description.appendValue("is view model wrapping " + invoice);
        }
    };
}
 
Example 7
Source File: FileContainsLines.java    From tool.accelerate.core with Apache License 2.0 5 votes vote down vote up
@Override
public void describeMismatch(Object file, Description description) {
    List<String> lines = readLinesSafely(file, description);
    if (lines != null) {
        lineMatchingDelegate.describeMismatch(lines, description);
        description.appendText(" in file ");
        description.appendValue(file);
        description.appendText(" with lines ");
        description.appendValue(readLinesSafely(file, Description.NONE));
    }
}
 
Example 8
Source File: TrySuccessMatcher.java    From vics with MIT License 5 votes vote down vote up
@Override
protected void describeMismatchSafely(Try<S> item, Description mismatchDescription) {
    mismatchDescription.appendText(DESCRIPTION);
    if (item.isSuccess()) {
        mismatchDescription.appendValue(item.get());
    } else {
        mismatchDescription.appendText(" but was a Try failure");
    }
}
 
Example 9
Source File: EntryEncodingUtilTest.java    From c5-replicator with Apache License 2.0 5 votes vote down vote up
private static Matcher<OLogEntryHeader> theSameMessageAs(OLogEntryHeader message) {
  return new TypeSafeMatcher<OLogEntryHeader>() {
    @Override
    public boolean matchesSafely(OLogEntryHeader item) {
      return message.getSeqNum() == item.getSeqNum()
          && message.getTerm() == item.getTerm()
          && message.getContentLength() == item.getContentLength();
    }

    @Override
    public void describeTo(Description description) {
      description.appendValue(message);
    }
  };
}
 
Example 10
Source File: IgnoreFilePatternTest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public void describeMismatch(Object item, Description description) {
    description.appendText("was ");
    if (!(item instanceof IgnoreFilePattern.PathNameMatchResult)) {
        description.appendValue(item);
    } else {
        IgnoreFilePattern.PathNameMatchResult res = (IgnoreFilePattern.PathNameMatchResult) item;
        description.appendText("isMatch? ").appendValue(res.isMatch)
                .appendText(" requiresMore? ").appendValue(res.requiresMore)
                .appendText(" isLast? ").appendValue(res.isLastElementMatch)
                .appendText(" next ").appendValue(res.next);
    }
}
 
Example 11
Source File: DrawableMatcher.java    From droidcon-android-espresso with Apache License 2.0 5 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendText("with drawable from resource id: ");
    description.appendValue(resourceId);
    if (resourceName != null) {
        description.appendText("[");
        description.appendText(resourceName);
        description.appendText("]");
    }
}
 
Example 12
Source File: SameJsonAsMatcher.java    From confluence-publisher with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendValue(this.expectedJson);
}
 
Example 13
Source File: FutureActions.java    From c5-replicator with Apache License 2.0 4 votes vote down vote up
public void describeTo(Description description) {
  description.appendText("returns a future with exception ");
  description.appendValue(exception);
}
 
Example 14
Source File: BinaryHeapQueueTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void describeTo(Description description) {
    description.appendValue( expected );
}
 
Example 15
Source File: FutureActions.java    From c5-replicator with Apache License 2.0 4 votes vote down vote up
public void describeTo(Description description) {
  description.appendText("returns a future with value ");
  description.appendValue(futureResult);
}
 
Example 16
Source File: JenkinsMatchers.java    From jenkins-test-harness with MIT License 4 votes vote down vote up
public void describeTo(Description description) {
    description.appendText("follows the hashCode contract when compared to ");
    description.appendValue(other);
}
 
Example 17
Source File: DeserializationSchemaMatcher.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
	description.appendValue(expected);
}
 
Example 18
Source File: JenkinsMatchers.java    From jenkins-test-harness with MIT License 4 votes vote down vote up
public void describeTo(Description description) {
    description.appendText("has a symmetric equals(Object) method with ");
    description.appendValue(other);
}
 
Example 19
Source File: ViewMinSizeMatcher.java    From prebid-mobile-android with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendText("with MinSizeMatcher: ");
    description.appendValue(expectedMinWith + "x" + expectedMinHeight);
}
 
Example 20
Source File: IsReserializable.java    From concurrentlinkedhashmap with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
  description.appendValue("serialized clone");
}