{"action":"created","issue":{"url":"https://api.github.com/repos/jayway/powermock/issues/427","labels_url":"https://api.github.com/repos/jayway/powermock/issues/427/labels{/name}","comments_url":"https://api.github.com/repos/jayway/powermock/issues/427/comments","events_url":"https://api.github.com/repos/jayway/powermock/issues/427/events","html_url":"https://github.com/jayway/powermock/issues/427","id":97130696,"number":427,"title":"PowerMockRunner processes JUnit Rules incorrectly","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":5,"created_at":"2015-07-24T19:49:22Z","updated_at":"2015-07-24T19:49:46Z","closed_at":null,"body":"_From [Iso.poc...@gmail.com](https://code.google.com/u/107642349162510209372/) on November 09, 2012 09:55:39_\n\nWhat steps will reproduce the problem? Use test class in attachment\r\n1. Run testWithoutException() without PowerMockRunner\r\n2. Run testWithoutException() with PowerMockRunner\r\n3. Run testWithException() without PowerMockRunner\r\n4. Run testWithException() with PowerMockRunner What is the expected output? What do you see instead? 1. NO EXCEPTION - START\r\nNO EXCEPTION - STOP\r\nRule1\r\nRule2 2. Rule1\r\nNO EXCEPTION - START\r\nNO EXCEPTION - STOP\r\nRule2 3. EXCEPTION - START\r\n\r\n4.\r\nRule1\r\nEXCEPTION - START What version of the product are you using? On what operating system? JUnit 4.8.2\r\nPowerMock 1.4.12 Please provide any additional information below. As you can see, PowerMockRunner handles JUnit Rules differently than BlockJUnit4ClassRunner. Please compare: PowerMockJUnit47RunnerDelegateImpl#executeTest(Method, Object, Runnable) with BlockJUnit4ClassRunner#withRules(FrameworkMethod, Object, Statement).\r\n\r\nJUnit PASSES each Rule's returned statement and the last declared rule gets statement that evaluates test method. On contrary PowerMockRunner runs every declared rule one by one.\r\n\r\nPlease see java doc of MethodRule: \"Multiple {@link MethodRule}s can be applied to a test method. The Statement that executes the method is passed to each annotated Rule in turn, and each may return a substitute or modified Statement, which is passed to the next {@link Rule}, if any.\".\r\nIt means that PowerMockRunner behaviour is wrong.\n\n**Attachment:** [TestClass.java](http://code.google.com/p/powermock/issues/detail?id=407)\n\n_Original issue: http://code.google.com/p/powermock/issues/detail?id=407_"},"comment":{"url":"https://api.github.com/repos/jayway/powermock/issues/comments/124681346","html_url":"https://github.com/jayway/powermock/issues/427#issuecomment-124681346","issue_url":"https://api.github.com/repos/jayway/powermock/issues/427","id":124681346,"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-24T19:49:46Z","updated_at":"2015-07-24T19:49:46Z","body":"_From [Iso.poc...@gmail.com](https://code.google.com/u/107642349162510209372/) on November 30, 2012 01:31:37_\n\nI can agree that in most cases developers should not use PowerMock but just refactor code to create classes that are testable (program to interfaces, use Dependency Injection, prevent creating highly coupled classes, avoid sharing complex business logic through static utility classes, etc), but ...\r\nI see potential of PowerMock when your code relay on third-party-libraries or frameworks. For example: Eclipse 3.x Platform lacks of IoC container, which encourages to use static utilicty classes/methods a lot. Moreover there are plenty of places when you need to obtain Eclipse's Workbench - through some static methods.\r\nThe other example is when you are using third party library's class which is final or has some final methods. To do some unit tests you have to (want to ?) mock this class.\r\n\r\nBut lets back to the original issue. I'll try to provide some patch but I'm not an expert of JUnit. Moreover as far as I know the newest version of JUnit deprecates usage of MethodRule in favour of TestRule. So it may (or may not) be handled differently in the newest version (currently I'm using JUnit 4.8.2).\r\n\r\nGenerally I think that fact that PowerMock needs it own runner: PowerMockRunner is a source of maintenance hell. If JUnit implements new feature you also have to do it (or maybe I'm wrong - I'm not very familiar how exactly PowerMockRunner works. I only imagine that the \"only\" think that it should do is to somehow cheat class loader ;. Here comes idea whether we can use Aspect Programming to achieve that)).\r\n\r\nFor me personally I want to use PowerMock to:\r\n- mock final classes\r\n- mock final methods\r\n- mock static methods in utility classes\r\n\r\nI'm thinking about investigate how to deal with it basing on yours experience. I'm not familiar with PowerMock requirements but form me it should work under JUnit and EasyMock and to be as more transparent as possible."}}