Issue
Want to write junit5 test case/coverage for code inside execute method as below are my sample(dummy) src class, actual methods contains project lot of business logic.
If i mock the taskExecutor, it bypass whole execute() with dummy values.
Any suggestion how can i cover run method in attached code, Below are sample test case
Solution
You can outsource your in-lined Runnable
to its own class like:
public class MyRunnable implements Runnable {
private final JdbcTemplate jdbcTemplate;
public MyRunnable(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public void run() {
// ... do your logic here
}
}
and then write a unit test for this class to verify its behaviour in isolation.
Inside your RedisScheduler
you can then make use of your new class:
taskExecutor.execute(new MyRunnable(jdbcTemplate));
Answered By - rieckpil