Hi Team,
How to mock the method which is in the same class we are testing?
PFB the sample test case which I’m trying in my project:
class SampleAction { (generated from stateless action)
public handleEvent() {
…
registry();
}
public registry() {
…
}
}
Test case
@Test
void handleEventTest() {
final SampleAction mockA = Mockito.mock(SampleAction .class);
final MockRegistry mockService = MockRegistry.create().withMock(SampleAction .class, mockA);
when(mockA .registry()).thenReturn(“test”));
final SampleActionTestKit testKit = SampleActionATestKit.of(SampleAction::new, mockService);
final ActionResult result = testKit.handleEvent();
}
When I try this, it is always going inside the actual registry method, instead of mocked one.
Can someone please help to mock the method which is present inside the same class where the testing method present