jeudi 22 février 2018

Mockito verifying method invocation without using equals method

While using Spock i can do something like this:

when:

12.times {mailSender.send("blabla", "subject", "content")}

then:

12 * javaMailSender.send(_)

When i tried to do same in Mockito:

verify(javaMailSender,times(12)).send(any(SimpleMailMessage.class))

I got an error that SimpleMailMessage has null values, so i had to initialize it in test:

SimpleMailMessage simpleMailMessage = new SimpleMailMessage()
simpleMailMessage.setTo("blablabla")
simpleMailMessage.subject = "subject"
simpleMailMessage.text = "content"
verify(javaMailSender,times(12)).send(simpleMailMessage))

Now it works but it's a large workload and i really don't care about equality. What if SimpleMailMessage will have much more arguments or another objects with another arguments, meh. Is there any way to check that send method was just called X times?

Aucun commentaire:

Enregistrer un commentaire