Provide mock for package-private class?

705 views
Skip to first unread message

Phuong Hoang

unread,
May 10, 2012, 4:52:45 PM5/10/12
to powe...@googlegroups.com
Hi,
Is there a way to provide mock for package-private class using powermock? If it is not possible, is there any other alternatives?

Thanks


Johan Haleby

unread,
May 11, 2012, 11:32:46 AM5/11/12
to powe...@googlegroups.com
Yes you can specify the fully-qualified name to the class in the @PrepareForTest annotation.

/Johan



--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To view this discussion on the web visit https://groups.google.com/d/msg/powermock/-/TvJ8x11R6MEJ.
To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/powermock?hl=en.

Johan Haleby

unread,
Jul 27, 2012, 2:15:37 AM7/27/12
to powe...@googlegroups.com
If the test doesn't even compile you need to move the test class to the same structure package where the package-private class is located (if this is the class you're testing) but in the test folder. I.e. if your package private class under test is in src/main/java/x/y/MyClass then your test should be in src/test/java/x/y/MyClassSpec

/Johan

On Thu, Jul 26, 2012 at 4:10 PM, Alwyn <alwyn.s...@aciworldwide.com> wrote:
I have tried this and the test doesn't want to compile due to the class not being visible in the package of the test.  Am I missing anything?


On Friday, May 11, 2012 11:32:46 AM UTC-4, Johan Haleby wrote:
Yes you can specify the fully-qualified name to the class in the @PrepareForTest annotation.

/Johan

On Thu, May 10, 2012 at 10:52 PM, Phuong Hoang <hoang.l...@gmail.com> wrote:
Hi,
Is there a way to provide mock for package-private class using powermock? If it is not possible, is there any other alternatives?

Thanks


--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To view this discussion on the web visit https://groups.google.com/d/msg/powermock/-/TvJ8x11R6MEJ.
To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/powermock?hl=en.



This email message and any attachments may contain confidential, proprietary or non-public information. The information is intended solely for the designated recipient(s). If an addressing or transmission error has misdirected this email, please notify the sender immediately and destroy this email. Any review, dissemination, use or reliance upon this information by unintended recipients is prohibited. Any opinions expressed in this email are those of the author personally.

--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To view this discussion on the web visit https://groups.google.com/d/msg/powermock/-/bEVZ8cV2Sc8J.

Alwyn

unread,
Jul 28, 2012, 12:42:50 AM7/28/12
to powe...@googlegroups.com
Ok, so for classes that are not in the same package I guess the only alternative is to add a public wrapper for the package private  class for use by test cases.


On Friday, July 27, 2012 2:15:37 AM UTC-4, Johan Haleby wrote:
If the test doesn't even compile you need to move the test class to the same structure package where the package-private class is located (if this is the class you're testing) but in the test folder. I.e. if your package private class under test is in src/main/java/x/y/MyClass then your test should be in src/test/java/x/y/MyClassSpec

/Johan

Johan Haleby

unread,
Jul 28, 2012, 12:01:32 PM7/28/12
to powe...@googlegroups.com
Yes unless want to move your test. PowerMock cannot do anything about compile-time errors.

To view this discussion on the web visit https://groups.google.com/d/msg/powermock/-/8wyt6DNg4uwJ.

To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages