Skip to content

Commit

Permalink
Adds withoutAnnotations parameter to @mock
Browse files Browse the repository at this point in the history
  • Loading branch information
wezleytsai committed Apr 5, 2023
1 parent f9fbf50 commit db8214f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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
*/
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

0 comments on commit db8214f

Please sign in to comment.