Skip to content

Commit

Permalink
Clarify new type-checking behavior of ArgumentCaptor (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenCurran committed Aug 27, 2023
1 parent eeeff29 commit 8962ed0
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/org/mockito/ArgumentCaptor.java
Expand Up @@ -50,8 +50,7 @@
* Custom argument matchers via {@link ArgumentMatcher} are usually better for stubbing.
*
* <p>
* This utility class <strong>*doesn't do any type checks*</strong>. The generic signatures are only there to avoid casting
* in your code.
* This utility class <strong>will</strong> perform type checking on the generic type (since Mockito 5.0.0).
* <p>
* There is an <strong>annotation</strong> that you might find useful: &#64;{@link Captor}
* <p>
Expand All @@ -68,7 +67,7 @@ public class ArgumentCaptor<T> {

private ArgumentCaptor(Class<? extends T> clazz) {
this.clazz = clazz;
this.capturingMatcher = new CapturingMatcher<T>(clazz);
this.capturingMatcher = new CapturingMatcher<>(clazz);
}

/**
Expand Down Expand Up @@ -138,16 +137,14 @@ public List<T> getAllValues() {
/**
* Build a new <code>ArgumentCaptor</code>.
* <p>
* Note that an <code>ArgumentCaptor</code> <b>*doesn't do any type checks*</b>. It is only there to avoid casting
* in your code. This might however change (type checks could be added) in a
* future major release.
* An <code>ArgumentCaptor</code> will perform type checks (since Mockito 5.0.0).
*
* @param clazz Type matching the parameter to be captured.
* @param <S> Type of clazz
* @param <U> Type of object captured by the newly built ArgumentCaptor
* @return A new ArgumentCaptor
*/
public static <U, S extends U> ArgumentCaptor<U> forClass(Class<S> clazz) {
return new ArgumentCaptor<U>(clazz);
return new ArgumentCaptor<>(clazz);
}
}

0 comments on commit 8962ed0

Please sign in to comment.