Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Junit testcase for Asynchronous calll

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I m new to vertex and below is the code which i have written for an update statement to db, i need to mock this upsertQuery method and write Junit for this, can some body help me on this.

 
Marshal
Posts: 3489
494
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The documentation for Vert.x JUnit 5 integration might help.
 
siddu math
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ron i have checked this page but i want to mock this Db call, i m not able to get it .
 
Saloon Keeper
Posts: 12864
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that the only thing a mock of that code should do is return a Future<StatusCode>. You can mock whatever interface you were implementing to return a hardcoded CompletableFuture.completedFuture(SUCCESS), completedFuture(BAD_DATA) or completedFuture(RETRY).
 
siddu math
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stephan,but i m not able to figure it out.Its giving me error.

   Mockito.when(client.upsertQuery(Mockito.any(),Mockito.any()).onSuccess(Mockito.any())).thenReturn(CompletableFuture.completedFuture(StatusCode.SUCCESS));

StatusCode is an Enum class.

 
Stephan van Hulst
Saloon Keeper
Posts: 12864
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're mocking onSuccess() and trying to return a Future from it. onSuccess() has a void return type.

Just mock upsertQuery():
 
siddu math
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stephan

i tried but gives error because client .upsertQuery has written type Future <JsonObject>.

So the code is some thing like


 
Stephan van Hulst
Saloon Keeper
Posts: 12864
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, I couldn't see what the return type of upsertQuery() was.
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic