@Override
 public void describeMismatch(Object item, Description description) {
   if (!containsAll.matches(item)) {
     containsAll.describeMismatch(item, description);
   }
   if (!containsOnly.matches(item)) {
     containsOnly.describeMismatch(item, description);
   }
 }
Example #2
0
 @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\""));
 }
Example #3
0
 @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));
 }
Example #4
0
 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;
 }
  @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));
    }
  }
 private <T> String describeMismatch(Matcher<T> matcher, T object) {
   StringDescription description = new StringDescription();
   matcher.describeMismatch(object, description);
   return description.toString();
 }
Example #7
0
 @Override
 public void describeMismatch(Object item, Description description) {
   matcher.describeMismatch(item, description);
 }
 @Override
 protected void describeMismatchSafely(WrapsElement element, Description mismatchDescription) {
   matcher.describeMismatch(element, mismatchDescription);
 }
 @Override
 public void diagnoseNotSatisfyingTo(
     Description dissatisfactionDescription, Item<E> item, Description notFoundDescription) {
   if (item.hasAmount()) matcher.describeMismatch(item.get(), dissatisfactionDescription);
   else Describer.concat(dissatisfactionDescription, notFoundDescription);
 }
Example #10
0
 private <S> String descriptionOf(Matcher<S> matcher, S value) {
   StringDescription description = new StringDescription();
   matcher.describeMismatch(value, description);
   return description.toString();
 }