Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#182 Supply Javadoc comments for MatcherAssert #263

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions hamcrest/src/main/java/org/hamcrest/MatcherAssert.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
package org.hamcrest;


/**
* Utility class that contains static methods for verifying that assertions
* hold and reporting the violation when they do not.
*/
public class MatcherAssert {

/**
* Verifies that <code>matcher</code> matches <code>actual</code>.
* Convenience method for performing an assertion without supplying a reason.
* Equivalent to <code>assertThat("", actual, matcher)</code>.
*
* @see {@link MatcherAssert#assertThat(String, Object, Matcher)}
*
* @param <T> The type of the actual value to match.
* @param actual A value to test.
* @param matcher The matcher to use for matching the actual value
*/
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
assertThat("", actual, matcher);
}

/**
* Verifies that <code>matcher</code> matches <code>actual</code>. If the matcher
* does not match the actual value, this method throws an <code>AssertionError</code>
* with a description of the mismatch.
*
* @param <T> The type of the actual value to match.
* @param reason A reason for explaining the mismatch.
* @param actual A value to test.
* @param matcher The matcher to use for matching the actual value
*/
public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {
if (!matcher.matches(actual)) {
Description description = new StringDescription();
Expand All @@ -19,6 +45,14 @@ public static <T> void assertThat(String reason, T actual, Matcher<? super T> ma
}
}

/**
* Verifies that <code>assertion</code> evaluates to <code>true</code>, and
* throws an <code>AssertionError</code> with the message <code>reason</code>
* if it does not.
*
* @param reason The message use to report an assertion failure.
* @param assertion An expression expected to evaluate to <code>true</code>.
*/
public static void assertThat(String reason, boolean assertion) {
if (!assertion) {
throw new AssertionError(reason);
Expand Down