2

i have the method in springboot that consume a endpoint

public Mono<Void> mesaVisadoCalculadoraNotificar(NotificarIn in) {
 setTimeoutErrorCode("MVC-01");
 return Mono.fromCallable(() -> {
 WebTarget path = target.path(MesaVisadoCalculadora.NOTIFICAR.getUri());
 
 return restHelper.performRequest(path, in, new GenericType<Void>(){}, HttpAction.POST);
 });
 }
}

and this test

@Test
public void mesavisadoCalculadoraNotificaTest(){
 when(target.path(Mockito.anyString())).thenReturn(target);
 when(restHelper.performRequest(Mockito.any(WebTarget.class), Mockito.any(), Mockito.any(GenericType.class),Mockito.any(HttpAction.class))).thenReturn(Mono.empty());
 Mono<Void> promise = agent.mesaVisadoCalculadoraNotificar(in);
 promise.block()
 Assertions.assertNotNull(promise);
 
}

but in the line promise.block() return ClassCastException, any idea what it might be,

this is a error in console:

MesavisadoCalculadoraAgentTest > mesavisadoCalculadoraNotificaTest() FAILED
 java.lang.ClassCastException at MesavisadoCalculadoraAgentTest.java:65
java.lang.ClassCastException: reactor.core.publisher.MonoIgnorePublisher cannot be cast to java.lang.Void
 at infrastructure.agent.apimesavisadocalculadora.MesaVisadoCalculadoraAgent.lambda$mesaVisadoCalculadoraNotificar0ドル(MesaVisadoCalculadoraAgent.java:45)
 at reactor.core.publisher.MonoCallable.block(MonoCallable.java:81)
 at reactor.core.publisher.MonoCallable.block(MonoCallable.java:74)
 at infrastructure.agent.apimesavisadocalculadora.MesavisadoCalculadoraAgentTest.mesavisadoCalculadoraNotificaTest(MesavisadoCalculadoraAgentTest.java:65)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
 at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
Luke Woodward
65.4k16 gold badges95 silver badges108 bronze badges
asked Dec 5, 2025 at 16:10
5
  • Please edit your question and add the full exception details. Commented Dec 5, 2025 at 16:29
  • It doesn't provide much information. Commented Dec 5, 2025 at 16:54
  • 1
    @RomanGajardoRobles You need to provide enough information so others can replicate your exact problem. Commented Dec 5, 2025 at 16:56
  • @Andre Henle, Update the error details Commented Dec 5, 2025 at 17:19
  • What's the signature of restHelper.performRequest? Does it return a Mono<?>? Commented Dec 7, 2025 at 16:51

1 Answer 1

1

I think the problem is that:

  • you are setting up your restClient.performRequest method to return a Mono<Void>,
  • if you have a callable that returns a value of type T, then wrapping this callable in Mono.fromCallable(...) returns a value of type Mono<T>.

If you want Mono.fromCallable(...) to return Mono<Void>, then the callable needs to return Void. Therefore, the inner callable should return null rather than a Mono.

Try replacing the Mono.empty() in your mock setup with null.

Disclaimer: I haven't tested this.

answered Dec 5, 2025 at 18:36
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.