Skip to content

Commit dfd2355

Browse files
committed
Adapt Apache Geode LuceneIndexFactory.setFields(..) mocking to behavior changes between Mockito 4 (based on Java 8) and Mockito 5 (based on Java 11).
1 parent 8e9dab0 commit dfd2355

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/GemFireMockObjectsSupport.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
import org.springframework.data.gemfire.tests.util.ObjectUtils;
173173
import org.springframework.data.gemfire.util.ArrayUtils;
174174
import org.springframework.data.gemfire.util.CollectionUtils;
175+
import org.springframework.data.gemfire.util.JavaVersion;
175176
import org.springframework.data.util.ReflectionUtils;
176177
import org.springframework.lang.NonNull;
177178
import org.springframework.lang.Nullable;
@@ -2458,7 +2459,7 @@ private static LuceneIndexFactory mockLuceneIndexFactory(Map<LuceneIndexKey, Luc
24582459
return mockLuceneIndexFactory;
24592460
});
24602461

2461-
when(mockLuceneIndexFactory.setFields(ArgumentMatchers.<String[]>any())).thenAnswer(invocation -> {
2462+
Answer<LuceneIndexFactory> answer = invocation -> {
24622463

24632464
Object[] fieldsArgument = invocation.getArguments();
24642465

@@ -2472,7 +2473,14 @@ private static LuceneIndexFactory mockLuceneIndexFactory(Map<LuceneIndexKey, Luc
24722473
Collections.addAll(fields, fieldNames);
24732474

24742475
return mockLuceneIndexFactory;
2475-
});
2476+
};
2477+
2478+
if (JavaVersion.current().isNewerThanOrEqualTo(JavaVersion.ELEVEN)) {
2479+
doAnswer(answer).when(mockLuceneIndexFactory).setFields(any(String[].class));
2480+
}
2481+
else {
2482+
doAnswer(answer).when(mockLuceneIndexFactory).setFields(ArgumentMatchers.<String[]>any());
2483+
}
24762484

24772485
when(mockLuceneIndexFactory.setFields(anyMap())).thenAnswer(invocation -> {
24782486

spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/mock/GemFireMockObjectsSupportIntegrationTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,13 @@
3131
import org.springframework.data.gemfire.tests.support.AbstractSecurityManager;
3232

3333
/**
34-
* Integration tests for {@link GemFireMockObjectsSupport}.
34+
* Integration Tests for {@link GemFireMockObjectsSupport}.
3535
*
3636
* @author John Blum
3737
* @see java.util.Properties
3838
* @see org.junit.Test
39-
* @see org.apache.geode.cache.Cache
40-
* @see org.apache.geode.cache.CacheFactory
4139
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
4240
* @see org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport
43-
* @see org.springframework.data.gemfire.tests.support.AbstractSecurityManager
4441
* @since 1.0.0
4542
*/
4643
public class GemFireMockObjectsSupportIntegrationTests extends IntegrationTestsSupport {

spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/mock/GemFireMockObjectsSupportUnitTests.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,16 @@
4343
import org.apache.geode.cache.query.Index;
4444
import org.apache.geode.cache.server.ClientSubscriptionConfig;
4545

46-
import org.apache.lucene.analysis.Analyzer;
47-
4846
import org.springframework.data.gemfire.IndexType;
4947

48+
import org.apache.lucene.analysis.Analyzer;
49+
5050
/**
5151
* Unit Tests for {@link GemFireMockObjectsSupport}.
5252
*
5353
* @author John Blum
5454
* @see org.junit.Test
5555
* @see org.mockito.Mockito
56-
* @see org.apache.geode.cache.AttributesMutator
57-
* @see org.apache.geode.cache.Cache
58-
* @see org.apache.geode.cache.Region
59-
* @see org.apache.geode.cache.RegionAttributes
60-
* @see org.apache.geode.cache.RegionService
61-
* @see org.apache.geode.cache.asyncqueue.AsyncEventListener
62-
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueue
63-
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory
64-
* @see org.apache.geode.cache.server.ClientSubscriptionConfig
6556
* @see org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport
6657
* @since 1.0.0
6758
*/

0 commit comments

Comments
 (0)