File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ errorprone-test-api = { module = "com.google.errorprone:error_prone_test_helpers
3030groovy = { module = " org.codehaus.groovy:groovy" , version = " 3.0.25" }
3131hamcrest = { module = " org.hamcrest:hamcrest-core" , version = " 3.0" }
3232junit4 = { module = " junit:junit" , version.ref = " junit4" }
33+ jspecify = { module = " org.jspecify:jspecify" , version = " 1.0.0" }
3334junit-jupiter-api = { module = " org.junit.jupiter:junit-jupiter-api" , version.ref = " junit-jupiter" }
3435junit-jupiter-engine = { module = " org.junit.jupiter:junit-jupiter-engine" , version.ref = " junit-jupiter" }
3536junit-jupiter-params = { module = " org.junit.jupiter:junit-jupiter-params" , version.ref = " junit-jupiter" }
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ dependencies {
4444 compileOnly(libs.hamcrest)
4545 compileOnly(libs.opentest4j)
4646 implementation(libs.objenesis)
47+ implementation(libs.jspecify)
4748
4849 testImplementation(libs.assertj)
4950 testImplementation(libs.junit.jupiter.api)
Original file line number Diff line number Diff line change 1212 requires static org .objenesis ;
1313 requires static org .opentest4j ;
1414 requires static jdk .unsupported ;
15+ requires org .jspecify ;
1516
1617 exports org .mockito ;
1718 exports org .mockito .configuration ;
Original file line number Diff line number Diff line change 44 */
55package org .mockito ;
66
7+ import org .jspecify .annotations .Nullable ;
78import org .mockito .exceptions .misusing .PotentialStubbingProblem ;
89import org .mockito .exceptions .misusing .UnnecessaryStubbingException ;
910import org .mockito .internal .MockitoCore ;
@@ -2895,7 +2896,7 @@ public static <T> MockedConstruction<T> mockConstruction(
28952896 * @return OngoingStubbing object used to stub fluently.
28962897 * <strong>Do not</strong> create a reference to this returned object.
28972898 */
2898- public static <T > OngoingStubbing <T > when (T methodCall ) {
2899+ public static <T > OngoingStubbing <T > when (@ Nullable T methodCall ) {
28992900 return MOCKITO_CORE .when (methodCall );
29002901 }
29012902
Original file line number Diff line number Diff line change 3030import java .util .List ;
3131import java .util .function .Function ;
3232
33+ import org .jspecify .annotations .Nullable ;
3334import org .mockito .InOrder ;
3435import org .mockito .MockSettings ;
3536import org .mockito .MockedConstruction ;
@@ -136,7 +137,7 @@ public <T> MockedConstruction<T> mockConstruction(
136137 return new MockedConstructionImpl <>(control );
137138 }
138139
139- public <T > OngoingStubbing <T > when (T methodCall ) {
140+ public <T > OngoingStubbing <T > when (@ Nullable T methodCall ) {
140141 MockingProgress mockingProgress = mockingProgress ();
141142 mockingProgress .stubbingStarted ();
142143 @ SuppressWarnings ("unchecked" )
Original file line number Diff line number Diff line change 44 */
55package org .mockito .stubbing ;
66
7+ import org .jspecify .annotations .Nullable ;
78import org .mockito .Mockito ;
89import org .mockito .NotExtensible ;
910
@@ -47,7 +48,7 @@ public interface OngoingStubbing<T> {
4748 *
4849 * @return object that allows stubbing consecutive calls
4950 */
50- OngoingStubbing <T > thenReturn (T value );
51+ OngoingStubbing <T > thenReturn (@ Nullable T value );
5152
5253 /**
5354 * Sets consecutive return values to be returned when the method is called. E.g:
@@ -67,7 +68,7 @@ public interface OngoingStubbing<T> {
6768 // Additional method helps users of JDK7+ to hide heap pollution / unchecked generics array
6869 // creation warnings (on call site)
6970 @ SuppressWarnings ({"unchecked" , "varargs" })
70- OngoingStubbing <T > thenReturn (T value , T ... values );
71+ OngoingStubbing <T > thenReturn (@ Nullable T value , @ Nullable T ... values );
7172
7273 /**
7374 * Sets Throwable objects to be thrown when the method is called. E.g:
You can’t perform that action at this time.
0 commit comments