<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
</dependencies>
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClass.class, MyUtils.class})
public class MyClassTest {
@Test
public void testDoSomething() throws Exception {
PowerMockito.mockStatic(MyUtils.class);
PowerMockito.when(MyUtils.getSomeStaticValue()).thenReturn(42);
MyClass myClass = new MyClass();
int result = myClass.doSomething();
Assert.assertEquals(42, result);
PowerMockito.verifyStatic(MyUtils.class);
MyUtils.getSomeStaticValue();
}
}