{"action":"created","issue":{"url":"https://api.github.com/repos/jayway/powermock/issues/484","labels_url":"https://api.github.com/repos/jayway/powermock/issues/484/labels{/name}","comments_url":"https://api.github.com/repos/jayway/powermock/issues/484/comments","events_url":"https://api.github.com/repos/jayway/powermock/issues/484/events","html_url":"https://github.com/jayway/powermock/issues/484","id":97196223,"number":484,"title":"PowerMock+TestNG+DataProvider RuntimeException","user":{"login":"johanhaleby","id":187029,"avatar_url":"https://avatars.githubusercontent.com/u/187029?v=3","gravatar_id":"","url":"https://api.github.com/users/johanhaleby","html_url":"https://github.com/johanhaleby","followers_url":"https://api.github.com/users/johanhaleby/followers","following_url":"https://api.github.com/users/johanhaleby/following{/other_user}","gists_url":"https://api.github.com/users/johanhaleby/gists{/gist_id}","starred_url":"https://api.github.com/users/johanhaleby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanhaleby/subscriptions","organizations_url":"https://api.github.com/users/johanhaleby/orgs","repos_url":"https://api.github.com/users/johanhaleby/repos","events_url":"https://api.github.com/users/johanhaleby/events{/privacy}","received_events_url":"https://api.github.com/users/johanhaleby/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jayway/powermock/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/jayway/powermock/labels/imported","name":"imported","color":"FFFFFF"},{"url":"https://api.github.com/repos/jayway/powermock/labels/Priority-Medium","name":"Priority-Medium","color":"FFFFFF"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-25T05:47:17Z","updated_at":"2015-07-25T05:47:24Z","closed_at":null,"body":"_From [Ignas.Tr...@gmail.com](https://code.google.com/u/112024306843858881334/) on October 01, 2013 15:01:03_\n\nWhat steps will reproduce the problem? ======================================\r\n\r\n@Test\r\n@PrepareForTest\r\npublic class StaticTest extends PowerMockTestCase {\r\n\r\n    @DataProvider\r\n    public final Object[][] getWeekday() {\r\n        return new Object[][] {\r\n                {new CustomClass()}\r\n        };\r\n    }\r\n\r\n    @Test (dataProvider = \"getWeekday\")\r\n    public void forAllWeekdaysAllClassroomsShouldBeAvailableInitially(CustomClass p) {\r\n        assertTrue(true);\r\n    }\r\n\r\n}\r\n\r\nclass CustomClass {} What is the expected output? What do you see instead? =====================================================\r\nI see:\r\njava.lang.RuntimeException: Can't invoke method public void lt.ignas.classroombooking.ReservationPlaceTest.bookingForSeparateDayShouldRemainClassroomAvailable(lt.ignas.classroombooking.HourOfWeek,lt.ignas.classroombooking.HourOfWeek), probably due to classloader mismatch\r\n\r\nI expect:\r\ntest to start with dataProvider provided object and to pass succesfully. What version of the product are you using? On what operating system? ====================================================================\r\nUBUNTU 12.04\r\n\r\njava version \"1.7.0_40\"\r\nJava(TM) SE Runtime Environment (build 1.7.0_40-b43)\r\nJava HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)\r\n\r\n\\<dependency>\r\n    \\<groupId>org.testng</groupId>\r\n    \\<artifactId>testng</artifactId>\r\n    \\<version>6.8.7</version>\r\n\\</dependency>\r\n\\<dependency>\r\n    \\<groupId>org.mockito</groupId>\r\n    \\<artifactId>mockito-core</artifactId>\r\n    \\<version>1.9.5</version>\r\n    \\<scope>test</scope>\r\n\\</dependency>\r\n\\<dependency>\r\n    \\<groupId>org.powermock</groupId>\r\n    \\<artifactId>powermock-module-testng</artifactId>\r\n    \\<version>1.5.1</version>\r\n\\</dependency>\r\n\\<dependency>\r\n    \\<groupId>org.powermock</groupId>\r\n    \\<artifactId>powermock-api-mockito</artifactId>\r\n    \\<version>1.5.1</version>\r\n    \\<exclusions>\r\n        \\<exclusion>\r\n            \\<groupId>org.mockito</groupId>\r\n            \\<artifactId>mockito-all</artifactId>\r\n        \\</exclusion>\r\n    \\</exclusions>\r\n\\</dependency> Please provide any additional information below. ================================================\r\n1. Without '@PrepareForTest' test PASSES.\r\n2. Without 'extends PowerMockTestCase' test PASSES.\r\n3. If DataProvider gives STD ( http://en.wikipedia.org/wiki/Standard_library ) class object (like StringBuilder, Object, int, String, etc.) (and test method requires the same type) test PASSES (see APPENDIX A below)\r\n4. If DataProvider gives any custom class included in my project (like CustomClass in the example above) (and test metho requires that type) - test FAILS.\r\n5. If DataProvider gives any custom class included in my project (like CustomClass in the example above) BUT test method requires Object - test PASSES. (see APPENDIX B below)\r\n\r\nLast statement is pretty good workround, but Java's compile time checkings goes away. And explicit cast is needed. \r\n\r\n===== APPENDIX A ======\r\n\r\n@Test\r\n@PrepareForTest\r\npublic class StaticTest extends PowerMockTestCase {\r\n\r\n    @DataProvider\r\n    public final Object[][] getWeekday() {\r\n        return new Object[][] {\r\n                {new StringBuilder()}\r\n        };\r\n    }\r\n\r\n    @Test (dataProvider = \"getWeekday\")\r\n    public void forAllWeekdaysAllClassroomsShouldBeAvailableInitially(StringBuilder p) {\r\n        assertTrue(true);\r\n    }\r\n\r\n}\r\n\r\n===== APPENDIX B ======\r\n\r\n@Test\r\n@PrepareForTest\r\npublic class StaticTest extends PowerMockTestCase {\r\n\r\n    @DataProvider\r\n    public final Object[][] getWeekday() {\r\n        return new Object[][] {\r\n                {new CustomClass()}\r\n        };\r\n    }\r\n\r\n    @Test (dataProvider = \"getWeekday\")\r\n    public void forAllWeekdaysAllClassroomsShouldBeAvailableInitially(Object p) {\r\n        assertTrue(true);\r\n    }\r\n\r\n}\r\n\r\nclass CustomClass {}\n\n_Original issue: http://code.google.com/p/powermock/issues/detail?id=464_"},"comment":{"url":"https://api.github.com/repos/jayway/powermock/issues/comments/124803616","html_url":"https://github.com/jayway/powermock/issues/484#issuecomment-124803616","issue_url":"https://api.github.com/repos/jayway/powermock/issues/484","id":124803616,"user":{"login":"johanhaleby","id":187029,"avatar_url":"https://avatars.githubusercontent.com/u/187029?v=3","gravatar_id":"","url":"https://api.github.com/users/johanhaleby","html_url":"https://github.com/johanhaleby","followers_url":"https://api.github.com/users/johanhaleby/followers","following_url":"https://api.github.com/users/johanhaleby/following{/other_user}","gists_url":"https://api.github.com/users/johanhaleby/gists{/gist_id}","starred_url":"https://api.github.com/users/johanhaleby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanhaleby/subscriptions","organizations_url":"https://api.github.com/users/johanhaleby/orgs","repos_url":"https://api.github.com/users/johanhaleby/repos","events_url":"https://api.github.com/users/johanhaleby/events{/privacy}","received_events_url":"https://api.github.com/users/johanhaleby/received_events","type":"User","site_admin":false},"created_at":"2015-07-25T05:47:24Z","updated_at":"2015-07-25T05:47:24Z","body":"_From [verma....@gmail.com](https://code.google.com/u/110678300271257301934/) on September 03, 2014 21:10:49_\n\nAFAIK if you are using any PowerMock:PrepareForTest, you should not use the custom class as test case input.\r\n\r\nYou can always put it like  public void forAllWeekdaysAllClassroomsShouldBeAvailableInitially(Object p) {\r\n        customClass = (CustomClass) p;\r\n        assertTrue(true);\r\n}"}}