Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VERTX JUNIT5 Issue Mocking Static Classes #124

Closed
DMIC123 opened this issue Dec 22, 2022 · 3 comments
Closed

VERTX JUNIT5 Issue Mocking Static Classes #124

DMIC123 opened this issue Dec 22, 2022 · 3 comments
Labels

Comments

@DMIC123
Copy link

DMIC123 commented Dec 22, 2022

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 {

@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

@DMIC123 DMIC123 added the bug label Dec 22, 2022
@DMIC123
Copy link
Author

DMIC123 commented Dec 22, 2022

vertx-junit5 version is 4.3.7, mockito-inline is 3.8.0,junit-jupiter-api is 5.8.2,mockito-junit-jupiter is 2.23.0

@tsegismont tsegismont added question and removed bug labels Jan 4, 2023
@tsegismont
Copy link
Contributor

This does not look like a bug but rather a question about Mockito static mocking. I'm not sure this is the best place to ask for help about it.

Perhaps if you modify your snippets to show an easily reproducible case someone will try it out.

@tsegismont tsegismont closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2023
@DMIC123
Copy link
Author

DMIC123 commented Jan 4, 2023

I have mentioned the above steps . Unable to figure out a way . Earlier with JUNIT4 we could easily mock such scenarios with PowerMockito.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants