{"action":"created","issue":{"url":"https://api.github.com/repos/jayway/powermock/issues/497","labels_url":"https://api.github.com/repos/jayway/powermock/issues/497/labels{/name}","comments_url":"https://api.github.com/repos/jayway/powermock/issues/497/comments","events_url":"https://api.github.com/repos/jayway/powermock/issues/497/events","html_url":"https://github.com/jayway/powermock/issues/497","id":97196437,"number":497,"title":"mockStatic of JAXBContext fail with PowerMockRule","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":1,"created_at":"2015-07-25T05:49:22Z","updated_at":"2015-07-25T05:49:24Z","closed_at":null,"body":"_From [88ch...@gmail.com](https://code.google.com/u/110564866721639014231/) on January 14, 2014 14:52:54_\n\nWhat steps will reproduce the problem? 1. this is the class that i`m testing:\r\npublic class Some {\r\n  public String some() {\r\n    return String.format(\"123\", \"456\");\r\n  }\r\n\t\r\n  public JAXBContext getJAXBContext() throws JAXBException {\r\n    return JAXBContext.newInstance(Configuration.class);\r\n  }\r\n}\r\n\r\n2. this is my test class\r\n@PrepareForTest({Some.class, JAXBContext.class})\r\n//@RunWith(PowerMockRunner.class)\r\npublic class SomeTest {\r\n  \r\n  @Rule\r\n  public PowerMockRule rule = new PowerMockRule ();\r\n\t\r\n  @Test\r\n  public void testSome() {\r\n    PowerMockito.mockStatic(String.class);\r\n    PowerMockito.when(String.format(\"123\", \"456\")).thenReturn(\"789\");\r\n    Some s = new Some();\r\n    String value = s.some();\r\n    Assert.assertEquals(\"789\", value);\r\n  }\r\n\t\r\n  @Test\r\n  public void testJAXB() throws JAXBException {\r\n    PowerMockito.mockStatic(JAXBContext.class);\r\n    JAXBContext mock = PowerMockito.mock(JAXBContext.class);\r\n     PowerMockito.when(JAXBContext.newInstance(Configuration.class)).thenReturn(mock);\r\n\t\t\r\n    Some some = new Some();\r\n    JAXBContext context = some.getJAXBContext();\r\n    Assert.assertSame(mock, context);\r\n  } \r\n}\r\n3. using maven with the following dependencies:\r\n\\<dependency>\r\n   \\<groupId>org.powermock</groupId>\r\n   \\<artifactId>powermock-module-junit4-rule-agent</artifactId>\r\n   \\<version>${powermock.version}</version>\r\n   \\<scope>test</scope>\r\n\\</dependency>\r\n\\<dependency>\r\n   \\<groupId>org.powermock</groupId>\r\n   \\<artifactId>powermock-api-mockito</artifactId>\r\n   \\<version>${powermock.version}</version>\r\n   \\<scope>test</scope>\r\n\\</dependency>\r\n\r\nwith plugin configuration:\r\n\\<plugin>\r\n  \\<artifactId>maven-surefire-plugin</artifactId>\r\n    \\<configuration>\r\n      \\<argLine>-javaagent:${org.powermock:powermock-module-javaagent:jar}</argLine>\r\n      \\<useSystemClassloader>true</useSystemClassloader>\r\n    \\</configuration>\r\n\\</plugin> What is the expected output? What do you see instead? getting the error from the test:\r\nTests in error:\r\n  testJ(com.att.tlv.ci.crawler.test.parser.SomeTest):\r\nwhen() requires an argument which has to be 'a method call on a mock'.\r\nFor example:\r\n    when(mock.getArticles()).thenReturn(articles);\r\n\r\nAlso, this error might show up because:\r\n1. you stub either of: final/private/equals()/hashCode() methods.\r\n   Those methods *cannot* be stubbed/verified.\r\n2. inside when() you don't call method on mock but on some other object.\r\n3. the parent of the mocked class is not public.\r\n   It is a limitation of the mock engine. What version of the product are you using? On what operating system? \\<powermock.version>1.5.2</powermock.version>\r\njava version \"1.6.0_30\" Please provide any additional information below. when i put PowerMockRunner (commented out in my example) it work fine.\r\nonly with the javaagent it fails..\n\n_Original issue: http://code.google.com/p/powermock/issues/detail?id=477_"},"comment":{"url":"https://api.github.com/repos/jayway/powermock/issues/comments/124804033","html_url":"https://github.com/jayway/powermock/issues/497#issuecomment-124804033","issue_url":"https://api.github.com/repos/jayway/powermock/issues/497","id":124804033,"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:49:24Z","updated_at":"2015-07-25T05:49:24Z","body":"_From [88ch...@gmail.com](https://code.google.com/u/110564866721639014231/) on January 14, 2014 05:54:35_\n\nforgot to mention that only the second test fail (the one with the JAXB), the first test (with the String.format) in both cases pass."}}