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

The following examples show how to use org.hamcrest.Description#appendValueList() . 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: GitMatchers.java    From multi-module-maven-release-plugin with MIT License 6 votes vote down vote up
public static Matcher<Git> hasCleanWorkingDirectory() {
    return new TypeSafeDiagnosingMatcher<Git>() {
        @Override
        protected boolean matchesSafely(Git git, Description mismatchDescription) {
            try {
                Status status = git.status().call();
                if (!status.isClean()) {
                    String start = "Uncommitted changes in ";
                    String end = " at " + git.getRepository().getWorkTree().getAbsolutePath();
                    mismatchDescription.appendValueList(start, ", ", end, status.getUncommittedChanges());
                }
                return status.isClean();
            } catch (GitAPIException e) {
                throw new RuntimeException("Error checking git status", e);
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("A git directory with no staged or unstaged changes");
        }
    };
}
 
Example 2
Source File: GitMatchers.java    From multi-module-maven-release-plugin with MIT License 6 votes vote down vote up
public static Matcher<Git> hasTag(final String tag) {
    return new TypeSafeDiagnosingMatcher<Git>() {
        @Override
        protected boolean matchesSafely(Git repo, Description mismatchDescription) {
            try {
                mismatchDescription.appendValueList("a git repo with tags: ", ", ", "", repo.getRepository().getTags().keySet());
                return GitHelper.hasLocalTag(repo, tag);
            } catch (Exception e) {
                throw new RuntimeException("Couldn't access repo", e);
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("a git repo with the tag " + tag);
        }
    };
}
 
Example 3
Source File: RecordedRequestMatcher.java    From auth0-java with MIT License 6 votes vote down vote up
private boolean matchesQueryParameter(RecordedRequest item, Description mismatchDescription) {
    HttpUrl requestUrl = item.getRequestUrl();
    if (requestUrl.querySize() == 0) {
        mismatchDescription.appendText(" query was empty");
        return false;
    }

    String queryParamValue = requestUrl.queryParameter(first);
    if (second.equals(queryParamValue)) {
        return true;
    }

    mismatchDescription.appendValueList("Query parameters were {", ", ", "}.",
            requestUrl.query().split("&"));
    return false;
}
 
Example 4
Source File: RecordedRequestMatcher.java    From auth0-java with MIT License 6 votes vote down vote up
private boolean hasQueryParameter(RecordedRequest item, Description mismatchDescription) {
    String path = item.getPath();
    boolean hasQuery = path.indexOf("?") > 0;
    if (!hasQuery) {
        mismatchDescription.appendText(" query was empty");
        return false;
    }

    String query = path.substring(path.indexOf("?") + 1, path.length());
    String[] parameters = query.split("&");
    for (String p : parameters) {
        if (p.startsWith(String.format("%s=", first))) {
            return true;
        }
    }
    mismatchDescription.appendValueList("Query parameters were {", ", ", "}.", parameters);
    return false;
}
 
Example 5
Source File: ExactCountMatcher.java    From multi-module-maven-release-plugin with MIT License 6 votes vote down vote up
@Override
protected boolean matchesSafely(List<String> items, Description mismatchDescriptor) {
    int count = 0;
    for (String item : items) {
        if (stringMatcher.matches(item)) {
            count++;
        }
    }
    boolean okay = count == expectedCount;
    if (!okay) {
        mismatchDescriptor.appendText("was matched " + count + " times in the following list:");
        String separator = String.format("%n") + "          ";
        mismatchDescriptor.appendValueList(separator, separator, "", items);

    }
    return okay;
}
 
Example 6
Source File: HasNoneOfReasons.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void describeMismatch(Object item, Description description) {
    describeTo(description);
    description.appendValueList(" but actual event reasons were {", ", ", "}.",
            ((List<Event>) item).stream().map(evt -> {
                String objRef = "";
                if (evt.getInvolvedObject() != null) {
                    objRef = " involved object: " + evt.getInvolvedObject().getKind() + "/" + evt.getInvolvedObject().getName();
                }
                return evt.getReason() + " (" + evt.getType() + " " + evt.getMessage() + objRef + ")\n";
            })
                    .collect(Collectors.toList()));
}
 
Example 7
Source File: HasCookieMatcher.java    From matchers-java with Apache License 2.0 5 votes vote down vote up
@Override
protected void describeMismatchSafely(WebDriver item, Description mismatchDescription) {
    mismatchDescription.appendText("was only ");
    List<String> cookNames = new LinkedList<>();
    for (Cookie cook : item.manage().getCookies()) {
       cookNames.add(cook.getName());
    }
    mismatchDescription.appendValueList("[", ", ", "]", cookNames);
}
 
Example 8
Source File: CodeUsesMethodReferencesMatcher.java    From lambda-tutorial with GNU General Public License v2.0 5 votes vote down vote up
private void context(String sourceCode, String methodName, Description mismatchDescription) {
    if (!sourceCode.contains(methodName)) {
        mismatchDescription.appendText("You did not appear to invoke the method at all.");
    } else {
        String[] lines = sourceCode.split("\\n");
        mismatchDescription.appendText("Actual invocations: ");
        mismatchDescription.appendValueList("[", ",", "]",
                Arrays.stream(lines).filter(l -> l.contains(methodName)).map(String::trim).collect(toList()));
    }
}
 
Example 9
Source File: UserExceptionMatcher.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected void describeMismatchSafely(final UserException e, final Description description) {
  description.appendText("UserException thrown was of type: ")
    .appendValue(e.getErrorType().toString());
  if (expectedMessage != null) {
    description.appendText(" with message: \"")
      .appendText(e.getMessage())
    .appendText("\"");
  }
  if (expectedContexts != null) {
    description.appendValueList(" with contexts {", ",", "}", e.getContextStrings());
  }
}
 
Example 10
Source File: UserExceptionMatcher.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void describeTo(final Description description) {
  description.appendText("UserException of type: ")
    .appendValue(expectedType.toString());
  if (expectedMessage != null) {
    description.appendText(" with message that contains: \"")
      .appendText(expectedMessage)
      .appendText("\"");
  }
  if (expectedContexts != null) {
    description.appendValueList(" with contexts that contain every one of {", ",", "}", expectedContexts);
  }
}
 
Example 11
Source File: ReflectionsTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
public <T> Matcher<Set<? super T>> are(final T... ts) {
    final Collection<?> c1 = Arrays.asList(ts);
    return new BaseMatcher<Set<? super T>>() {
        public boolean matches(Object o) {
            Collection<?> c2 = (Collection<?>) o;
            return c1.containsAll(c2) && c2.containsAll(c1);
        }

        public void describeTo(Description description) {
            description.appendText("elements: ");
            description.appendValueList("(", ",", ")", ts);
        }
    };
}
 
Example 12
Source File: HasAnyOfReasons.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendValueList("The resource should contain at least one the following events {", ", ", "}. ", eventReasons);
}
 
Example 13
Source File: HasAllOfReasons.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendValueList("The resource should contain all of the following events {", ", ", "}. ", eventReasons);
}
 
Example 14
Source File: ExecutionGraphDeploymentTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
	description.appendValueList("<[", ", ", "]>", executionStages);
}
 
Example 15
Source File: ContainsSameElements.java    From vespa with Apache License 2.0 4 votes vote down vote up
private void appendCollection(Description description, Collection<?> collection) {
    description.appendValueList("{", ", ", "}", elementsToStringSorted(collection));
}
 
Example 16
Source File: AvailablePortMatcher.java    From docker-compose-rule with Apache License 2.0 4 votes vote down vote up
@Override
protected void describeMismatchSafely(Collection<DockerPort> unavailablePorts, Description mismatchDescription) {
    mismatchDescription.appendValueList("These ports were unavailable:\n", "\n", ".", buildClosedPortsErrorMessage(unavailablePorts));
}
 
Example 17
Source File: CollectionsMatchers.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendValueList("a collection which contains ", ", ", ".", items);
}
 
Example 18
Source File: CollectionsMatchers.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendValueList("a collection which contains ", ", ", ".", items);
}
 
Example 19
Source File: JVMMetricsHandlerTest.java    From styx with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendValueList("[", ",", "]", this.substrings);
}
 
Example 20
Source File: HasNoneOfReasons.java    From strimzi-kafka-operator with Apache License 2.0 2 votes vote down vote up
/**
 * Generates a description of the object.  The description may be part of a
 * a description of a larger object of which this is just a component, so it
 * should be worded appropriately.
 *
 * @param description The description to be built or appended to.
 */
@Override
public void describeTo(Description description) {
    description.appendValueList("The resource should not contain no events with any of the reasons {", ", ", "}, ",
            prohibitedEvents);
}