How to test a function returning single value like expected onNext actual onComplete.?

343 views Asked by At

I am writing the test cases for one of the Spring Webflux function as:

public Mono<ClassTempKey> getKey(Param param1) {
    return getKeyFromBaseClass();
}

StepVerifier.create(class.getKey(param1)
   .assertNext(key -> {
      assertThat(key.getValue().isEqualTo(value);
   }).verifyComplete();

I am getting the following output

expected: onNext()  actual: onComplete()

The method will return a single key value. Not sure where I am doing wrong.

1

There are 1 answers

0
kerbermeister On BEST ANSWER

That would be clearer if you'd post the actual code of getKeyFromBaseClass() method.

But it looks like that method returns empty Mono, without any value. In reactor empty mono without additional handling returns onComplete signal (not onNext), so you can see it in your test.