I have implemented the Visitors of JSqlparser to parse SQL queries. The code is working absolutely fine. I am not sure how to do unit testing for those visitors. For example I have the following sql statement:
Select a.a1, a.a2 from foo as a
To parse it I have implemented StatementVisitor interface and my code goes like this:
public class StmntVisitorImpl implements StatementVisitor {
@Override
public void visit(Select select) {
LOG.debug("Begin Select visit : "+select.toString());
SelectVisitor selectVisitor = new SelectVisitorImpl();
select.getSelectBody().accept(selectVisitor);
if(select.getWithItemsList()!=null && !select.getWithItemsList().isEmpty()){
select.getWithItemsList().stream()
.forEach(wth -> wth.accept(selectVisitor));
}
}
@Override
public void visit(Delete delete) {}
@Override
public void visit(Update update) {}
@Override
public void visit(Insert insert) {}
@Override
public void visit(Replace replace) {}
@Override
public void visit(Drop drop) {}
}
Then I am calling it in another class as follows:
String sql = "Select a.a1, a.a2 from foo as a";
CCJSqlParserManager parserManager = new CCJSqlParserManager();
StatementVisitor statementVisitor = new StmntVisitorImpl ();
Statement sqlStatement = parserManager.parse(new StringReader(sql));
sqlStatement.accept(statementVisitor);
I want to write unit test cases for my StmntVisitorImpl, SelectVisitorImpl and other classes implementing the Visitor interfaces given by JSqlparser. How should I do it?