I want to test my code but I am noticing that some business logic classes demand on alot of objects with alot of state. But actually the communication between these classes is limited to 1 or 2 methods.
Is it good style if I create an interface with these 2 methods and in my test just create a mock object which does nothing?
The code will then have alot more interfaces which are not really needed, that's why I'm not sure if it's a good idea?
Although having interfaces is a good idea, you don't need interfaces to do mocking. EasyMock, Mockito and PowerMock all allow mocking of concrete classes. So given that, you can leave the code as is and use Mockito (my personal favorite) to mock the injected classes.
FYI, the mocks shouldn't "does nothing". They should be tested with each possible return value and each possible exception thrown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With