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

Comments

2 participants
@oazmon

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 added the bug label Mar 16, 2016

@rliesenfeld rliesenfeld self-assigned this Mar 16, 2016

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Mar 16, 2016

Member

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

Member

rliesenfeld commented Mar 16, 2016

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

@oazmon

This comment has been minimized.

Show comment
Hide comment
@oazmon

oazmon Mar 18, 2016

Need any help?

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