/**
  * メッセージの構築。 期待値をDateに変換してメッセージに追加する。(時間部分は差分として出ちゃうけど、めんどいのでこの辺は適当)
  *
  * @param description
  */
 public void describeTo(Description description) {
   if (expected == null) {
     description.appendText(expected);
   } else {
     description.appendValue(expectedDate);
   }
 }
Esempio n. 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\""));
 }
 /**
  * Matches the contents of a mod ODU singal Id instruction.
  *
  * @param instructionJson JSON instruction to match
  * @param description Description object used for recording errors
  * @return true if contents matches, false otherwise
  */
 private boolean matchModOduSingalIdInstruction(
     JsonNode instructionJson, Description description) {
   ModOduSignalIdInstruction instructionToMatch = (ModOduSignalIdInstruction) instruction;
   String jsonSubType = instructionJson.get("subtype").textValue();
   if (!instructionToMatch.subtype().name().equals(jsonSubType)) {
     description.appendText("subtype was " + jsonSubType);
     return false;
   }
   String jsonType = instructionJson.get("type").textValue();
   if (!instructionToMatch.type().name().equals(jsonType)) {
     description.appendText("type was " + jsonType);
     return false;
   }
   final JsonNode jsonOduSignal = instructionJson.get("oduSignalId");
   int jsonTpn = jsonOduSignal.get("tributaryPortNumber").intValue();
   int jsonTsLen = jsonOduSignal.get("tributarySlotLength").intValue();
   byte[] tributaryBitMap =
       HexString.fromHexString(jsonOduSignal.get("tributarySlotBitmap").asText());
   OduSignalId jsonOduSignalId = OduSignalId.oduSignalId(jsonTpn, jsonTsLen, tributaryBitMap);
   if (!instructionToMatch.oduSignalId().equals(jsonOduSignalId)) {
     description.appendText("oduSignalId was " + instructionToMatch);
     return false;
   }
   return true;
 }
 @Override
 protected void describeMismatchSafelyDerived(SqlQuery actual, Description mismatchDescription) {
   mismatchDescription.appendText(getName());
   mismatchDescription.appendText(" was ");
   mismatchDescription.appendValueList(
       "[", ",", "]", actual.children().map(this::extractIdentifier).collect(Collectors.toList()));
 }
Esempio n. 5
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));
 }
  /**
   * Matches the contents of a push header instruction.
   *
   * @param instructionJson JSON instruction to match
   * @param description Description object used for recording errors
   * @return true if contents match, false otherwise
   */
  private boolean matchModMplsHeaderInstruction(JsonNode instructionJson, Description description) {
    ModMplsHeaderInstruction instructionToMatch = (ModMplsHeaderInstruction) instruction;
    final String jsonSubtype = instructionJson.get("subtype").textValue();
    if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
      description.appendText("subtype was " + jsonSubtype);
      return false;
    }

    final String jsonType = instructionJson.get("type").textValue();
    if (!instructionToMatch.type().name().equals(jsonType)) {
      description.appendText("type was " + jsonType);
      return false;
    }

    final JsonNode ethJson = instructionJson.get("ethernetType");
    if (ethJson == null) {
      description.appendText("ethernetType was not null");
      return false;
    }

    if (instructionToMatch.ethernetType().toShort() != ethJson.asInt()) {
      description.appendText("ethernetType was " + ethJson);
      return false;
    }

    return true;
  }
Esempio n. 7
0
 @Override
 public void describeTo(Description description) {
   description.appendText("at a distance ");
   description.appendValue(distance);
   description.appendText(" from ");
   description.appendValue(seat);
 }
 protected boolean fail(
     String reasonForFailure, Collection<? extends E> item, Description mismatchDescription) {
   mismatchDescription.appendText(reasonForFailure);
   mismatchDescription.appendText(" <");
   mismatchDescription.appendText(item.toString());
   mismatchDescription.appendText(">");
   return false;
 }
Esempio n. 9
0
 @Test
 public void shouldBeDescriptive() {
   Matcher<Object> matcher = isJson(withPathEvaluatedTo(true));
   Description description = new StringDescription();
   matcher.describeTo(description);
   assertThat(description.toString(), startsWith("is json"));
   assertThat(description.toString(), containsString(TestingMatchers.MATCH_TRUE_TEXT));
 }
Esempio n. 10
0
 @Override
 public void describeTo(Description description) {
   description.appendText("is about ");
   description.appendValue(d);
   description.appendText(" (factor ");
   description.appendValue(factor);
   description.appendText(")");
 }
 @Override
 public void describeTo(Description description) {
   description.appendText("a Complex number having ");
   reMatcher.describeTo(description);
   description.appendText(" as real part and ");
   imMatcher.describeTo(description);
   description.appendText(" as imaginary part");
 }
Esempio n. 12
0
 @Override
 public void describeTo(final Description description) {
   if (this.expected.longValue() == 0L) {
     description.appendText("zero or null");
   } else {
     description.appendValue(this.expected);
   }
 }
 @Override
 public void describeTo(Description description) {
   description.appendText("link lookup for source \"");
   description.appendText(source);
   description.appendText(" and destination ");
   description.appendText(destination);
   description.appendText("\"");
 }
Esempio n. 14
0
 @Override
 public void describeMismatchSafely(Object bean, Description description) {
   if (beanPropertyValueFound) {
     description.appendText("found property value ").appendValue(beanPropertyValue);
   } else {
     description.appendText("property not found");
   }
 }
Esempio n. 15
0
 @Override
 public void describeMismatch(Object o, Description d) {
   if (o instanceof DcacheVersion) {
     d.appendText("Object not a DcacheVersion");
   } else {
     DcacheVersion other = (DcacheVersion) o;
     d.appendText("version " + other + " is not before " + comparison);
   }
 }
Esempio n. 16
0
 @Override
 public void describeMismatch(Object item, Description description) {
   description.appendText("was:");
   if (item instanceof String) {
     description.appendText((String) item);
   } else {
     description.appendValue(item);
   }
 }
Esempio n. 17
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;
 }
Esempio n. 18
0
  public void describeTo(Description description) {
    description.appendText("Found unexpected match at element " + index + " in the fragment.");

    if (matcher instanceof BaseHtmlElementMatcher) {
      description.appendText(
          "\nThe unexpected match is below: (the first is the element that actually matched, the second (after the but) is the full fragment)\n");
      ((BaseHtmlElementMatcher) matcher).describeMatchSafely(description);
    } else {
      description.appendText("\nThe unexpected match is below:\n");
      description.appendText("not ").appendDescriptionOf(matcher);
    }
  }
Esempio n. 19
0
 @Override
 protected void describeMismatchSafely(File item, Description mismatchDescription) {
   if (null != this.mismatch) {
     this.mismatch.describeMismatch(item, mismatchDescription);
   } else {
     mismatchDescription.appendValue(item).appendText(" contained\n");
     List<File> files = files(item);
     for (File file : files) {
       mismatchDescription.appendValue(file.getName()).appendText("\n");
     }
   }
 }
 public boolean isFinished() {
   if (nextMatchIx < matchers.size()) {
     mismatchDescription
         .appendDescriptionOf(matchers.get(nextMatchIx))
         .appendText(" was not found");
     if (lastMatchedItem != null) {
       mismatchDescription.appendText(" after ").appendValue(lastMatchedItem);
     }
     return false;
   }
   return true;
 }
Esempio n. 21
0
 @Override
 protected boolean matches(Object item, Description mismatchDescription) {
   FileSink fs = (FileSink) item;
   try {
     String contents = fs.getContents();
     mismatchDescription.appendValue(contents);
     return matcher.matches(contents);
   } catch (IOException e) {
     mismatchDescription.appendText("failed with an IOException: " + e.getMessage());
     return false;
   }
 }
Esempio n. 22
0
  @Override
  protected void describeMismatchSafely(final T item, final Description mismatchDescription) {
    mismatchDescription.appendValue(item).appendText(" is not equivalent to ");

    if (comparison == null) {
      mismatchDescription.appendText("null value");
    } else {
      mismatchDescription.appendValue(comparison);
    }

    mismatchDescription.appendText(" according with Equivalence ").appendValue(equivalence);
  }
Esempio n. 23
0
 @Override
 public void describeMismatch(Object item, Description description) {
   if (!snippetFileExists(item)) {
     description.appendText("The file " + item + " does not exist");
   } else if (this.expectedContents != null) {
     try {
       this.expectedContents.describeMismatch(read((File) item), description);
     } catch (IOException e) {
       description.appendText("The contents of " + item + " cound not be read");
     }
   }
 }
  @Override
  protected boolean matchesSafely(final Metadata metadata, final Description description) {
    if (idIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText("Metadata with id = " + metadata.id());
      return false;
    }

    if (nameIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText("Metadata with name = " + metadata.name());
      return false;
    }

    if (causationIdsDoNotMatchWith(metadata)) {
      description.appendText("Metadata with causationIds = " + metadata.causation());
      return false;
    }

    if (userIdIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText("Metadata with userId = " + metadata.userId().orElse(NOT_SET));
      return false;
    }

    if (sessionIdIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText("Metadata with sessionId = " + metadata.sessionId().orElse(NOT_SET));
      return false;
    }

    if (streamIdIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText(
          "Metadata with streamId = " + metadata.streamId().map(UUID::toString).orElse(NOT_SET));
      return false;
    }

    if (versionIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText(
          "Metadata with version = " + metadata.version().map(String::valueOf).orElse(NOT_SET));
      return false;
    }

    if (clientCorrelationIdIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText(
          "Metadata with clientCorrelationId = "
              + metadata.clientCorrelationId().map(String::valueOf).orElse(NOT_SET));
      return false;
    }

    if (jsonMatcherIsSetAndDoesNotMatchWith(metadata)) {
      description.appendText("Metadata ");
      jsonMatcher.ifPresent(
          matcher -> matcher.describeMismatch(metadata.asJsonObject().toString(), description));
      return false;
    }

    return true;
  }
Esempio n. 25
0
  public void describeTo(Description description) {
    java.util.regex.Matcher arg = ARG_PATTERN.matcher(descriptionTemplate);

    int textStart = 0;
    while (arg.find()) {
      description.appendText(descriptionTemplate.substring(textStart, arg.start()));
      int argIndex = Integer.parseInt(arg.group(1));
      description.appendValue(values[argIndex]);
      textStart = arg.end();
    }

    if (textStart < descriptionTemplate.length()) {
      description.appendText(descriptionTemplate.substring(textStart));
    }
  }
Esempio n. 26
0
        @Override
        protected boolean matchesSafely(String item, Description mismatchDescription) {
            try {
                if (!date.isEqual(ZonedDateTime.parse(item))) {
                    mismatchDescription.appendText("was ").appendValue(item);
                    return false;
                }
                return true;
            } catch (DateTimeParseException e) {
                mismatchDescription.appendText("was ").appendValue(item)
                    .appendText(", which could not be parsed as a ZonedDateTime");
                return false;
            }

        }
 public void describeTo(Description description) {
   description
       .appendText("a Message with Headers that match except ID and timestamp for payload: ")
       .appendValue(payload)
       .appendText(" and headers: ")
       .appendValue(headers);
 }
  /**
   * Matches the contents of a group instruction.
   *
   * @param instructionJson JSON instruction to match
   * @param description Description object used for recording errors
   * @return true if contents match, false otherwise
   */
  private boolean matchGroupInstruction(JsonNode instructionJson, Description description) {
    final String jsonType = instructionJson.get("type").textValue();
    GroupInstruction instructionToMatch = (GroupInstruction) instruction;
    if (!instructionToMatch.type().name().equals(jsonType)) {
      description.appendText("type was " + jsonType);
      return false;
    }

    final int jsonGroupId = instructionJson.get("groupId").intValue();
    if (instructionToMatch.groupId().id() != jsonGroupId) {
      description.appendText("groupId was " + jsonGroupId);
      return false;
    }

    return true;
  }
Esempio n. 29
0
 @Override
 public void describeMismatchSafely(BigDecimal bigDecimal, Description description) {
   description
       .appendValue(bigDecimal)
       .appendText(" differed by ")
       .appendValue(this.actualDelta(bigDecimal));
 }
  /**
   * Matches the contents of a meter instruction.
   *
   * @param instructionJson JSON instruction to match
   * @param description Description object used for recording errors
   * @return true if contents match, false otherwise
   */
  private boolean matchMeterInstruction(JsonNode instructionJson, Description description) {
    final String jsonType = instructionJson.get("type").textValue();
    MeterInstruction instructionToMatch = (MeterInstruction) instruction;
    if (!instructionToMatch.type().name().equals(jsonType)) {
      description.appendText("type was " + jsonType);
      return false;
    }

    final long jsonMeterId = instructionJson.get("meterId").longValue();
    if (instructionToMatch.meterId().id() != jsonMeterId) {
      description.appendText("meterId was " + jsonMeterId);
      return false;
    }

    return true;
  }