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

  • SEARCH
  • Home
  • 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 7052067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:20:21+00:00 2026-05-28T03:20:21+00:00

I made a simple Test Class to simplify my actual problem : public class

  • 0

I made a simple Test Class to simplify my actual problem :

public class BidonTest {

@Mocked
IBidon ibidon;

@Mocked
IBidon ibidon2;

@Mocked
Bidon bidon;

@Mocked
Bidon bidon2;

@Test
public void testBidon(){
    new NonStrictExpectations(2, Bidon.class){
        {
            ibidon.doIt(); result = "i: coco";
            ibidon2.doIt(); result = "i: ismael et jordan";
            bidon.doIt(); result = "c: coco";
            bidon2.doIt(); result = "c: ismael et jordan";
        }
    };
    System.out.println(ibidon.doIt());
    System.out.println(ibidon2.doIt());
    System.out.println(bidon.doIt());
    System.out.println(bidon2.doIt());
}


public interface IBidon{
    public String doIt();
}

public class Bidon implements IBidon{
    @Override
    public String doIt(){
        return "toto";
    }
}

}

Below, the test result :

i: coco
i: coco
c: coco
c: ismael et jordan

My first question is : why ibidon2 returns “coco” ? (even if i have few ideas, but maybe someone here is a JMockit expert 😀 )
My second question is : how can i change it to make it return “ismael et jordan” ?

  • 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-28T03:20:22+00:00Added an answer on May 28, 2026 at 3:20 am

    It works fine for me, after fixing your source.

    package main;
    
    import mockit.Mocked;
    import mockit.NonStrictExpectations;
    import org.junit.Test;
    
    public class TestBidon {
        @Mocked IBidon ibidon;
        @Mocked IBidon ibidon2;
        @Mocked Bidon bidon;
        @Mocked Bidon bidon2;
    
        @Test public void testBidon() {
            new NonStrictExpectations() {{
                ibidon.doIt();  result = "i: coco";
                ibidon2.doIt(); result = "i: ismael et jordan";
                bidon.doIt();   result = "c: coco";
                bidon2.doIt();  result = "c: ismael et jordan";
            }};
    
            System.out.println(ibidon.doIt());
            System.out.println(ibidon2.doIt());
            System.out.println(bidon.doIt());
            System.out.println(bidon2.doIt());
        }
    }
    

    Produces:

    i: coco
    i: ismael et jordan
    c: coco
    c: ismael et jordan
    

    What version are you using? The above was via 0.999.12.

    (Also not sure why you’re using an invocation count here since it depends on being a NonStrictInvocation to avoid the assert.)

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

Sidebar

Related Questions

I'm using AbstractTransactionalJUnit4SpringContextTests to run a simple test: public class MyTests extends AbstractTransactionalJUnit4SpringContextTests {
I have made a simple test application for the issue, two winforms each containing
I'm putting together a simple test made up of two tutorials available online for
I have a little trouble getting gettext to work. I made a simple test
I have made a simple program with : working with files(read write) end class
I have made a simple example application to test Fluent NHibernate with the automapping
I have made a simple test applet that has a red background and a
I was trying to learn CoffeeScript, and made this simple class as first try:
I am playing around with MbUnit and Rhino Mocks and made a simple test.
Made a simple test project where i try to bind to a xmldatasource in

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.