{"action":"opened","issue":{"url":"https://api.github.com/repos/mockito/mockito/issues/353","repository_url":"https://api.github.com/repos/mockito/mockito","labels_url":"https://api.github.com/repos/mockito/mockito/issues/353/labels{/name}","comments_url":"https://api.github.com/repos/mockito/mockito/issues/353/comments","events_url":"https://api.github.com/repos/mockito/mockito/issues/353/events","html_url":"https://github.com/mockito/mockito/issues/353","id":133089858,"number":353,"title":"@Mock-annotated fields are null for inner test classes (e.g. when using junit-hierarchicalcontextrunner)","user":{"login":"UrsMetz","id":1553875,"avatar_url":"https://avatars.githubusercontent.com/u/1553875?v=3","gravatar_id":"","url":"https://api.github.com/users/UrsMetz","html_url":"https://github.com/UrsMetz","followers_url":"https://api.github.com/users/UrsMetz/followers","following_url":"https://api.github.com/users/UrsMetz/following{/other_user}","gists_url":"https://api.github.com/users/UrsMetz/gists{/gist_id}","starred_url":"https://api.github.com/users/UrsMetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UrsMetz/subscriptions","organizations_url":"https://api.github.com/users/UrsMetz/orgs","repos_url":"https://api.github.com/users/UrsMetz/repos","events_url":"https://api.github.com/users/UrsMetz/events{/privacy}","received_events_url":"https://api.github.com/users/UrsMetz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-11T21:17:41Z","updated_at":"2016-02-11T21:17:41Z","closed_at":null,"body":"Using the two current versions of Mockito (1.10.19 and 2.x-beta) and the JUnit-Mockito-Rule together with JUnit extensions like [junit-hierarchicalcontextrunner](https://github.com/bechte/junit-hierarchicalcontextrunner/) that use inner classes causes fails with `NullPointerException`s\r\n```java\r\n@RunWith(HierarchicalContextRunner.class)\r\npublic class HierarchicalMockitoTest {\r\n    @Rule\r\n    public MockitoRule mockitoRule = MockitoJUnit.rule();\r\n\r\n    @Mock\r\n    private Runnable runnable;\r\n\r\n    public class Context {\r\n        @Test\r\n        public void test() throws Exception {\r\n            runnable.run();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nWith older 1.x versions that didn't not contain the new JUnit rule API (e.g. where `MockitoJUnitRule` was not deprecated yet) the above test pass. I guess the reason is that the old rule's constructor had the current test instance passed in. In newer versions the rule uses the `target` from `org.junit.rules.MethodRule#apply()` which in this example is an instance of `HierarchicalMockitoTest.Context` so the `@Mock`-annotated fields of the outer classes are not seen and the mocks won't get instantiated."}}