Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2626 : Introduce MockSettings.mockMaker
- Loading branch information
1 parent
e962176
commit f58affa
Showing
13 changed files
with
158 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2022 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker; | ||
import org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker; | ||
|
||
import java.util.Arrays; | ||
|
||
public final class CustomMockMakerTest { | ||
@Test | ||
public void test_custom_mock_maker() throws Exception { | ||
class TestClass { | ||
String noop() { | ||
return "UNUSED"; | ||
} | ||
|
||
final String finalMethod() { | ||
noop(); | ||
return "ORIGINAL"; | ||
} | ||
} | ||
|
||
TestClass inlineMock = | ||
Mockito.mock( | ||
TestClass.class, | ||
Mockito.withSettings() | ||
.outerInstance(this) | ||
.useConstructor() | ||
.mockMaker(InlineByteBuddyMockMaker.class)); | ||
TestClass subclassMock = | ||
Mockito.mock( | ||
TestClass.class, | ||
Mockito.withSettings() | ||
.outerInstance(this) | ||
.useConstructor() | ||
.mockMaker(ByteBuddyMockMaker.class)); | ||
|
||
for (TestClass mock : Arrays.asList(inlineMock, subclassMock)) { | ||
Mockito.when(mock.finalMethod()).thenReturn("MOCKED"); | ||
} | ||
|
||
Assert.assertEquals("MOCKED", inlineMock.finalMethod()); | ||
Assert.assertEquals("ORIGINAL", subclassMock.finalMethod()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters