Fix tests broken with the upgrade of Mockito framework With the change 390986, Mockito framework was upgraded from 3.3.3 to 5.6.0 and because of that some tests started failing. This change requires minor refactoring to fix those tests, as outlined in the following points: - The method `verifyZeroInteractions` is no longer supported in the class `org.mockito.Mockito` [1]. Instead, it can be substituted with `verifyNoInteractions`. - In Mockito version 3.3.3, the execution of real code occurred in methods without defined expectations, and some tests were designed accordingly. However, with Mockito 5.6.0, when methods are invoked without specified expectations, the framework will now appropriately return either null, a primitive/primitive wrapper value, or an empty collection. As a result, minor refactoring was necessary. - The handling of Mockito expectations in methods declared with varargs has been restructured to use the format `any(MyClass[].class)`. References: [1] https://github.com/mockito/mockito/blob/v5.6.0/src/main/java/org/mockito/Mockito.java#L2699 Change-Id: Ic3d8641c4ca6b485212bdaa55d359a4cc4bb4741
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueueTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueueTest.java index 14447a9..90c9b9c 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueueTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueueTest.java
@@ -26,7 +26,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import com.google.common.base.Suppliers; @@ -527,7 +527,7 @@ Event event = generateBatchRefUpdateEvent("refs/multi-site/version"); objectUnderTest.onEvent(event); - verifyZeroInteractions(wq, rd, dis, sl, fetchClientFactory, accountAttribute); + verifyNoInteractions(wq, rd, dis, sl, fetchClientFactory, accountAttribute); } @Test @@ -541,7 +541,7 @@ Event event = generateBatchRefUpdateEvent("refs/starred-changes/41/2941/1000000"); objectUnderTest.onEvent(event); - verifyZeroInteractions(wq, rd, dis, sl, fetchClientFactory, accountAttribute); + verifyNoInteractions(wq, rd, dis, sl, fetchClientFactory, accountAttribute); } @Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/DeleteRefCommandTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/DeleteRefCommandTest.java index 9c9c689..40912ac 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/DeleteRefCommandTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/DeleteRefCommandTest.java
@@ -41,7 +41,6 @@ import com.googlesource.gerrit.plugins.replication.pull.fetch.ApplyObject; import java.util.Optional; import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.Repository; @@ -78,7 +77,6 @@ @Mock private RefUpdate refUpdate; @Mock private Repository repository; @Mock private Ref currentRef; - @Mock private RefDatabase refDb; @Captor ArgumentCaptor<Event> eventCaptor; private DeleteRefCommand objectUnderTest; @@ -92,8 +90,7 @@ when(source.getURI(TEST_PROJECT_NAME)).thenReturn(TEST_REMOTE_URI); when(gitManager.openRepository(any())).thenReturn(repository); when(repository.updateRef(any())).thenReturn(refUpdate); - when(repository.getRefDatabase()).thenReturn(refDb); - when(refDb.exactRef(anyString())).thenReturn(currentRef); + when(repository.exactRef(anyString())).thenReturn(currentRef); when(refUpdate.delete()).thenReturn(Result.FORCED); objectUnderTest = @@ -131,8 +128,7 @@ @Test public void shouldHandleNonExistingRef() throws Exception { when(source.isMirror()).thenReturn(true); - when(refDb.exactRef(anyString())).thenReturn(null); - + when(repository.exactRef(anyString())).thenReturn(null); objectUnderTest.deleteRef(TEST_PROJECT_NAME, NON_EXISTING_REF_NAME, TEST_SOURCE_LABEL); verify(eventDispatcher, never()).postEvent(any());
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/client/FetchRestApiClientWithBasicAuthenticationTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/client/FetchRestApiClientWithBasicAuthenticationTest.java index ebac729..165ed80 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/client/FetchRestApiClientWithBasicAuthenticationTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/client/FetchRestApiClientWithBasicAuthenticationTest.java
@@ -39,7 +39,7 @@ @Before public void setup() throws Exception { when(bearerTokenProvider.get()).thenReturn(Optional.empty()); - when(credentialProvider.supports(any())) + when(credentialProvider.supports(any(CredentialItem[].class))) .thenAnswer( new Answer<Boolean>() { @@ -54,7 +54,7 @@ } }); - when(credentialProvider.get(any(), any(CredentialItem.class))).thenReturn(true); + when(credentialProvider.get(any(), any(CredentialItem[].class))).thenReturn(true); when(credentials.create(anyString())).thenReturn(credentialProvider); when(replicationConfig.getConfig()).thenReturn(config); when(config.getStringList("replication", null, "syncRefs")).thenReturn(new String[0]);