Actually this is for code coverage and I’m having a hard time, covering to catch statements.
Any ideas?
for example:
I want my selectSomethingBySomething() method (which selects from db) to throw an SQLException which is pretty hard on a test method without actually touching the actual source code. Given also the constraint that what I can only control is the parameters for the WHERE clause.
You need to first mock the class containing
selectSomethingBySomething()and then record this behavior. In mockito you’ll say:Then inject
someDaoMockinto your class under test and when it callssomeDaoMock.selectSomethingBySomething()it’ll throw previously chosen exception.