Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocked Objects strip runtime annotations #278

Open
johanhaleby opened this issue Jul 24, 2015 · 2 comments
Open

Mocked Objects strip runtime annotations #278

johanhaleby opened this issue Jul 24, 2015 · 2 comments

Comments

@johanhaleby
Copy link
Collaborator

From mathos.m...@gmail.com on April 28, 2010 20:06:05

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.

Attachment: powerMockAnnotation.txt

Original issue: http://code.google.com/p/powermock/issues/detail?id=258

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on April 29, 2010 06:36:18

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 :).

@pskrivanek
Copy link

We have the same problem when processing tests according to annotations.
Is it possible to complete this repair?

We use powermock version 2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants