For example I have the following handler:
@Component
public class MyHandler {
@AutoWired
private MyDependency myDependency;
public void someMethod(Object parameter) {
...
ThirdPartyClass thirdPartyObject = new ThirdPartyClass(parameter);
thirdPartyObject.unnecessaryMethod();
...
}
}
To test this, I want to write something like this:
@RunWith(MockitoJUnitRunner.class}
class MyHandlerTest {
@InjectMocks
MyHandler myHandler;
@Mock
MyDependency myDependency;
@Test
public void testSomeMethod() {
...
myHandler.someMethor(parameter);
...
}
}
I want to avoid calling unnecessaryMethod()
. Is there any way to do this?
If unnecessaryMethod()
is static then I can use PowerMockito to mock it, but can PowerMockito help in my situation?