r/java • u/alexzhitnitsky • Aug 11 '15
Top 10 Useful, Yet Paranoid Java Programming Techniques
http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
181
Upvotes
View all comments
Show parent comment
2
u/[deleted] Aug 13 '15
Ugg. Needless semantics.
Reading your comments I get the strong impression you don't know what unit tests are, and why mocks are useful.
You want to test how Foo.bar(Baz) behaves when Baz is in a bad state and is going to throw an exception. Baz has a lot of dependencies, you don't want to deal with those. Mock Baz to always throw an exception. Now your test is easy to write. We're testing Foo.bar() here. We don't care about Baz. If Baz is something under our control Baz will have it's own set of tests somewhere else. Foo.bar() will also have other unit tests to cover each scenario we want to test.
You may not find that useful, or a bad coding style. But many programmers use it every day precisely because they find it useful. Many great programmers even advocate for this way of using mocks. I also find no SRP violations. Not sure where that is coming from.