dimanche 10 janvier 2021

I couldn't understand the logic of willThrow, doThrow in junit mockito testing

I have this piece of simple code but couldn't understand its logic and meaning.

void findByIdThrows(){
    given(addressRepository.findById(1)).willThrow(new RuntimeException("boom iii"));

    assertThrows(RuntimeException.class, () -> servic.findById(1));

    then(addressRepository).should().findById(1);
}

Does it mean: if you got a RuntimeException during the finding of the address with id #1 then assert that I'll give the RuntimeException?

What does the last line (then....) do exactly?

Aucun commentaire:

Enregistrer un commentaire