Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-153088

Upgrade Mockito to major version 4 and removes the dependency on PowerMock

Details

    Description

      This PR updates Mockito to major version 4 and removes the dependency on PowerMock.

      PowerMock appears to be abandoned and Mockito v4 adds support for static method mocking and constructor mocking which we previously needed to use PowerMock to get. We currently add mockito-core and mockito-inline to lib.(However, Mockito-inline may be abolished when the inline mock-making feature is integrated into the default mock maker in the future. Eventually, it will be mockito-core only. )

      Notable changes with the upgrade

      Conflict between MockitoJUnitRunner and LiferayUnitTestRule

      Previously we use portal-test/StatementWrapper.java to inspect Target from the statement. After migrating to the new MockitoJUnitRunner, the statement will return as a lambda which will cause the StatementWrapper can not to obtain the statement and then throw an unknown statement exception. So we avoid using MockitoJUnitRunner to init annotation.

      We will add the SF rule about this.

      Junit Version caused "xxx method .... must return an Iterable of arrays." exception in parametrized tests

      See test result in https://github.com/liferay-core-infra/liferay-portal/pull/871

      Previously Gradle will load Junit-4.12 when compiling powermock-module-junit4, After we removed powermock dependencies, it uses version Junit-4.11 automatically.

      For parametrized tests, JUnit 4.11 expects every parameter set to be an array, so it will throw the exception in our tests. Junit 4.12+ does not has this restriction anymore. so Junit 4.12 is manually added back to the test classpath in LiferayOSGiDefaultsPlugin.java for master.

      @RunWith(Parameterized.class)
      public class CSSBuilderTest extends BaseCSSBuilderJniTestCase {
      
      	@Parameterized.Parameters(name = "{0}")
      	public static String[] getSeparators() {
      		return new String[] {"=", " "};
      	}
      
      @Parameterized.Parameters                                                                              
      public static Collection<xxx[]> getSeparators() {                                            
         xxxx
      } 
      

      Attachments

        Issue Links

          Activity

            People

              tina.tian Tina Tian
              janis.zhang Janis Zhang
              Janis Zhang Janis Zhang
              Enterprise Release HU Enterprise Release HU
              Janis Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Packages

                  Version Package
                  7.0.X
                  7.1.X
                  7.2.X
                  7.3.X
                  Master