I am using Mockrunner to mock Sql DB for my unit tests. Following is my query:-
"select * from table where userId in (" + userIds + ")"
Now my userIds is state dependent. I don't need my test cases dependent on the arrangement inside the list - userIds. So I don't need exact match but regex matching. I have already enabled regex matching by below code:-
StatementResultSetHandler statementHandler = connection.getStatementResultSetHandler();
usersResult = statementHandler.createResultSet("users");
statementHandler.setUseRegularExpressions(true);
//How to write this regex query?
statementHandler.prepareResultSet("select * from table where userId in .*", campaignsResult);
But as it is noted, I have no idea about the regex syntax supported by Mockrunner.
Edit: I unable to match queries like "Select * from tables"
with "Select * from tab .*"
. So It has to do something with the way I using regex with Mockrunner
There are some helpful examples available here. For instance:
From this, I surmise that it's using standard Java regex syntax. In which case, you probably want:
...or perhaps more succinctly (and depending upon exactly how fine-grained your tests need to be):
The main caveat to be aware of when enabling the regex matching is that any literal special characters that you want in your query (such as
*
,(
, and)
literals) need to be escaped in your regex before it will work properly.