Skip to content

Commit

Permalink
applied @CheckReturnValue to some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenelesnov committed Aug 2, 2021
1 parent 3dc7b7c commit c0d0054
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/mockito/ArgumentCaptor.java
Expand Up @@ -59,6 +59,7 @@
* @see Captor
* @since 1.8.0
*/
@CheckReturnValue
public class ArgumentCaptor<T> {

private final CapturingMatcher<T> capturingMatcher = new CapturingMatcher<T>();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/mockito/ArgumentMatchers.java
Expand Up @@ -112,6 +112,7 @@
*
* @see AdditionalMatchers
*/
@CheckReturnValue
@SuppressWarnings("unchecked")
public class ArgumentMatchers {

Expand Down
46 changes: 1 addition & 45 deletions src/main/java/org/mockito/Mockito.java
Expand Up @@ -1590,6 +1590,7 @@
* released. To define mock behavior and to verify method invocations, use the <code>MockedConstruction</code> that is returned.
* <p>
*/
@CheckReturnValue
@SuppressWarnings("unchecked")
public class Mockito extends ArgumentMatchers {

Expand Down Expand Up @@ -1860,7 +1861,6 @@ public class Mockito extends ArgumentMatchers {
* @param classToMock class or interface to mock
* @return mock object
*/
@CheckReturnValue
public static <T> T mock(Class<T> classToMock) {
return mock(classToMock, withSettings());
}
Expand All @@ -1880,7 +1880,6 @@ public static <T> T mock(Class<T> classToMock) {
* @param name of the mock
* @return mock object
*/
@CheckReturnValue
public static <T> T mock(Class<T> classToMock, String name) {
return mock(classToMock, withSettings().name(name).defaultAnswer(RETURNS_DEFAULTS));
}
Expand All @@ -1897,7 +1896,6 @@ public static <T> T mock(Class<T> classToMock, String name) {
* @return A {@link org.mockito.MockingDetails} instance.
* @since 1.9.5
*/
@CheckReturnValue
public static MockingDetails mockingDetails(Object toInspect) {
return MOCKITO_CORE.mockingDetails(toInspect);
}
Expand All @@ -1921,7 +1919,6 @@ public static MockingDetails mockingDetails(Object toInspect) {
*
* @return mock object
*/
@CheckReturnValue
public static <T> T mock(Class<T> classToMock, Answer defaultAnswer) {
return mock(classToMock, withSettings().defaultAnswer(defaultAnswer));
}
Expand Down Expand Up @@ -1949,7 +1946,6 @@ public static <T> T mock(Class<T> classToMock, Answer defaultAnswer) {
* @param mockSettings additional mock settings
* @return mock object
*/
@CheckReturnValue
public static <T> T mock(Class<T> classToMock, MockSettings mockSettings) {
return MOCKITO_CORE.mock(classToMock, mockSettings);
}
Expand Down Expand Up @@ -2033,7 +2029,6 @@ public static <T> T mock(Class<T> classToMock, MockSettings mockSettings) {
* to spy on
* @return a spy of the real object
*/
@CheckReturnValue
public static <T> T spy(T object) {
return MOCKITO_CORE.mock(
(Class<T>) object.getClass(),
Expand Down Expand Up @@ -2068,7 +2063,6 @@ public static <T> T spy(T object) {
* @since 1.10.12
*/
@Incubating
@CheckReturnValue
public static <T> T spy(Class<T> classToSpy) {
return MOCKITO_CORE.mock(
classToSpy, withSettings().useConstructor().defaultAnswer(CALLS_REAL_METHODS));
Expand All @@ -2091,7 +2085,6 @@ public static <T> T spy(Class<T> classToSpy) {
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedStatic<T> mockStatic(Class<T> classToMock) {
return mockStatic(classToMock, withSettings());
}
Expand All @@ -2114,7 +2107,6 @@ public static <T> MockedStatic<T> mockStatic(Class<T> classToMock) {
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedStatic<T> mockStatic(Class<T> classToMock, Answer defaultAnswer) {
return mockStatic(classToMock, withSettings().defaultAnswer(defaultAnswer));
}
Expand All @@ -2137,7 +2129,6 @@ public static <T> MockedStatic<T> mockStatic(Class<T> classToMock, Answer defaul
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedStatic<T> mockStatic(Class<T> classToMock, String name) {
return mockStatic(classToMock, withSettings().name(name));
}
Expand All @@ -2160,7 +2151,6 @@ public static <T> MockedStatic<T> mockStatic(Class<T> classToMock, String name)
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedStatic<T> mockStatic(Class<T> classToMock, MockSettings mockSettings) {
return MOCKITO_CORE.mockStatic(classToMock, mockSettings);
}
Expand All @@ -2179,7 +2169,6 @@ public static <T> MockedStatic<T> mockStatic(Class<T> classToMock, MockSettings
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedConstruction<T> mockConstructionWithAnswer(
Class<T> classToMock, Answer defaultAnswer, Answer... additionalAnswers) {
return mockConstruction(
Expand Down Expand Up @@ -2209,7 +2198,6 @@ public static <T> MockedConstruction<T> mockConstructionWithAnswer(
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedConstruction<T> mockConstruction(Class<T> classToMock) {
return mockConstruction(classToMock, index -> withSettings(), (mock, context) -> {});
}
Expand All @@ -2226,7 +2214,6 @@ public static <T> MockedConstruction<T> mockConstruction(Class<T> classToMock) {
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedConstruction<T> mockConstruction(
Class<T> classToMock, MockedConstruction.MockInitializer<T> mockInitializer) {
return mockConstruction(classToMock, withSettings(), mockInitializer);
Expand All @@ -2244,7 +2231,6 @@ public static <T> MockedConstruction<T> mockConstruction(
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedConstruction<T> mockConstruction(
Class<T> classToMock, MockSettings mockSettings) {
return mockConstruction(classToMock, context -> mockSettings);
Expand All @@ -2262,7 +2248,6 @@ public static <T> MockedConstruction<T> mockConstruction(
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedConstruction<T> mockConstruction(
Class<T> classToMock,
Function<MockedConstruction.Context, MockSettings> mockSettingsFactory) {
Expand All @@ -2282,7 +2267,6 @@ public static <T> MockedConstruction<T> mockConstruction(
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedConstruction<T> mockConstruction(
Class<T> classToMock,
MockSettings mockSettings,
Expand All @@ -2303,7 +2287,6 @@ public static <T> MockedConstruction<T> mockConstruction(
* @return mock controller
*/
@Incubating
@CheckReturnValue
public static <T> MockedConstruction<T> mockConstruction(
Class<T> classToMock,
Function<MockedConstruction.Context, MockSettings> mockSettingsFactory,
Expand Down Expand Up @@ -2371,7 +2354,6 @@ public static <T> MockedConstruction<T> mockConstruction(
* @return OngoingStubbing object used to stub fluently.
* <strong>Do not</strong> create a reference to this returned object.
*/
@CheckReturnValue
public static <T> OngoingStubbing<T> when(T methodCall) {
return MOCKITO_CORE.when(methodCall);
}
Expand Down Expand Up @@ -2402,7 +2384,6 @@ public static <T> OngoingStubbing<T> when(T methodCall) {
* @param mock to be verified
* @return mock object itself
*/
@CheckReturnValue
public static <T> T verify(T mock) {
return MOCKITO_CORE.verify(mock, times(1));
}
Expand All @@ -2429,7 +2410,6 @@ public static <T> T verify(T mock) {
*
* @return mock object itself
*/
@CheckReturnValue
public static <T> T verify(T mock, VerificationMode mode) {
return MOCKITO_CORE.verify(mock, mode);
}
Expand Down Expand Up @@ -2584,7 +2564,6 @@ public static void verifyNoInteractions(Object... mocks) {
* @param toBeThrown to be thrown when the stubbed method is called
* @return stubber - to select a method for stubbing
*/
@CheckReturnValue
public static Stubber doThrow(Throwable... toBeThrown) {
return MOCKITO_CORE.stubber().doThrow(toBeThrown);
}
Expand All @@ -2607,7 +2586,6 @@ public static Stubber doThrow(Throwable... toBeThrown) {
* @return stubber - to select a method for stubbing
* @since 2.1.0
*/
@CheckReturnValue
public static Stubber doThrow(Class<? extends Throwable> toBeThrown) {
return MOCKITO_CORE.stubber().doThrow(toBeThrown);
}
Expand Down Expand Up @@ -2635,7 +2613,6 @@ public static Stubber doThrow(Class<? extends Throwable> toBeThrown) {
// Additional method helps users of JDK7+ to hide heap pollution / unchecked generics array
// creation
@SuppressWarnings({"unchecked", "varargs"})
@CheckReturnValue
public static Stubber doThrow(
Class<? extends Throwable> toBeThrown, Class<? extends Throwable>... toBeThrownNext) {
return MOCKITO_CORE.stubber().doThrow(toBeThrown, toBeThrownNext);
Expand Down Expand Up @@ -2672,7 +2649,6 @@ public static Stubber doThrow(
* @return stubber - to select a method for stubbing
* @since 1.9.5
*/
@CheckReturnValue
public static Stubber doCallRealMethod() {
return MOCKITO_CORE.stubber().doCallRealMethod();
}
Expand All @@ -2699,7 +2675,6 @@ public static Stubber doCallRealMethod() {
* @param answer to answer when the stubbed method is called
* @return stubber - to select a method for stubbing
*/
@CheckReturnValue
public static Stubber doAnswer(Answer answer) {
return MOCKITO_CORE.stubber().doAnswer(answer);
}
Expand Down Expand Up @@ -2742,7 +2717,6 @@ public static Stubber doAnswer(Answer answer) {
*
* @return stubber - to select a method for stubbing
*/
@CheckReturnValue
public static Stubber doNothing() {
return MOCKITO_CORE.stubber().doNothing();
}
Expand Down Expand Up @@ -2793,7 +2767,6 @@ public static Stubber doNothing() {
* @param toBeReturned to be returned when the stubbed method is called
* @return stubber - to select a method for stubbing
*/
@CheckReturnValue
public static Stubber doReturn(Object toBeReturned) {
return MOCKITO_CORE.stubber().doReturn(toBeReturned);
}
Expand Down Expand Up @@ -2848,7 +2821,6 @@ public static Stubber doReturn(Object toBeReturned) {
* @since 2.1.0
*/
@SuppressWarnings({"unchecked", "varargs"})
@CheckReturnValue
public static Stubber doReturn(Object toBeReturned, Object... toBeReturnedNext) {
return MOCKITO_CORE.stubber().doReturn(toBeReturned, toBeReturnedNext);
}
Expand Down Expand Up @@ -2880,7 +2852,6 @@ public static Stubber doReturn(Object toBeReturned, Object... toBeReturnedNext)
*
* @return InOrder object to be used to verify in order
*/
@CheckReturnValue
public static InOrder inOrder(Object... mocks) {
return MOCKITO_CORE.inOrder(mocks);
}
Expand Down Expand Up @@ -2981,7 +2952,6 @@ public static Object[] ignoreStubs(Object... mocks) {
*
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode times(int wantedNumberOfInvocations) {
return VerificationModeFactory.times(wantedNumberOfInvocations);
}
Expand All @@ -3003,7 +2973,6 @@ public static VerificationMode times(int wantedNumberOfInvocations) {
*
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode never() {
return times(0);
}
Expand All @@ -3019,7 +2988,6 @@ public static VerificationMode never() {
*
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode atLeastOnce() {
return VerificationModeFactory.atLeastOnce();
}
Expand All @@ -3036,7 +3004,6 @@ public static VerificationMode atLeastOnce() {
*
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode atLeast(int minNumberOfInvocations) {
return VerificationModeFactory.atLeast(minNumberOfInvocations);
}
Expand All @@ -3052,7 +3019,6 @@ public static VerificationMode atLeast(int minNumberOfInvocations) {
*
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode atMostOnce() {
return VerificationModeFactory.atMostOnce();
}
Expand All @@ -3069,7 +3035,6 @@ public static VerificationMode atMostOnce() {
*
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode atMost(int maxNumberOfInvocations) {
return VerificationModeFactory.atMost(maxNumberOfInvocations);
}
Expand All @@ -3087,7 +3052,6 @@ public static VerificationMode atMost(int maxNumberOfInvocations) {
* @param wantedNumberOfInvocations number of invocations to verify
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode calls(int wantedNumberOfInvocations) {
return VerificationModeFactory.calls(wantedNumberOfInvocations);
}
Expand All @@ -3108,7 +3072,6 @@ public static VerificationMode calls(int wantedNumberOfInvocations) {
*
* @return verification mode
*/
@CheckReturnValue
public static VerificationMode only() {
return VerificationModeFactory.only();
}
Expand Down Expand Up @@ -3141,7 +3104,6 @@ public static VerificationMode only() {
*
* @return object that allows fluent specification of the verification (times(x), atLeast(y), etc.)
*/
@CheckReturnValue
public static VerificationWithTimeout timeout(long millis) {
return new Timeout(millis, VerificationModeFactory.times(1));
}
Expand Down Expand Up @@ -3197,7 +3159,6 @@ public static VerificationWithTimeout timeout(long millis) {
*
* @return object that allows fluent specification of the verification
*/
@CheckReturnValue
public static VerificationAfterDelay after(long millis) {
return new After(millis, VerificationModeFactory.times(1));
}
Expand Down Expand Up @@ -3281,7 +3242,6 @@ public static void validateMockitoUsage() {
*
* @return mock settings instance with defaults.
*/
@CheckReturnValue
public static MockSettings withSettings() {
return new MockSettingsImpl().defaultAnswer(RETURNS_DEFAULTS);
}
Expand All @@ -3295,7 +3255,6 @@ public static MockSettings withSettings() {
* @return verification mode
* @since 2.1.0
*/
@CheckReturnValue
public static VerificationMode description(String description) {
return times(1).description(description);
}
Expand All @@ -3305,7 +3264,6 @@ public static VerificationMode description(String description) {
* An instance of {@code MockingDetails} can be retrieved via {@link #mockingDetails(Object)}.
*/
@Deprecated
@CheckReturnValue
static MockitoDebugger debug() {
return new MockitoDebuggerImpl();
}
Expand All @@ -3316,7 +3274,6 @@ static MockitoDebugger debug() {
* @since 2.1.0
*/
@Incubating
@CheckReturnValue
public static MockitoFramework framework() {
return new DefaultMockitoFramework();
}
Expand All @@ -3330,7 +3287,6 @@ public static MockitoFramework framework() {
* @since 2.7.0
*/
@Incubating
@CheckReturnValue
public static MockitoSessionBuilder mockitoSession() {
return new DefaultMockitoSessionBuilder();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/mockito/stubbing/Stubber.java
Expand Up @@ -4,6 +4,7 @@
*/
package org.mockito.stubbing;

import org.mockito.CheckReturnValue;
import org.mockito.Mockito;
import org.mockito.NotExtensible;

Expand Down Expand Up @@ -39,6 +40,7 @@
*
* See examples in javadoc for {@link Mockito}
*/
@CheckReturnValue
@SuppressWarnings("unchecked")
@NotExtensible
public interface Stubber extends BaseStubber {
Expand Down

0 comments on commit c0d0054

Please sign in to comment.