java - How can I unit test that I received correct PreparedStatement? -


i want pass in suitable object verify method, not any().

is there way it?

i cannot take , copy lambda method , pass results verify. doesn't work because lambdas cannot tested directly.

my unit test not close testing anything:

    @test public void testruntrigger() {     campaigntrigger.updatecampaignstatus();      verify(jdbctemplate).update(any(preparedstatementcreator.class));     assertequals("update campaign set state = 'finished'  state in ('paused','created','running') , campaign_end < ? ", campaigntrigger.update_campaign_sql); } 

and class i'm testing :

@component @slf4j public class campaigntrigger { final string update_campaign_sql = string.format("update campaign set state = '%s' " +                 " state in (%s) , campaign_end < ? ", finished,         stream.of(paused, created, running)                 .map(campaignstate::name)                 .collect(collectors.joining("','", "'", "'")));  @autowired private jdbctemplate jdbctemplate;  @scheduled(cron = "${lotto.triggers.campaign}") @timed void updatecampaignstatus() {     jdbctemplate.update(con -> {         preparedstatement callablestatement = con.preparestatement(update_campaign_sql);         callablestatement.settimestamp(1,  timestamp.valueof(localdatetime.now()));         log.debug("updating campaigns statuses.");         return callablestatement;     }); } 

any advice, or theoretical knowledge not way highly appreciate.

you shouldn't mock code don't control. mock code have tests, because when mocking assuming know (i.e. define) how mocked class works.

here, have no idea how jdbctemplate works , whether calling lambda think does.

testing code code don't control point of integration tests. i.e. should test campaigntrigger real database (or in-memory one) , without mocking jdbctemplate.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -