Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial mocking of a delegate class #268

Closed
oazmon opened this issue Mar 15, 2016 · 2 comments
Closed

Partial mocking of a delegate class #268

oazmon opened this issue Mar 15, 2016 · 2 comments
Assignees
Labels

Comments

@oazmon
Copy link

oazmon commented Mar 15, 2016

Please provide the following information:

  • Version of JMockit that was used: 1,21

  • Description of the problem or enhancement request:
    When attempting to test a delegate class, and an highly simplified case would be:
    public static class MyClass implements Runnable {
    private Runnable r;

    public MyClass(Runnable r) {
        this.r = r;
    }
    
    public Runnable getRun() {
        return r;
    }
    
    public void run() {
        getRun().run();
    }
    

    }

And attempting to perform a partial mock on the class to isolate in the above example the run() method from the getRun() method, and example test would be:

@Test
public void testMe(final @Injectable Runnable mockedRunnable) {
    final MyClass instance = new MyClass(mockedRunnable);
    new Expectations(instance) {
        {
            instance.getRun();
            result = new Runnable() {
                public void run() {
                    System.out.print("Expectation runnable");
                }
            };
        }
    };

    instance.run();
}

One gets: java.lang.IllegalArgumentException: Already mocked: interface java.lang.Runnable
Removing the extends Runnable on the class solves the error, but makes the delegate useless.

Any ideas?

@rliesenfeld rliesenfeld self-assigned this Mar 16, 2016
@rliesenfeld
Copy link
Member

It's a bug; should be fixed by the time the next release is out.

@oazmon
Copy link
Author

oazmon commented Mar 18, 2016

Need any help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants