-
Bug
-
Resolution: Unresolved
-
Critical
-
None
using the plugin-pom 3.51 as a base for your plugins.
if you use powermock and mockito at the recommended versions tests that use powermock blowup with org.mockito.exceptions.base.MockitoException: org.mockito.exceptions.base.MockitoException: Cannot mock/spy class java.lang.SystemMockito cannot mock/spy because : - final class at ShowBadMockitoVersion.testWeGetHere(ShowBadMockitoVersion.java:21)
// code placeholder import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; 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({ System.class }) public class ShowBadMockitoVersion { @Test public void testWeGetHere() throws Exception { PowerMockito.mockStatic(System.class); PowerMockito.when(System.getProperty(eq("zzz"), any())).thenReturn("TEST"); assertEquals("TEST", System.getProperty("zzz", "bogus")); } }
Downgrading the mockito version locally to 2.23.0 and powermock dependencies to 2.0.2 fixes the issue.