Skip to content

Commit

Permalink
Fix up more javadoc warnings under jdk21
Browse files Browse the repository at this point in the history
  • Loading branch information
tumbarumba committed Nov 17, 2024
1 parent 5dc0112 commit f089c7e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
8 changes: 3 additions & 5 deletions hamcrest/src/main/java/org/hamcrest/Matchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ public static <T> Matcher<Optional<T>> optionalWithValue(Matcher<? super T> matc
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception
* Matcher for {@link Runnable} that expects an exception to be thrown
*
* @param <T> type of the Runnable
* @return The matcher.
Expand Down Expand Up @@ -2297,23 +2297,21 @@ public static <T extends Runnable, U extends Throwable> Matcher<T> throwsExcepti
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message equal to the provided <code>message</code>
*
* @param <T> type of the Runnable
* @param <U> type of the Throwable
* @param message the String against which examined exception messages are compared
* @return The matcher.
*/
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsExceptionWithMessage(String message) {
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(String message) {
return ThrowsException.throwsExceptionWithMessage(message);
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message matching the provided <code>messageMatcher</code>
*
* @param <T> type of the Runnable
* @param <U> type of the Throwable
* @param messageMatcher matcher to validate exception's message
* @return The matcher.
*/
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsExceptionWithMessage(Matcher<String> messageMatcher) {
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(Matcher<String> messageMatcher) {
return ThrowsException.throwsExceptionWithMessage(messageMatcher);
}
}
65 changes: 65 additions & 0 deletions hamcrest/src/main/java/org/hamcrest/exception/ThrowsException.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,100 @@ public class ThrowsException<T extends Runnable> extends TypeSafeDiagnosingMatch
private final IsInstanceOf classMatcher;
private final Matcher<? super String> messageMatcher;

/**
* Constructor, best called from one of the static {@link #throwsException()} methods.
* @param classMatcher the matcher for the type of the exception
* @param messageMatcher the matcher for the exception message
*/
public ThrowsException(IsInstanceOf classMatcher, Matcher<? super String> messageMatcher) {
this.classMatcher = classMatcher;
this.messageMatcher = messageMatcher;
}

/**
* Matcher for {@link Runnable} that expects an exception to be thrown
*
* @param <T> type of the Runnable
* @return The matcher.
*/
public static <T extends Runnable> Matcher<T> throwsException() {
return throwsException(Throwable.class);
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception equal
* to the provided <code>throwable</code>
*
* @param <U> type of the Runnable
* @param <T> type of the Throwable
* @param throwable the Throwable class against which examined exceptions are compared
* @return The matcher.
*/
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(U throwable) {
return throwsException(throwable.getClass(), throwable.getMessage());
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception of the
* provided <code>throwableClass</code> class
*
* @param <U> type of the Runnable
* @param <T> type of the Throwable
* @param throwableClass the Throwable class against which examined exceptions are compared
* @return The matcher.
*/
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(Class<U> throwableClass) {
return new ThrowsException<>(new IsInstanceOf(throwableClass), anything("<anything>"));
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception of the
* provided <code>throwableClass</code> class and has a message equal to the provided
* <code>message</code>
*
* @param <T> type of the Runnable
* @param <U> type of the Throwable
* @param throwableClass the Throwable class against which examined exceptions are compared
* @param exactMessage the String against which examined exception messages are compared
* @return The matcher.
*/
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(Class<U> throwableClass, String exactMessage) {
return throwsException(throwableClass, equalTo(exactMessage));
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception of the provided
* <code>throwableClass</code> class and has a message matching the provided
* <code>messageMatcher</code>
*
* @param <T> type of the Runnable
* @param <U> type of the Throwable
* @param throwableClass the Throwable class against which examined exceptions are compared
* @param messageMatcher matcher to validate exception's message
* @return The matcher.
*/
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(Class<U> throwableClass, Matcher<String> messageMatcher) {
return new ThrowsException<>(new IsInstanceOf(throwableClass), messageMatcher);
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message equal to the provided <code>message</code>
*
* @param <T> type of the Runnable
* @param exactMessage the String against which examined exception messages are compared
* @return The matcher.
*/
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(String exactMessage) {
return throwsException(Throwable.class, equalTo(exactMessage));
}

/**
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message matching the provided <code>messageMatcher</code>
*
* @param <T> type of the Runnable
* @param messageMatcher matcher to validate exception's message
* @return The matcher.
*/
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(Matcher<String> messageMatcher) {
return throwsException(Throwable.class, messageMatcher);
}
Expand Down

0 comments on commit f089c7e

Please sign in to comment.