Link to home
Start Free TrialLog in
Avatar of Sathish David  Kumar N
Sathish David Kumar NFlag for India

asked on

How to write code coverage for lambda preparestatement

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();
Avatar of mccarl
mccarl
Flag of Australia image

How to right code coverage

What do you mean by this? It doesn't really make much sense to me.
Avatar of Sathish David  Kumar N

ASKER

sorry How to write code coverage for Lambda expression
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?
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
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.
ASKER CERTIFIED SOLUTION
Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial