-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update Mockito to 5.16.1 #10686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Mockito to 5.16.1 #10686
Conversation
Dependency name change mockito-inline to mockito-core. Inline is now the default and the last version of mockito-inline released is 5.2.0. assertj-core in user-authenticators/saml2 pulls in an incompatible version of byte-buddy and required an exclusion. Updating the version of assertj is left for a future PR. The upgrade requires Java 11+, dropping support for Java 8. CloudStack documentation already says to use Java 11 and does not indicate that java 8 is supported. Test classes using @RunWith(MockitoJUnitRunner.class) now get run in strict mode. Changes were made to tests where the stubbing intention was clear. In ManagementServerMaintenanceManagerImplTest there are 5 tests where the intention of the test is unclear. Each of the statements now use Mockito.lenient() to avoid the exception. Other cases in the tests follow a similar pattern. Minor clean up. Both @SPY and Mockito.spy( should not be used. Favored the annotation. Both @RunWith(MockitoJUnitRunner.class) and MockitoAnnotations.openMocks(this); should not be used. Favored the annotation. Unnecessary extends TestCase removed. @Injectmocks and new in statement unnecessary. Removed new when issue presented. Some of the Cmd classes like UpdateNetworkCmd have a type tree that includes fields of type Object. This appears to cause issues with injection, requiring that @mock fields be available. This is where the following fields were added in multiple places: Object job; ResponseGenerator _responseGenerator; Wrong number of parameters for Mockito.when in LibvirtRevertSnapshotCommandWrapperTest.java
Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
|
@blueorangutan package |
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 20 out of 24 changed files in this pull request and generated 1 comment.
Files not reviewed (4)
- plugins/storage/volume/storpool/pom.xml: Language not supported
- plugins/user-authenticators/ldap/pom.xml: Language not supported
- plugins/user-authenticators/saml2/pom.xml: Language not supported
- pom.xml: Language not supported
Comments suppressed due to low confidence (2)
server/src/test/java/com/cloud/network/element/VirtualRouterElementTest.java:174
- [nitpick] Consider using a consistent naming style for mocks. Since other mocks in this file use an underscore prefix (e.g. _vpnDao), renaming loadBalancerDao to _loadBalancerDao could improve readability.
@Mock private LoadBalancerDao loadBalancerDao;
server/src/test/java/org/apache/cloud/api/query/QueryManagerImplTest.java:116
- The QueryManagerImpl spy instance is no longer initialized, which could lead to a NullPointerException. Consider instantiating it explicitly (e.g. new QueryManagerImpl()) or ensure it is initialized by the test framework.
private QueryManagerImpl queryManagerImplSpy;
LibvirtMigrateCommandWrapper spyLibvirtMigrateCmdWrapper = libvirtMigrateCmdWrapper; | ||
Mockito.doNothing().when(spyLibvirtMigrateCmdWrapper).deleteLocalVolume("volPath"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The redundant spy wrapping is unnecessary since libvirtMigrateCmdWrapper is already a spy. Removing this redundant wrapping can simplify the test code.
LibvirtMigrateCommandWrapper spyLibvirtMigrateCmdWrapper = libvirtMigrateCmdWrapper; | |
Mockito.doNothing().when(spyLibvirtMigrateCmdWrapper).deleteLocalVolume("volPath"); | |
Mockito.doNothing().when(libvirtMigrateCmdWrapper).deleteLocalVolume("volPath"); |
Copilot uses AI. Check for mistakes.
|
||
@Before | ||
public void setup() throws Exception { | ||
closeable = MockitoAnnotations.openMocks(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class is annotated with @RunWith(MockitoJUnitRunner.class)
which is calling MockitoAnnotations.openMocks(...);
before every test. Calling openMocks
a second time can have undesirable side effects.
I removed the line as it was unnecessary and could issues in some circumstances.
@@ -154,7 +154,7 @@ public void prepareForShutdownCmdOtherMsHostsInPreparingState() { | |||
ManagementServerHostVO msHost2 = mock(ManagementServerHostVO.class); | |||
List<ManagementServerHostVO> msHostList = new ArrayList<>(); | |||
msHostList.add(msHost2); | |||
Mockito.when(msHostDao.listBy(any())).thenReturn(msHostList); | |||
Mockito.lenient().when(msHostDao.listBy(any())).thenReturn(msHostList); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc mockito was throwing errors earlier when an unnecessary mocks was setup. Why is lenient()
required now? Can't we just remove the mock if it's not required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be removed. I choose not to remove it because I did not want to significantly alter any logic of the tests as part of the Mockito version upgrade.
It is unclear to me if the mock is not being used by accident and it should be used. I feel the discussion about the test intention should happen independently of the Mockito upgrade.
server/src/test/java/com/cloud/resourcelimit/ResourceLimitManagerImplTest.java
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10686 +/- ##
============================================
+ Coverage 16.30% 17.17% +0.86%
+ Complexity 13449 13445 -4
============================================
Files 5676 5277 -399
Lines 499208 466608 -32600
Branches 60374 54592 -5782
============================================
- Hits 81414 80126 -1288
+ Misses 408722 377562 -31160
+ Partials 9072 8920 -152
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13006 |
@vishesh92 , this seems ok to me as it is only unit tests I do not agree with copilot about the '_'s so I say let's merge. Any objections? |
@blueorangutan test |
@rohityadavcloud a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
yeah. Unit tests are passing, so not much of a concern here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall code lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clgtm
And tests are passing.
.../java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmdTest.java
Show resolved
Hide resolved
api/src/test/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmdTest.java
Show resolved
Hide resolved
api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java
Show resolved
Hide resolved
...ervisors/vmware/src/test/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImplTest.java
Show resolved
Hide resolved
...ypervisors/vmware/src/test/java/com/cloud/hypervisor/vmware/resource/VmwareResourceTest.java
Show resolved
Hide resolved
...saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmdTest.java
Show resolved
Hide resolved
(test env has been deleted due to space constrains, pls rekick tomorrow again) |
@blueorangutan package |
@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13042 |
@blueorangutan test |
@weizhouapache a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
[SF] Trillian test result (tid-12979)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merging this based on code reviews lgtms, GA/simulator tests and smoketests. |
Awesome work, congrats on your first merged pull request! |
Description
This PR updates Mockito to 5.16.1 from 4.
See the release notes for high level changes: https://github.com/mockito/mockito/releases/tag/v5.0.0
Dependency name change
mockito-inline
tomockito-core
. Inline is now the default and the last version ofmockito-inline
released is5.2.0
.assertj-core
in user-authenticators/saml2 pulls in an incompatible version of byte-buddy and required an exclusion. Updating the version of assertj is left for a future PR.The upgrade requires Java 11+, dropping support for Java 8. CloudStack documentation already says to use Java 11 and does not indicate that java 8 is supported.
Test classes using
@RunWith(MockitoJUnitRunner.class)
now get run in strict mode. Changes were made to tests where the stubbing intention was clear. InManagementServerMaintenanceManagerImplTest
there are 5 tests where the intention of the test is unclear. Each of the statements now useMockito.lenient()
to avoid the exception. Other cases in the tests follow a similar pattern.Minor clean up.
@Spy
andMockito.spy(
should not be used. Favored the annotation.@RunWith(MockitoJUnitRunner.class)
andMockitoAnnotations.openMocks(this);
should not be used. Favored the annotation.extends TestCase
removed.@InjectMocks
andnew
in statement unnecessary. Removed new when issue presented.Cmd
classes likeUpdateNetworkCmd
have a type tree that includes fields of typeObject
. This appears to cause issues with injection, requiring that@Mock
fields be available. This is where the following fields were added in multiple places:Object job;
ResponseGenerator _responseGenerator;
Mockito.when
in LibvirtRevertSnapshotCommandWrapperTest.javaTypes of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
All tests that run with flags:
-Dnoredist -P developer,systemvm
.Commands used:
mvn clean install -Dnoredist -P developer,systemvm
Do not need to verify running of the server or agent because Mockito is only used in tests.
How did you try to break this feature and the system with this change?