JiaLiangC opened a new pull request, #3860:
URL: https://github.com/apache/ambari/pull/3860

   …k to Mockito
   
   ## What changes were proposed in this pull request?
   
   
   
   
   ## Migrate RecommendationResourceProviderTest from EasyMock to Mockito
   
   ### Description
   This PR migrates the `RecommendationResourceProviderTest` class from 
EasyMock to Mockito testing framework. This change is necessary to resolve 
compatibility issues when running tests under JDK 17.
   
   ### Changes
   - Replaced EasyMock imports with Mockito imports
   - Updated `testCreateConfigurationResources` and 
`testCreateNotConfigurationResources` methods to use Mockito syntax
   - Refactored the `testCreateResources` helper method to use Mockito
   - Removed EasyMock dependency (if previously present)
   
   ### Key Error Resolved
   This PR addresses the following error that occurred after upgrading to JDK 
17:
   
   ```
   [ERROR] 
org.apache.ambari.server.controller.internal.RecommendationResourceProviderTest.testCreateConfigurationResources
 -- Time elapsed: 0.761 s <<< ERROR!
   java.lang.ClassCastException: class jdk.proxy2.$Proxy42 cannot be cast to 
class [Ljava.lang.Object; (jdk.proxy2.$Proxy42 is in module jdk.proxy2 of 
loader 'app'; [Ljava.lang.Object; is in module java.base of loader 'bootstrap')
   ```
   
   ### Possible Reasons for the Error
   The error likely occurs due to changes in how JDK 17 handles dynamic proxies 
compared to JDK 8:
   
   1. Module System: JDK 17 uses a stronger module system, which can affect how 
classes from different modules interact.
   2. Proxy Implementation: The way proxies are implemented has changed in JDK 
17, leading to incompatibilities with older mocking frameworks.
   3. Class Loader Differences: The error message indicates a mismatch between 
class loaders, which is more strictly enforced in JDK 17.
   4. EasyMock Compatibility: EasyMock may not be fully compatible with JDK 17, 
especially when it comes to creating proxies for array types.
   
   Migrating to Mockito, which is actively maintained and compatible with JDK 
17, should resolve these issues.
   
   
   ## How was this patch tested?
   - unit tests have been updated and pass
   
![image](https://github.com/user-attachments/assets/a12e2666-f6eb-4535-98c1-c25a8228e3db)
   
   
   (Please explain how this patch was tested. Ex: unit tests, manual tests)
   (If this patch involves UI changes, please attach a screen-shot; otherwise, 
remove this)
   
   Please review [Ambari Contributing 
Guide](https://cwiki.apache.org/confluence/display/AMBARI/How+to+Contribute) 
before opening a pull request.


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to