• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Mockito Mock on Static method of called class from calling class method

 
Ranch Hand
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have processPaymentDetails method like below for which trying to write unit test using mockito. Since PaymentAdapter class has static method parsePaymentInformatin getting called directly on class name without autowire not sure if i can use Mock for PaymentAdapter



Can you please advise. Any good links to refer these mockito related examples, concepts?
 
Ranch Hand
Posts: 86
Spring Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Mockito 3.4.0, it is possible to mock static methods
https://www.baeldung.com/mockito-mock-static-methods
 
Marshal
Posts: 8829
631
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sai rama krishna wrote:Since PaymentAdapter class has static method parsePaymentInformatin getting called directly on class name without autowire not sure if i can use Mock for PaymentAdapter


Why do you want to mock it in the first place?

sai rama krishna wrote:


Every time I see such variables names (in this case parameters), I freak out. What is the rationale behind naming pmtSt and not payment then pmtType and not paymentType? PmtSt type is also cryptic which very likely makes all code cryptic.
 
Liutauras Vilda
Marshal
Posts: 8829
631
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sai rama krishna wrote:


Here is another one.. Please, try to be disciplined, if that's not you, try to champion such values in the team, so code would be better readable. That is very important!
 
sai rama krishna
Ranch Hand
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I some time use mock for inject mock and vice versa and try to use mock where not needed. Any good books or resources to make my unit testing especially mockito concepts more deeper, stronger.
 
Right! We're on it! Let's get to work tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic