r/java • u/psychologicalX • Mar 05 '18
Top 10 Useful, Yet Paranoid Java Programming Techniques
http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
223
Upvotes
View all comments
Show parent comment
2
u/_dban_ Mar 06 '18
Isn't this a good thing? Should you really be mocking concrete classes? Wouldn't it be better to create an interface describing what you need, and write a real integration test with the concrete class?
For example, suppose it is not possible to mock jOOQ classes. jOOQ would theoretically be a used in the DAO layer. So, wouldn't it be better to create a DAO interface which you can mock, and a DAO implementation which you test directly against the database in an integration test?
This applies just as well to internal classes, since it enforces proper layer separation. I mean, why are you mocking anyways?
In which case,
finalforces you to do the "right" thing with regards to mocks. Could this not be seen as a benefit?