Skip to content

[JENKINS-60130] can not use recommended versions of powermock & mockito #1331

Description

@jenkins-infra-bot

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.

 

 

 

 


Originally reported by teilo, imported from: can not use recommended versions of powermock & mockito
  • status: Open
  • priority: Critical
  • component(s): plugin-pom
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20260108-221235
Raw content of original issue

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.

 

 

 

 

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions