• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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

 
Ranch Hand
Posts: 1029
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: 94
1
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
 
Sheriff
Posts: 9059
667
Mac OS X Spring 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
Sheriff
Posts: 9059
667
Mac OS X Spring 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: 1029
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.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic