How to write code coverage for lambda preparestatement

Sathish David  Kumar N
Sathish David  Kumar N used Ask the Experts™
on
How to right code coverage for preparedStatment lambda action

this.jdbcTemplate.query(sqlQuery, (PreparedStatementSetter) ps -> {
            ps.setTimestamp(1, startTime);
            ps.setTimestamp(2, endTime);
            ps.setString(3, status);
            ps.setString(4, Constants.SUCCESS);
            }, new CountResultSet()).intValue();
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
How to right code coverage

What do you mean by this? It doesn't really make much sense to me.
sorry How to write code coverage for Lambda expression
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
Ok, I thought that you may have meant "write" too, but still it doesn't make any sense. You don't "write" code coverage. Your code is either covered by test case(s) or not. Since I am guessing it may just be a language issue, can you try asking for what you want in another way?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

yes your correct .

example

return this.jdbcTemplate.query(sqlQuery, (PreparedStatementSetter) ps -> {
            ps.setTimestamp(1, startTime);
            ps.setTimestamp(2, endTime);
 // still 5 more line
              }, new CountResultSet()).intValue();

My test case does not cover
       ps.setTimestamp(1, startTime);
            ps.setTimestamp(2, endTime);
 // still 5 more line

I need to cover this 7 line how to do that
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
As long as your test case is calling the actual query() method call, then PreparedStatementSetter lines will get called to.

Perhaps your code coverage tool is just not indicating what lines have been called properly, and maybe this is because it can't handle the lambda syntax properly. Just as a verification of the above, if you change your code from a lambda to the "old" way using an anonymous inner class, do the lines show up as being covered? If so, you may need to see if your code coverage tool has an update that might be able to handle lambda's properly.
I found myself

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial