Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Multiplying mocked object method parameters
public class Card
{

public double roundMoney(double currencyValue , int digits) {
//some logic for rounding which includes heavy service calling
} 

}

Now I want to mock the class and whenever the roundMoney methods is called with parameters I want it to return the product of the parameters

Card mycard = mock(Card.class);
when(mycard.roundMoney(anyDouble(), anyInt()).thenReturn( anyDouble() * anyInt() ));

How can I achieve this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use thenAnswer instead of thenReturn? The answer implementation has access to the parameter values being passed.

See: Making a mocked method return an argument that was passed to it

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!