Adapt Apache Geode LuceneIndexFactory.setFields(..) mocking to behavior changes between Mockito 4 (based on Java 8) and Mockito 5 (based on Java 11).

This commit is contained in:
John Blum
2023-06-24 19:06:22 -07:00
parent 8e9dab0612
commit dfd2355aa4
3 changed files with 13 additions and 17 deletions

View File

@@ -172,6 +172,7 @@ import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.data.gemfire.tests.util.ObjectUtils;
import org.springframework.data.gemfire.util.ArrayUtils;
import org.springframework.data.gemfire.util.CollectionUtils;
import org.springframework.data.gemfire.util.JavaVersion;
import org.springframework.data.util.ReflectionUtils;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
@@ -2458,7 +2459,7 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
return mockLuceneIndexFactory;
});
when(mockLuceneIndexFactory.setFields(ArgumentMatchers.<String[]>any())).thenAnswer(invocation -> {
Answer<LuceneIndexFactory> answer = invocation -> {
Object[] fieldsArgument = invocation.getArguments();
@@ -2472,7 +2473,14 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
Collections.addAll(fields, fieldNames);
return mockLuceneIndexFactory;
});
};
if (JavaVersion.current().isNewerThanOrEqualTo(JavaVersion.ELEVEN)) {
doAnswer(answer).when(mockLuceneIndexFactory).setFields(any(String[].class));
}
else {
doAnswer(answer).when(mockLuceneIndexFactory).setFields(ArgumentMatchers.<String[]>any());
}
when(mockLuceneIndexFactory.setFields(anyMap())).thenAnswer(invocation -> {

View File

@@ -31,16 +31,13 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
import org.springframework.data.gemfire.tests.support.AbstractSecurityManager;
/**
* Integration tests for {@link GemFireMockObjectsSupport}.
* Integration Tests for {@link GemFireMockObjectsSupport}.
*
* @author John Blum
* @see java.util.Properties
* @see org.junit.Test
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.CacheFactory
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport
* @see org.springframework.data.gemfire.tests.support.AbstractSecurityManager
* @since 1.0.0
*/
public class GemFireMockObjectsSupportIntegrationTests extends IntegrationTestsSupport {

View File

@@ -43,25 +43,16 @@ import org.apache.geode.cache.lucene.LuceneService;
import org.apache.geode.cache.query.Index;
import org.apache.geode.cache.server.ClientSubscriptionConfig;
import org.apache.lucene.analysis.Analyzer;
import org.springframework.data.gemfire.IndexType;
import org.apache.lucene.analysis.Analyzer;
/**
* Unit Tests for {@link GemFireMockObjectsSupport}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.apache.geode.cache.AttributesMutator
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.RegionAttributes
* @see org.apache.geode.cache.RegionService
* @see org.apache.geode.cache.asyncqueue.AsyncEventListener
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueue
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory
* @see org.apache.geode.cache.server.ClientSubscriptionConfig
* @see org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport
* @since 1.0.0
*/