'how to test a reactive method?

This method its from exampleRepositoryImpl.

@Override
    public Mono<List<String>> getSalers(int value) {
        logger.info("ExampleRepositoryImpl::getSalers::START");
        Criteria criteria = new Criteria();
        criteria = criteria.where(salers).is(value);
        Query query = new Query();
        query.addCriteria(criteria);
        logger.info("ExampleRepositoryImpl::getSalers::END");
        return mongo.findDistinct(query,"salers",Example.class,String.class).collectList()
                .switchIfEmpty(Mono.error(ObjectNotFoundException::new));
    }

and my test class it's the following, is only the mock of the class...

EDIT: Add code to the test.

@ExtendWith(MockitoExtension.class)
public class ExampleTest {

    @Mock
    ReactiveMongoOperations mongo;

    ExampleRepositoryImpl exampleRepository;

    @BeforeEach
    void beforeEach(){
        ExampleRepositoryImpl examImpl = new ExampleRepositoryImpl(mongo);
        exampleRepository = spy(examImpl);
        reset(exampleRepository, mongo);
    }
    
    @Test
    void getSalerTest(){
      Criteria criteria = new Criteria();
        criteria = criteria.where("salers").is(5);
        Query query = new Query();
        query.addCriteria(criteria);

        when(mongo.findDistinct(query, "salers",Example.class,String.class))
                .thenReturn(Flux.just());

        verify(mongo.findDistinct(query, "salers",Example.class,String.class));
    }


Edited to add code to the test void getSalerTest(){};



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source