@Theory
 @SuppressWarnings({"unchecked", "rawtypes"})
 public void differentMatchersHaveDifferentDescriptions(
     Matcher matcher1, Matcher matcher2, Object value) {
   assumeThat(value, matcher1);
   assumeThat(value, not(matcher2));
   assertThat(matcher1.toString(), not(matcher2.toString()));
 }
Beispiel #2
0
 /** {@inheritDoc} */
 @SuppressWarnings("unchecked")
 public <T> JsonAsserter assertThat(String path, Matcher<T> matcher, String message) {
   T obj = JsonPath.<T>read(jsonObject, path);
   if (!matcher.matches(obj)) {
     throw new AssertionError(
         String.format(
             "JSON Assert Error: %s\nExpected:\n%s\nActual:\n%s",
             message, matcher.toString(), obj));
   }
   return this;
 }
 /**
  * Create Workbench ToolItem matching given toolTip matcher
  *
  * @param matcher
  */
 public WorkbenchToolItem(Matcher<String> toolTipMatcher) {
   ToolBarLookup tl = new ToolBarLookup();
   ToolBar[] workbenchToolBars = tl.getWorkbenchToolBars();
   ToolItem ti = null;
   for (ToolBar t : workbenchToolBars) {
     ti = tl.getToolItem(t, toolTipMatcher);
     if (ti != null) break;
   }
   Thrower.objectIsNull(ti, "ToolItem matching " + toolTipMatcher.toString() + " cannot be found");
   toolItem = ti;
 }
 @Override
 public String description() {
   StringBuffer message = new StringBuffer();
   message.append("an item matching ").append(matcher.toString()).append(" in\n");
   for (TableItem item : items) {
     String text = null;
     if (!item.getSWTWidget().isDisposed()) {
       text = item.getText();
     }
     message.append("\t").append(text).append("\n");
   }
   return message.toString();
 }
  /**
   * toString.
   *
   * @return a String representation of the request
   */
  @Override
  public String toString() {

    List<String> queryStringValues = new ArrayList<String>();

    for (Entry<String, Matcher<? extends String>> entry : params.entries()) {
      String stringified = removeQuotes(entry.getValue());
      queryStringValues.add(entry.getKey() + "=" + stringified);
    }

    String queryString = StringUtils.join(queryStringValues, "&");

    if (queryStringValues.size() > 0) {
      queryString = "?" + queryString;
    }

    return "ClientDriverRequest: " + method + " " + path.toString() + queryString + "; ";
  }
 @Test
 public void instanciated_matcher_should_provide_meaningful_description() {
   Matcher<Object> matcher =
       ((BeanFieldMatcher) BeanMatchers.the("firstName", is("Bill"))).getMatcher();
   assertThat(matcher.toString()).isEqualTo("firstName is 'Bill'");
 }
 private static String removeQuotes(Matcher<? extends String> matcher) {
   return StringUtils.removeEnd(StringUtils.removeStart(matcher.toString(), "\""), "\"");
 }