3.1. JVM Instrumentation
public class MyServiceTest {
@Mock
private ExternalService mockService;
private MyService tobeTested;
@Before
public void setup(){
MockitoAnnotations.openMocks(this);
tobeTested = new MyService(mockService);
}
@Test
public void testSomeMethod(){
Mockito.when(mockService.someMethod()).thenReturn("Mocked response");
String result = tobeTested.someMethod();
assertEquals("Mocked response", result);
}
}
<dependency>
<groupId>org.jmockring</groupId>
<artifactId>jmockring</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
groovy
testImplementation 'org.jmockring:jmockring:1.0.0'