Wednesday, 28 August 2019

junit mockito function call verify

https://www.vogella.com/tutorials/Mockito/article.html#mockito_verify

the most useful funcdtions are :


verify(coDao).saveAll(cosCaptor.capture());

then you can use the Captor to capture the value when saveAll function is called.


List<CustomerSex> list = cosCaptor.getValue();


you need to make sure you have the captor setup:


@Captor

private ArgumentCaptor<List<CustomerSex>> cosCaptor;


you may need:


@Rule

public MockitoRule rule = MockitoJUnit.rule();


cannot remember detail....


note:  "verify(coDao).saveAll(cosCaptor.capture());"  this also expect saveAll just get called only one time.



expect to throw excepction:


doThrow(CannotGetMongoDbConnectionException.class).when(poDao).save(ArgumentMatchers.<OutboundSex>any());

No comments:

Post a comment