Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:44:44+00:00 2026-05-24T13:44:44+00:00

I have this method to test : public static Date getDateSinceUTC(CstOrderBean orderBean) { int

  • 0

I have this method to test :

public static Date getDateSinceUTC(CstOrderBean orderBean) {

    int year = orderBean.getDeadLineYear();
    int month = orderBean.getDeadLineMonth();
    int day = orderBean.getDeadLineDay();
    int hour = orderBean.getDeadLineHour();
    int minute = orderBean.getDeadLineMinute();
    String ap = orderBean.getDeadLineAmPm() == 1 ? "PM" : "AM";

    //TODO   AM=0, PM=1  comes from html form
    SimpleDateFormat df = new SimpleDateFormat("yyyy:MM:dd:hh:mm:aa");
    String stringDate = stringifyIntegers(":", year, month, day, hour, minute); 
    stringDate = stringDate.concat(ap);

    Date date;
    try {
        date = df.parse(stringDate);
    } catch (ParseException e) {
        throw new Error("Parsing date from html form failed", e);
    }
    return date;
}

Where CstOrderBean needs to be mocked by Mockito because it is not a POJO (some static initializations etc. – from source code generator). But I need to run the method xxx times, hence set the mocks with many data combinations

I could use TestNG’s @DataProvider to do that. But I’m not sure how to do that, I guess that :

    when(ob.getDeadLineYear()).thenReturn(1, 2, 3);
     ....

in loop is a bad idea, isn’t it ? Is the correct way of doing this to create xx mocks and initialize them like that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:44:45+00:00Added an answer on May 24, 2026 at 1:44 pm

    Each test should get their own mock that preferably does not have variable data. If you use several different return values from the same mock object then the testing has to be white-box testing as the test is coupled with the number of calls to a mocked method instead of the result of the method under test.

    That said, you are able to define a set of return values with calling thenReturn repeatedly or by defining the return values as varargs

    when(ob.getDeadLineYear()).thenReturn(someValue, anotherValue, ..., ultimateValue);
    

    This might be cleaner as you should probably control the values that the mock returns anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
I have this factory method in java: public static Properties getConfigFactory() throws ClassNotFoundException, IOException
I have a method: public static IEnumerable<Datarow> getInfo (string test) { some functionality and
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have this method: public bool CanExecute() And after 70 commits, I added an
Is it possible to rewrite this extension method without the parameter? public static string
I have an Java class with a static final method getAll: public static final
I have this unit test: public void testDeEscapeResponse() { final String[] inputs = new
I have read this post about how to test private methods. I usually do
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.