Top "Powermock" questions

Use this tag for questions about PowerMock, a Java library for creating mock objects for classes and methods.

powermock mocking constructor via whennew() does not work with anonymous class

I have a DummyResource class and a DummyTarget file, and a test class TestDummyResource as below, but the mocked object …

java junit mockito powermock
How do I use Powermockito to mock the construction of new objects when testing a method in an anonymous class?

I woud like to write a JUnit test to verify that the code below uses a BufferedInputStream: public static final …

java mockito anonymous-class powermock object-construction
AnyString() as parameter for unit test

I have to deal with a legacy application that has no tests. So before I begin refactoring I want to …

java junit mockito powermock assertj
How can I mock a void method to throw an exception?

I have a structure like this: public class CacheWrapper { private Map<Object, Object> innerMap; public CacheWrapper() { //initialize the …

java unit-testing exception powermock easymock
mocking protected method

I want to mock an inherited protected method. I can't call this method directly from java code as it is …

java mockito powermock powermockito
Mocking a Private Variable that is Assumed to Exist

How can you get a mock object in at runtime when it is not created/initialized in the class you …

java mocking mockito powermock
PowerMock throws NoSuchMethodError (setMockName)

I'm trying to mock a constructor using PowerMockito but every time I run the test I get the following error: …

java mockito junit4 powermock
NoClassDefFoundError when using Powermock

I'm running a junit test case using the PowerMock test runner. I'm using the following command line to execute it: …

java unit-testing junit easymock powermock
How to mock a void static method to throw exception with Powermock?

I am trying to use Powermock and Mockito to mock a void static method to throw exception as below. But …

java unit-testing mockito powermock
Mock System class to get system properties

I have a folder path set in system variable through JVM arguments in Eclipse and I am trying to access …

java mocking environment-variables system powermock