Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60130

can not use recommended versions of powermock & mockito

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • plugin-pom
    • 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.

       

       

       

       

            Unassigned Unassigned
            teilo James Nord
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: