I would like to now, if it is possible to mock a class like
public class MyClass{
...
}
Our business logic create this object with new myClass()
somewhere in the code and therefore I don't have access to the created object to mock those methods. Is there a way to replace the whole class or to overwrite those methods. I'm using mockito and I only found examples to do this like
@Test
public void myTest{
MyClass myClass = Mockito.mock(MyClass.class);
Mockito.when(myClass.myMethod()).thenReturn("hello World");
...
}
We can't use PowerMock because it isn't compatible with our test environment.
Any suggestions are welcome.