mlinhard / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Mockito.when calls the method passed in if it's a method from a protected superclass #258

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. This code produces that behaviour:

public class MockitoBug {

    // Note: protected or private, not public
    class Foo {
        public String fooMethod() {
            throw new RuntimeException("This should not be called!");
        }
    }

    // Note: public
    public class Bar extends Foo {}

    @Test
    public void test() {
        Bar b = Mockito.mock(Bar.class);
        Mockito.when(b.fooMethod()).thenReturn(null);
        // => This throws an exception because it actually calls fooMethod()
    }
}

What is the expected output? What do you see instead?
Expected: Mockito.when(fooMethod()) should not call the method.
Result: it calls fooMethod (the real implementation) and we get an exception.

What version of the product are you using? On what operating system?
Version 1.8.1 on Linux

Please provide any additional information below.
I use Junit 4.
Thank you all, Mockito is great!

Original issue reported on code.google.com by mail.ab...@gmail.com on 28 Apr 2011 at 2:57

GoogleCodeExporter commented 9 years ago
Hi,

This issue is a duplicate of issue 212. This is due to a bug with CGLIB. 
Methods are not correctly intercepted.

Original comment by brice.du...@gmail.com on 28 Apr 2011 at 3:42