/
CustomMockMakerTest.java
50 lines (43 loc) · 1.6 KB
/
CustomMockMakerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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());
}
}