gordonad / powermock

Automatically exported from code.google.com/p/powermock
0 stars 0 forks source link

doInvokeMethod method in PowerMock should treat the InvokationTargetException separately #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Right now the doInvokeMethod catches all exceptions and wrap them in a RTE.
This is wrong. The InvokationTargetException should be caught explicitly
and the cause of this exceptions should be thrown instead. This to avoid
error stacks like this:

java.lang.RuntimeException: Failed to invoke method 'assertLogFileSet'.
Reason was: 'null'.
    at org.powermock.PowerMock.doInvokeMethod(PowerMock.java:1123)
    at org.powermock.PowerMock.expectVoid(PowerMock.java:723)
    at
se.mayapp.TargetPersistenceManagerTest.testGetLogFileList(TargetPersistenceManag
erTest.java:454)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:87)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.in
vokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:162)
    at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.ru
nMethods(PowerMockJUnit44RunnerDelegateImpl.java:119)
    at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.
run(PowerMockJUnit44RunnerDelegateImpl.java:112)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.ru
n(PowerMockJUnit44RunnerDelegateImpl.java:110)
    at
org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run
(JUnit4TestSuiteChunkerImpl.java:74)
    at
org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.
run(AbstractCommonPowerMockRunner.java:43)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReferen
ce.java:45)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.powermock.PowerMock.doInvokeMethod(PowerMock.java:1121)
    ... 26 more
Caused by: java.lang.IllegalStateException: You need to set the log path
before using the target persistence manager.
    at
se.mayapp.TargetPersistenceManager.assertLogFileSet(TargetPersistenceManager.jav
a:123)
    ... 31 more

I.e. the actual exception should be "java.lang.IllegalStateException: You
need to set the log path before using the target persistence manager."

Original issue reported on code.google.com by johan.ha...@gmail.com on 1 Oct 2008 at 11:46

GoogleCodeExporter commented 9 years ago
doInvokeMethod in PowerMock now catches and deals correctly with
InvocationTargetExceptions

Original comment by johan.ha...@gmail.com on 13 Oct 2008 at 4:37