Is there a way in junit to test rowlocked exception?
If you mock your database dependencies, then you can have your mock object throw the locked row exception.
As you'll have removed your direct dependency on the database, the test should run faster, and you'd be less prone to "flickering tests" due to database problems such as the database not being a available or something similar.
Also, this way, you are only testing your code, and nothing to do with the database - it is implementation agnostic. Should you choose to change database vendor in the future, this (a) shouldn't matter to your code and (b) your test doesn't care what database it is using.
Some example mocking frameworks to get you started:
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