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 6338735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:30:22+00:00 2026-05-24T19:30:22+00:00

I would be very grateful if someone could help me break through this issue

  • 0

I would be very grateful if someone could help me break through this issue I’ve been battling with recently. I am trying to mock a method that takes a double and a Calendar, and returns an integer that is determined by the value of the Calendar. The mock definition is below:

new NonStrictExpectations()
    {
        // this is my class to be mocked
        Calculator growthCalc;
        {
            GregorianCalendar month = new GregorianCalendar(2010, 0, 1);

            for (int i = 0; i < 3; i++)
            {
                // mock the "applyInflation" method
                growthCalc.applyInflation(anyDouble, month);
                result = i;

                month = (GregorianCalendar) month.clone();  //AAA
                month.add(Calendar.MONTH, 1);
            }

            growthCalc.toString();
            result = "Mocked Calculator";
        }
    };

The mock is set-up (calling toString() returns the correct text), but the applyInflation method returns zero for everything other than the last iteration of the loop above (i.e. it returns 2 when you pass-in the month new GregorianCalendar(2010,2,1).

I have concluded that the line marked AAA isn’t having the effect I think it should. It doesn’t seem to be changing the pointer to point to a new copy of “month” that I can modify without impacting the contents of the “month” that the mock expectation has set. Either that, or JMockit isn’t recording the mock the way I thought.

Please help! Please tell me where I’m going wrong. I would really like to know what’s up here as either my understanding of Java is fundamentally flawed or the JMockit implementation doesn’t behave the way it “should” (according to me 🙂 ). Or I’ve made a real schoolboy error that two evenings of starting haven’t spotted…

Thank you.

  • 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-24T19:30:23+00:00Added an answer on May 24, 2026 at 7:30 pm

    Your test is perfectly correct. It only fails because of a bug in JMockit, which I am fixing right away. Sorry for the trouble!

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

Sidebar

Related Questions

I would be so very grateful if someone could help me out! I have
This is driving me crazy. Very grateful if someone could help me out! Problem:
I would be very grateful if someone could explain if it is possible to
Would very much appreciate any help or hint on were to go next. I'm
have small problem, and would very much appreciate help :) I should convert byte
I've recently begun working on a very large, high traffic website. We would very
This would be very handy as typecasting gets boring fast.
I thought this would be very easy. I downloaded the JDK, extracted src.zip, modified
I really hope someone will be able to help me out with this. I
I was wondering if someone could help me with a bit of javascript and

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.