{"action":"opened","issue":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/2402","repository_url":"https://api.github.com/repos/robolectric/robolectric","labels_url":"https://api.github.com/repos/robolectric/robolectric/issues/2402/labels{/name}","comments_url":"https://api.github.com/repos/robolectric/robolectric/issues/2402/comments","events_url":"https://api.github.com/repos/robolectric/robolectric/issues/2402/events","html_url":"https://github.com/robolectric/robolectric/issues/2402","id":146286042,"number":2402,"title":"IllegalArgumentException when calling shadowed MessageQueue after another Robolectric test","user":{"login":"kzaikin","id":1436829,"avatar_url":"https://avatars.githubusercontent.com/u/1436829?v=3","gravatar_id":"","url":"https://api.github.com/users/kzaikin","html_url":"https://github.com/kzaikin","followers_url":"https://api.github.com/users/kzaikin/followers","following_url":"https://api.github.com/users/kzaikin/following{/other_user}","gists_url":"https://api.github.com/users/kzaikin/gists{/gist_id}","starred_url":"https://api.github.com/users/kzaikin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzaikin/subscriptions","organizations_url":"https://api.github.com/users/kzaikin/orgs","repos_url":"https://api.github.com/users/kzaikin/repos","events_url":"https://api.github.com/users/kzaikin/events{/privacy}","received_events_url":"https://api.github.com/users/kzaikin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-06T11:39:38Z","updated_at":"2016-04-06T11:39:38Z","closed_at":null,"body":"I am not able to shadow a MessageQueue if I run test case after another Robolectric-driven test cases where shadow is not applied.\r\n\r\nIf I run both `FirstTest` and `SecondTest`, then `SecondTest#idleIsExecuted` fails with \r\n\r\n    java.lang.IllegalArgumentException: attempted to invoke public void com.example.myapplication.SecondTest$InstantMessageQueue.addIdleHandler(android.os.MessageQueue$IdleHandler) on instance of class org.robolectric.shadows.ShadowMessageQueue, but ShadowMessageQueue doesn't extend InstantMessageQueue\r\n\tat android.os.MessageQueue.addIdleHandler(MessageQueue.java)\r\n\r\nIf I run `SecondTest` only then `SecondTest#idleIsExecuted` succeeds.\r\n\r\n    @RunWith(RobolectricTestRunner.class)\r\n    @Config(manifest = Config.NONE)\r\n    public class FirstTest {\r\n        @Test\r\n        public void emptyTest() {\r\n        }\r\n    }\r\n\r\n    @RunWith(RobolectricTestRunner.class)\r\n    @Config(shadows = {SecondTest.InstantMessageQueue.class})\r\n    public class SecondTest {\r\n    \r\n        @Implements(value = MessageQueue.class)\r\n        public static class InstantMessageQueue extends ShadowMessageQueue {\r\n            @Implementation\r\n            public void addIdleHandler(MessageQueue.IdleHandler handler) {\r\n                handler.queueIdle();\r\n            }\r\n        }\r\n    \r\n        @Test\r\n        public void idleIsExecuted() {\r\n            final boolean[] flag = new boolean[1];\r\n    \r\n            new Handler().getLooper().myQueue().addIdleHandler(new MessageQueue.IdleHandler() {\r\n                @Override\r\n                public boolean queueIdle() {\r\n                    flag[0] = true;\r\n                    return false;\r\n                }\r\n            });\r\n    \r\n            assertTrue(flag[0]);\r\n        }\r\n    }"}}