{"action":"closed","issue":{"url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1885","repository_url":"https://api.github.com/repos/androidannotations/androidannotations","labels_url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1885/labels{/name}","comments_url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1885/comments","events_url":"https://api.github.com/repos/androidannotations/androidannotations/issues/1885/events","html_url":"https://github.com/androidannotations/androidannotations/issues/1885","id":185635976,"number":1885,"title":"Fail to run test with Robolectric and PowerMock","user":{"login":"kaiyan910","id":9815472,"avatar_url":"https://avatars.githubusercontent.com/u/9815472?v=3","gravatar_id":"","url":"https://api.github.com/users/kaiyan910","html_url":"https://github.com/kaiyan910","followers_url":"https://api.github.com/users/kaiyan910/followers","following_url":"https://api.github.com/users/kaiyan910/following{/other_user}","gists_url":"https://api.github.com/users/kaiyan910/gists{/gist_id}","starred_url":"https://api.github.com/users/kaiyan910/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaiyan910/subscriptions","organizations_url":"https://api.github.com/users/kaiyan910/orgs","repos_url":"https://api.github.com/users/kaiyan910/repos","events_url":"https://api.github.com/users/kaiyan910/events{/privacy}","received_events_url":"https://api.github.com/users/kaiyan910/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-27T10:55:50Z","updated_at":"2016-10-27T11:00:43Z","closed_at":"2016-10-27T11:00:43Z","body":"DemoPresenterTest.java\r\n```` java\r\n@RunWith(RobolectricTestRunner.class)\r\n@Config(constants = BuildConfig.class, sdk = 23)\r\n@PowerMockIgnore({ \"org.mockito.*\", \"org.robolectric.*\", \"android.*\" })\r\n@PrepareForTest(DemoPresenterImpl_.class)\r\npublic class DemoPresenterTest {\r\n\r\n    @Rule\r\n    public MockitoRule rule = MockitoJUnit.rule();\r\n\r\n    private MockDemoNetworkService mMockDemoNetworkService;\r\n    private MockLceView mLceView;\r\n\r\n    private DemoPresenterImpl_ mPresenter;\r\n\r\n    @Before\r\n    public void setup() {\r\n\r\n        mMockDemoNetworkService = Mockito.mock(MockDemoNetworkService.class);\r\n        mLceView = Mockito.mock(MockLceView.class);\r\n        PowerMockito.mockStatic(DemoPresenterImpl_.class);\r\n\r\n        mPresenter = DemoPresenterImpl_.getInstance_(RuntimeEnvironment.application);\r\n\r\n        mPresenter.service = mMockDemoNetworkService;\r\n        mPresenter.view = mLceView;\r\n    }\r\n\r\n    @Test\r\n    public void testDownloadData() {\r\n\r\n        mPresenter.downloadData();\r\n        Mockito.verify(mLceView).onError(Mockito.anyInt());\r\n    }\r\n}\r\n````\r\nDemoPresenterImpl.java\r\n```` java\r\n@EBean\r\npublic class DemoPresenterImpl implements DemoPresenter {\r\n\r\n    @Bean(DemoNetworkService.class)\r\n    DemoService service;\r\n\r\n    protected LceView<Demo> view;\r\n\r\n    /**\r\n     * download the data from server for the first time, data will be saved into the database\r\n     * and for the next time it will query the database instead\r\n     */\r\n    @Override\r\n    @Background(delay = 1000)\r\n    public void downloadData() {\r\n\r\n        try {\r\n\r\n            List<Demo> result = service.getDemoList();\r\n\r\n            if (result != null) {\r\n                view.setData(result);\r\n            } // add else if the result is not return empty list but null\r\n\r\n        } catch (NetworkFailException e) {\r\n            view.onError(e.getResponse().getCode());\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void attach(LceView<Demo> view) {\r\n        this.view = view;\r\n    }\r\n}\r\n````\r\nMockDemoNetworkService.java\r\n````\r\npublic class MockDemoNetworkService implements DemoService {\r\n\r\n    @Override\r\n    public List<Demo> getDemoList() throws NetworkFailException {\r\n\r\n        NetworkFailResponse response = new NetworkFailResponse();\r\n        response.setCode(500);\r\n\r\n        throw new NetworkFailException(response);\r\n    }\r\n\r\n    @Override\r\n    public boolean setDemoList(List<Demo> demoList) {\r\n        return false;\r\n    }\r\n}\r\n````\r\nWhen I run the test it returns \"Cannot subclass final class class com.*.DemoPresenterImpl_\", if I change to DemoPresenterImpl, the test can run but the mLceView never get called\r\n````\r\nWanted but not invoked: mockLceView.onError(); -> at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:245) Actually, there were zero interactions with this mock.\r\n````\r\nam I doing something wrong?"}}
{"actor":{"display_login":"WonderCsabo"}}