From 8962ed07d680b61939cf1ae49eaa210e01cfaf27 Mon Sep 17 00:00:00 2001 From: StevenCurran Date: Sun, 27 Aug 2023 04:39:24 -0400 Subject: [PATCH] Clarify new type-checking behavior of ArgumentCaptor (#3103) --- src/main/java/org/mockito/ArgumentCaptor.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/mockito/ArgumentCaptor.java b/src/main/java/org/mockito/ArgumentCaptor.java index e9b347bd2e..2fdeb628d7 100644 --- a/src/main/java/org/mockito/ArgumentCaptor.java +++ b/src/main/java/org/mockito/ArgumentCaptor.java @@ -50,8 +50,7 @@ * Custom argument matchers via {@link ArgumentMatcher} are usually better for stubbing. * *

- * This utility class *doesn't do any type checks*. The generic signatures are only there to avoid casting - * in your code. + * This utility class will perform type checking on the generic type (since Mockito 5.0.0). *

* There is an annotation that you might find useful: @{@link Captor} *

@@ -68,7 +67,7 @@ public class ArgumentCaptor { private ArgumentCaptor(Class clazz) { this.clazz = clazz; - this.capturingMatcher = new CapturingMatcher(clazz); + this.capturingMatcher = new CapturingMatcher<>(clazz); } /** @@ -138,9 +137,7 @@ public List getAllValues() { /** * Build a new ArgumentCaptor. *

- * Note that an ArgumentCaptor *doesn't do any type checks*. 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 ArgumentCaptor will perform type checks (since Mockito 5.0.0). * * @param clazz Type matching the parameter to be captured. * @param Type of clazz @@ -148,6 +145,6 @@ public List getAllValues() { * @return A new ArgumentCaptor */ public static ArgumentCaptor forClass(Class clazz) { - return new ArgumentCaptor(clazz); + return new ArgumentCaptor<>(clazz); } }