[JIRA] (JENKINS-60130) can not use recommended versions of powermock & mockito

8 views
Skip to first unread message

jnord@cloudbees.com (JIRA)

unread,
Nov 11, 2019, 8:15:03 AM11/11/19
to jenkinsc...@googlegroups.com
James Nord created an issue
 
Jenkins / Bug JENKINS-60130
can not use recommended versions of powermock & mockito
Issue Type: Bug Bug
Assignee: Unassigned
Components: plugin-pom
Created: 2019-11-11 13:14
Priority: Critical Critical
Reporter: James Nord

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.misusing.NotAMockException: Argument should be a mock, but is: class java.lang.Class

 

 

 

 

 

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

jnord@cloudbees.com (JIRA)

unread,
Nov 11, 2019, 8:39:02 AM11/11/19
to jenkinsc...@googlegroups.com
James Nord updated an issue
Change By: James Nord
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. misusing base . NotAMockException MockitoException : Argument should be a mock, but is  org.mockito.exceptions.base.MockitoException :  Cannot mock/spy class java.lang. Class SystemMockito cannot mock/spy because : - final class at ShowBadMockitoVersion.testWeGetHere(ShowBadMockitoVersion.java:21) }}

 

 
{code:java}
// 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"));
 
  }
}
{code}
 

 Downgrading the mockito version locally to {{2.23.0}} and powermock dependencies to {{2.0.2}} fixes the issue.

 

 

 

 
Reply all
Reply to author
Forward
0 new messages