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
Roman Gajardo Robles
235 bronze badges
1 Answer 1
I think the problem is that:
- you are setting up your
restClient.performRequestmethod to return aMono<Void>, - if you have a callable that returns a value of type
T, then wrapping this callable inMono.fromCallable(...)returns a value of typeMono<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
Luke Woodward
65.4k16 gold badges95 silver badges108 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-java
restHelper.performRequest? Does it return aMono<?>?