You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am unable to mock static classes for Vertx JUNIT5. Added all dependencies as well in pom.xml for Vertx JUNIT5. (junit-jupiter-api,junit-jupiter-engine,mockito-inline,mockito-core,mockito-junit-jupiter,vertx-junit5)
@BeforeEach
public void beforeEach(Vertx vertx,VertxTestContext ctx)
{
vertx=Vertx.vertx(options);
Mockito.mockstatic(Placeholder.java);
when (Placeholder.getValue(Mockito.anyString()).thenReturn("value")
vertx.deployVerticle(MyVerticle.class.getaName()).onSuccess(ok->ctx.completeNow())
}
}
Main Class:
MyVerticle extends AbstractVerticle{
@Override
public void start(Promise appState)
{ ….
Placeholder.getValue(“MyValue”); // this is always returning NULL even this is mocked in test class
…
}
}
When verticle is deployed the start method MyVerticle Class is invoked. But even though Placeholder class is mocked then also Placeholder.getValue("MyValue") is returned as NULL.
Unable to figure out how to do that mocking. I have tried with Mocked Static as well but that also does not help. To me it looks like when vertx deploy verticle is called then the start method is not being invoked directly but it will be invoked by Vertx. so somewhere that scope is lost and whatever mocking is done in test class is lost. Unable to figure out a way. Any help is appreciated
The text was updated successfully, but these errors were encountered:
I am unable to mock static classes for Vertx JUNIT5. Added all dependencies as well in pom.xml for Vertx JUNIT5. (junit-jupiter-api,junit-jupiter-engine,mockito-inline,mockito-core,mockito-junit-jupiter,vertx-junit5)
Code Snippet:
@ExtendWith (VertxExtension.class)
VertxTestClass {
}
Main Class:
MyVerticle extends AbstractVerticle{
public void start(Promise appState)
{ ….
}
When verticle is deployed the start method MyVerticle Class is invoked. But even though Placeholder class is mocked then also Placeholder.getValue("MyValue") is returned as NULL.
Unable to figure out how to do that mocking. I have tried with Mocked Static as well but that also does not help. To me it looks like when vertx deploy verticle is called then the start method is not being invoked directly but it will be invoked by Vertx. so somewhere that scope is lost and whatever mocking is done in test class is lost. Unable to figure out a way. Any help is appreciated
The text was updated successfully, but these errors were encountered: