You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2019/12/11 03:41:49 UTC

[GitHub] [incubator-doris] xy720 opened a new pull request #2423: Upgrade JMockit from version 1.13 to 1.48

xy720 opened a new pull request #2423: Upgrade JMockit from version 1.13 to 1.48
URL: https://github.com/apache/incubator-doris/pull/2423
 
 
   Issue #2263 
   This commit is going to upgrade JMockit versions to 1.48(2019).
   
   There are several important difference between version 1.13 and 1.48.
   
   **First. JMockit is not longer support mocking private method anymore.**
   In version 1.13, JMockit has already been unsupported to mock private method.
   However, we still can use tricks to mock private method:
   
   ```
   new Expectation()  {
       Deencapsulation.invoke(object, "privateMethod", parameters);
       result = 1;
   }
   ```
   
   but JMockit banned this way in newer version, and they removed the tool `mockit.internal.util.Deencapsulation` to prevent user from using it .
   
   We can also use other ways to mock this method.
   i.e. Create a subclass of tested object and override the method needed to mock.
   
   **Second. util class Deencapsulation is removed **
   There are so many places that we use Deencapsulation in Doris Unit Test.
   i.e. we used to modify field in a object using Deencapsulation in a unit test:
   
   ```
   Deencapsulation.setField(object, "fieldName", fieldValue);
   ```
   
   In newer version, JMockit suggests us to use annotation @Injectable to inject value into field:
   
   ```
   class SomeTest {
      @Tested CodeUnderTest tested;
      @Injectable Dependency dep1;
      @Injectable AnotherDependency dep2;
      @Injectable int someIntegralProperty = 123;
   
      @Test
      void someTestMethod(@Injectable("true") boolean flag, @Injectable("Mary") String name) {
         // Record expectations on mocked types, if needed.
   
         tested.exerciseCodeUnderTest();
   
         // Verify expectations on mocked types, if required.
      }
   }
   ```
   
   However, we can't use @injectable in two circumstances:
   1、the field's value is already initialized.
   2、the following type is not mockable and injectable:
   ```
   "java/lang/String java/lang/StringBuffer java/lang/StringBuilder java/lang/AbstractStringBuilder java/util/Iterator java/util/Comparator java/util/Spliterator java/util/Collection java/util/List java/util/Set java/util/SortedSet java/util/Queue java/util/Enumeration java/util/Map java/util/SortedMap java/util/Map$Entry java/util/AbstractCollection java/util/AbstractMap java/util/Hashtable java/lang/Throwable java/lang/Object java/lang/Enum java/lang/System java/lang/ThreadLocal java/lang/ClassLoader java/lang/Math java/lang/StrictMath java/time/Duration java/nio/file/Paths".
   ```
   
   That is bad. **So I suggests to keep the Deencapsulation after we upgrade to 1.48.** And I've removed the part dependency on jmockit in the deencapsulation. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org