Katarzynasrom / powermock

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

Mocked Objects strip runtime annotations #258

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The mocked objects that are returned by createMock (and the like) no longer
have runtime annotations.  This causes problem when you have code that you
are testing that depend on the existence of these annotations.

Though in some cases this is because of code in PowerMock, there are some
lower level libraries (i.e. EasyMock's use of gclib and java's Proxy class)
which also are responsible for the missing annotations.  I have created a
patch for PowerMock that would allow for these values to be returned.  I
opted for doing it at the PowerMock level as it already uses javassist
(which is more straightforward then gclib) and already had started
overriding EasyMock's class ProxyFactory.

The patch involves a class that will take an originating class and the
mocked class and the generated byte code for the mocked class and will
reapply the runtime annotations.  I also had to change the way that
interface mocks were created by creating an InterfaceProxyFactory class
(this does change interfaces from being created with java's Proxy class to
a similar method as creating a class). Hence there are some minor changes
to how to determine if a class is an interface proxy (i.e. instead of
calling Proxy.isProxyClass()).  For now the class just reapplies
annotations to the class and method objects, I could do fields and
parameters for completeness, but wanted to see if this functionality and
implementation would be acceptable.

Original issue reported on code.google.com by mathos.m...@gmail.com on 28 Apr 2010 at 6:06

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Cool! Thanks for your patch. I'm extremely busy atm so I don't have time to 
look at
it right now but I will eventually :).

Original comment by johan.ha...@gmail.com on 29 Apr 2010 at 1:36