Skip to content

Commit 47a4695

Browse files
pkernevezbric3
authored andcommitted
chore: add jspecify with minimal change. Fixes #3503
1 parent 25f1395 commit 47a4695

6 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎gradle/libs.versions.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ errorprone-test-api = { module = "com.google.errorprone:error_prone_test_helpers
3030
groovy = { module = "org.codehaus.groovy:groovy", version = "3.0.25" }
3131
hamcrest = { module = "org.hamcrest:hamcrest-core", version = "3.0" }
3232
junit4 = { module = "junit:junit", version.ref = "junit4" }
33+
jspecify = { module = "org.jspecify:jspecify", version = "1.0.0" }
3334
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
3435
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" }
3536
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" }

‎mockito-core/build.gradle.kts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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)

‎mockito-core/src/main/java/module-info.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
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;

‎mockito-core/src/main/java/org/mockito/Mockito.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.mockito;
66

7+
import org.jspecify.annotations.Nullable;
78
import org.mockito.exceptions.misusing.PotentialStubbingProblem;
89
import org.mockito.exceptions.misusing.UnnecessaryStubbingException;
910
import 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

‎mockito-core/src/main/java/org/mockito/internal/MockitoCore.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131
import java.util.function.Function;
3232

33+
import org.jspecify.annotations.Nullable;
3334
import org.mockito.InOrder;
3435
import org.mockito.MockSettings;
3536
import 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")

‎mockito-core/src/main/java/org/mockito/stubbing/OngoingStubbing.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.mockito.stubbing;
66

7+
import org.jspecify.annotations.Nullable;
78
import org.mockito.Mockito;
89
import 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:

0 commit comments

Comments
 (0)