I have a Java application that talks to a MySQL database using Spring JDBC Templates. In one of my tests I want to simulate a table not being there in an integration test, however I cannot actually temporarily drop/recreate or rename the table in our testing database for a variety of reasons.
I also don’t want to mock out the particular DAO method call that would hit the table that throws the error in case going forward we use other methods. I want to do something like intercept the sql before it goes off to the database and replace the table name (if present) with a bogus name–or something else to the same effect.
Test driven development for the win!
If interception is what you want, using aspects could be a solution.
You’d have to create a pointcut intercepting, e.g., the call to the specific method “sending the sql before it goes off to the database”.
Then you can create before/around advice, in which you can manipulate the data (“replace the table name with a bogus name”) before you proceed with the call
See aspectj, as well as Aspect Oriented Programming with Spring.