Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds withoutAnnotations parameter to @Mock #2965

Merged
merged 2 commits into from Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/org/mockito/Mock.java
Expand Up @@ -132,6 +132,13 @@
*/
String mockMaker() default "";

/**
* Mock will not attempt to preserve all annotation metadata, see {@link MockSettings#withoutAnnotations()}.
*
* @since 5.3.0
TimvdLippe marked this conversation as resolved.
Show resolved Hide resolved
*/
boolean withoutAnnotations() default false;

enum Strictness {

/**
Expand Down
Expand Up @@ -56,6 +56,9 @@ public static Object processAnnotationForMock(
if (!annotation.mockMaker().isEmpty()) {
mockSettings.mockMaker(annotation.mockMaker());
}
if (annotation.withoutAnnotations()) {
mockSettings.withoutAnnotations();
}

mockSettings.genericTypeToMock(genericType.get());

Expand Down
Expand Up @@ -88,6 +88,9 @@ public void shouldLookForAnnotatedMocksInSuperClasses() throws Exception {
@Mock(stubOnly = true)
IMethods stubOnly;

@Mock(withoutAnnotations = true)
IMethods withoutAnnotations;

@Test
public void shouldInitMocksWithGivenSettings() throws Exception {
assertEquals("i have a name", namedAndReturningMocks.toString());
Expand All @@ -99,6 +102,8 @@ public void shouldInitMocksWithGivenSettings() throws Exception {
assertTrue(hasExtraInterfaces instanceof List);
assertTrue(Mockito.mockingDetails(stubOnly).getMockCreationSettings().isStubOnly());

assertTrue(Mockito.mockingDetails(withoutAnnotations).getMockCreationSettings().isStripAnnotations());

assertEquals(0, noExtraConfig.intReturningMethod());
}

Expand Down