コード例 #1
0
 @Override
 public void describeMismatch(Object item, Description description) {
   if (!containsAll.matches(item)) {
     containsAll.describeMismatch(item, description);
   }
   if (!containsOnly.matches(item)) {
     containsOnly.describeMismatch(item, description);
   }
 }
コード例 #2
0
ファイル: IsJsonTest.java プロジェクト: jayway/JsonPath
 @Test
 public void shouldDescribeMismatchOfInvalidJson() {
   Matcher<Object> matcher = isJson(withPathEvaluatedTo(true));
   Description description = new StringDescription();
   matcher.describeMismatch("invalid-json", description);
   assertThat(description.toString(), containsString("\"invalid-json\""));
 }
コード例 #3
0
ファイル: IsJsonTest.java プロジェクト: jayway/JsonPath
 @Test
 public void shouldDescribeMismatchOfValidJson() {
   Matcher<Object> matcher = isJson(withPathEvaluatedTo(true));
   Description description = new StringDescription();
   matcher.describeMismatch(BOOKS_JSON_STRING, description);
   assertThat(description.toString(), containsString(TestingMatchers.MISMATCHED_TEXT));
 }
コード例 #4
0
ファイル: ObjectChecker.java プロジェクト: akune/immutables
 static void fail(@Nullable Object actualValue, Matcher<?> matcher) {
   Description description =
       new StringDescription()
           .appendText("\nExpected: ")
           .appendDescriptionOf(matcher)
           .appendText("\n     but: ");
   matcher.describeMismatch(actualValue, description);
   AssertionError assertionError = new AssertionError(description.toString());
   assertionError.setStackTrace(ObjectChecker.trimStackTrace(assertionError.getStackTrace()));
   throw assertionError;
 }
コード例 #5
0
  @Override
  public boolean matches(Object item) {
    try {
      if (item == null) {
        return matchingError("Guice injector is null");
      }

      if (!Injector.class.isAssignableFrom(item.getClass())) {
        return matchingError("Object " + item + " is not a Guice Injector");
      }

      T instance = ((Injector) item).getInstance(typeKey);

      if (instance == null) {
        return matchingError("Instance " + typeKey + " is null");
      }

      Class<?> instanceClass = instance.getClass();
      if (!expectedType.isAssignableFrom(instanceClass)) {
        return matchingError(
            "Instance "
                + typeKey
                + " type mismatch: expected "
                + expectedType
                + " but was "
                + ""
                + instanceClass);
      }

      if (!instanceMatcher.matches(instance)) {
        matcherDescription = new StringDescription();
        matcherDescription.appendText(
            "Instance " + typeKey + " does not match " + "expectations: ");
        instanceMatcher.describeMismatch(item, matcherDescription);
        return false;
      } else {
        return true;
      }
    } catch (ConfigurationException | ProvisionException ex) {
      return matchingError(
          "Cannot get instance of "
              + typeKey
              + " from Guice Injector\n"
              + ex.getMessage()
              + "\n\n"
              + "Error stack trace: \n"
              + "-------------------\n"
              + getStackTrace(ex));
    }
  }
コード例 #6
0
 private <T> String describeMismatch(Matcher<T> matcher, T object) {
   StringDescription description = new StringDescription();
   matcher.describeMismatch(object, description);
   return description.toString();
 }
コード例 #7
0
ファイル: DescribedAs.java プロジェクト: nelsonnan/hamcrest
 @Override
 public void describeMismatch(Object item, Description description) {
   matcher.describeMismatch(item, description);
 }
コード例 #8
0
 @Override
 protected void describeMismatchSafely(WrapsElement element, Description mismatchDescription) {
   matcher.describeMismatch(element, mismatchDescription);
 }
コード例 #9
0
 @Override
 public void diagnoseNotSatisfyingTo(
     Description dissatisfactionDescription, Item<E> item, Description notFoundDescription) {
   if (item.hasAmount()) matcher.describeMismatch(item.get(), dissatisfactionDescription);
   else Describer.concat(dissatisfactionDescription, notFoundDescription);
 }
コード例 #10
0
 private <S> String descriptionOf(Matcher<S> matcher, S value) {
   StringDescription description = new StringDescription();
   matcher.describeMismatch(value, description);
   return description.toString();
 }