Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock a method that returns `Mono<Void>`

How to mock a method that returns Mono<Void>?

I have this method that returns Mono<Void>

public Mono<Void> deleteMethod(Post post) {

        return statusRepository.delete(post);
    }

In my test class I want to do something like this

given(statusRepository.delete(any(Post.class))).willReturn(Mono.empty());

Is there any better way to do this?

Can someone help me?

Thanks.

like image 392
user3595026 Avatar asked Jul 23 '19 19:07

user3595026


1 Answers

This is possible using Mockito.when:

Mockito.when(statusRepository.delete(any(Post.class)).thenReturn(Mono.empty());

...call the method and verify...

Mockito.verify(statusRepository).delete(any(Post.class));
like image 192
Gustavo Ballesté Avatar answered Oct 10 '22 19:10

Gustavo Ballesté