Skip to content

Commit 9a87c46

Browse files
Upgrade mockito
1 parent 3986e4b commit 9a87c46

5 files changed

Lines changed: 33 additions & 20 deletions

File tree

build-logic/src/main/java/org/ehcache/build/conventions/JavaConvention.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public void apply(Project project) {
2222

2323
dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "junit:junit:" + project.property("junitVersion"));
2424
dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.assertj:assertj-core:" + project.property("assertjVersion"));
25+
dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "net.bytebuddy:byte-buddy:" + project.property("byteBuddyVersion"));
26+
dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "net.bytebuddy:byte-buddy-agent:" + project.property("byteBuddyVersion"));
2527
dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.hamcrest:hamcrest:" + project.property("hamcrestVersion"));
2628
dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.mockito:mockito-core:" + project.property("mockitoVersion"));
2729
ModuleDependency md = (ModuleDependency)dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.terracotta:terracotta-utilities-test-tools:" + project.property("terracottaUtilitiesVersion"));
@@ -35,6 +37,14 @@ public void apply(Project project) {
3537
subs.substitute(subs.module("org.hamcrest:hamcrest-library:1.3")).with(subs.module("org.hamcrest:hamcrest-library:" + project.property("hamcrestVersion")));
3638
subs.substitute(subs.module("junit:junit:4.12")).using(subs.module("junit:junit:4.13.1"));
3739
});
40+
config.getResolutionStrategy().eachDependency(details -> {
41+
String group = details.getRequested().getGroup();
42+
String name = details.getRequested().getName();
43+
if ("net.bytebuddy".equals(group) && ("byte-buddy".equals(name) || "byte-buddy-agent".equals(name))) {
44+
details.useVersion(project.property("byteBuddyVersion").toString());
45+
details.because("Align Byte Buddy family versions across AssertJ and Mockito");
46+
}
47+
});
3848
});
3949
}
4050
}

clustered/ehcache-client/src/test/java/org/ehcache/clustered/client/internal/service/DefaultClusteringServiceDestroyTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
import static org.mockito.Mockito.when;
5656
import static org.mockito.Mockito.withSettings;
5757

58+
import org.mockito.quality.Strictness;
59+
5860
/**
5961
* DefaultClusteringServiceDestroyTest
6062
*/
@@ -194,7 +196,7 @@ public void testDestroyOnPartialDestroyState() throws Exception {
194196

195197
private void mockLockForWriteLockSuccess() throws org.terracotta.exception.EntityNotProvidedException, org.terracotta.exception.EntityNotFoundException, org.terracotta.exception.EntityVersionMismatchException {
196198
when(connection.<VoltronReadWriteLockClient, Object, Void>getEntityRef(same(VoltronReadWriteLockClient.class), eq(1L), any())).thenReturn(lockEntityRef);
197-
VoltronReadWriteLockClient lockClient = mock(VoltronReadWriteLockClient.class, withSettings().lenient());
199+
VoltronReadWriteLockClient lockClient = mock(VoltronReadWriteLockClient.class, withSettings().strictness(Strictness.LENIENT));
198200
when(lockEntityRef.fetchEntity(null)).thenReturn(lockClient);
199201

200202
when(lockClient.tryLock(LockMessaging.HoldType.WRITE)).thenReturn(true);
@@ -203,7 +205,7 @@ private void mockLockForWriteLockSuccess() throws org.terracotta.exception.Entit
203205

204206
private void mockLockForReadLockSuccess() throws org.terracotta.exception.EntityNotProvidedException, org.terracotta.exception.EntityNotFoundException, org.terracotta.exception.EntityVersionMismatchException {
205207
when(connection.<VoltronReadWriteLockClient, Object, Void>getEntityRef(same(VoltronReadWriteLockClient.class), eq(1L), any())).thenReturn(lockEntityRef);
206-
VoltronReadWriteLockClient lockClient = mock(VoltronReadWriteLockClient.class, withSettings().lenient());
208+
VoltronReadWriteLockClient lockClient = mock(VoltronReadWriteLockClient.class, withSettings().strictness(Strictness.LENIENT));
207209
when(lockEntityRef.fetchEntity(null)).thenReturn(lockClient);
208210

209211
when(lockClient.tryLock(LockMessaging.HoldType.READ)).thenReturn(true);

ehcache-core/src/test/java/org/ehcache/core/EhcacheManagerTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void testCanDestroyAndClose() throws Exception {
117117
Store store = mock(Store.class);
118118
CacheEventDispatcherFactory cacheEventNotificationListenerServiceProvider = mock(CacheEventDispatcherFactory.class);
119119

120-
when(storeProvider.createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any())).thenReturn(store);
120+
when(storeProvider.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(store);
121121
when(store.getConfigurationChangeListeners()).thenReturn(new ArrayList<>());
122122
when(cacheEventNotificationListenerServiceProvider.createCacheEventDispatcher(store)).thenReturn(mock(CacheEventDispatcher.class));
123123

@@ -200,7 +200,7 @@ public void testNoClassLoaderSpecified() {
200200

201201
final Collection<Service> services = getServices(storeProvider, cenlProvider);
202202
when(storeProvider
203-
.createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock);
203+
.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(mock);
204204
EhcacheManager cacheManager = new EhcacheManager(config, services);
205205
cacheManager.init();
206206
assertSame(ClassLoading.getDefaultClassLoader(), cacheManager.getClassLoader());
@@ -240,7 +240,7 @@ public ClassLoader getClassLoader() {
240240

241241
final Collection<Service> services = getServices(storeProvider, cenlProvider);
242242
when(storeProvider
243-
.createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock);
243+
.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(mock);
244244
EhcacheManager cacheManager = new EhcacheManager(config, services);
245245
cacheManager.init();
246246
assertSame(cl1, cacheManager.getClassLoader());
@@ -274,7 +274,7 @@ public void testThrowsWhenAddingExistingCache() {
274274
final Collection<Service> services = getServices(storeProvider, cenlProvider);
275275

276276
when(storeProvider
277-
.createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock);
277+
.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(mock);
278278

279279
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
280280
caches.put("bar", cacheConfiguration);
@@ -303,7 +303,7 @@ public void testThrowsWhenNotInitialized() {
303303
final Collection<Service> services = getServices(storeProvider, cenlProvider);
304304

305305
when(storeProvider
306-
.createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock);
306+
.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(mock);
307307

308308
final CacheConfiguration<Integer, String> cacheConfiguration = new TestCacheConfig<>(Integer.class, String.class);
309309
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
@@ -341,7 +341,7 @@ public void testThrowsWhenRetrievingCacheWithWrongTypes() {
341341

342342
final Collection<Service> services = getServices(storeProvider, cenlProvider);
343343
when(storeProvider
344-
.createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock);
344+
.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(mock);
345345

346346
final CacheConfiguration<Integer, String> cacheConfiguration = new TestCacheConfig<>(Integer.class, String.class);
347347
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
@@ -406,7 +406,7 @@ public void testLifeCyclesCacheLoaders() throws Exception {
406406
when(cenlProvider.createCacheEventDispatcher(mock)).thenReturn(cenlServiceMock);
407407
Collection<Service> services = getServices(cacheLoaderWriterProvider, decoratorLoaderWriterProvider, storeProvider, cenlProvider);
408408
when(storeProvider
409-
.createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock);
409+
.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(mock);
410410

411411
EhcacheManager manager = new EhcacheManager(cfg, services);
412412
manager.init();
@@ -494,8 +494,7 @@ <K, V> InternalCache<K, V> createNewEhcache(final String alias, final CacheConfi
494494
final InternalCache<K, V> ehcache = super.createNewEhcache(alias, config, keyType, valueType);
495495
caches.add(alias);
496496
if(caches.size() == 1) {
497-
when(storeProvider.createStore(
498-
ArgumentMatchers.<Store.Configuration<K,V>>any(), ArgumentMatchers.<ServiceConfiguration<?, ?>>any()))
497+
when(storeProvider.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class)))
499498
.thenThrow(thrown);
500499
}
501500
return ehcache;
@@ -669,7 +668,7 @@ public void testChangesToManagerAreReflectedInConfig() {
669668
Store store = mock(Store.class);
670669
CacheEventDispatcherFactory cacheEventNotificationListenerServiceProvider = mock(CacheEventDispatcherFactory.class);
671670

672-
when(storeProvider.createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any())).thenReturn(store);
671+
when(storeProvider.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(store);
673672
when(store.getConfigurationChangeListeners()).thenReturn(new ArrayList<>());
674673
when(cacheEventNotificationListenerServiceProvider.createCacheEventDispatcher(store)).thenReturn(mock(CacheEventDispatcher.class));
675674

@@ -716,7 +715,7 @@ public void testCachesAddedAtRuntimeGetReInited() {
716715
Store store = mock(Store.class);
717716
CacheEventDispatcherFactory cacheEventNotificationListenerServiceProvider = mock(CacheEventDispatcherFactory.class);
718717

719-
when(storeProvider.createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any())).thenReturn(store);
718+
when(storeProvider.createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class))).thenReturn(store);
720719
when(store.getConfigurationChangeListeners()).thenReturn(new ArrayList<>());
721720
when(cacheEventNotificationListenerServiceProvider.createCacheEventDispatcher(store)).thenReturn(mock(CacheEventDispatcher.class));
722721

@@ -754,7 +753,7 @@ public void testCachesAddedAtRuntimeGetReInited() {
754753
public void testCloseWhenRuntimeCacheCreationFails() throws Exception {
755754
Store.Provider storeProvider = mock(Store.Provider.class);
756755
when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1);
757-
doThrow(new Error("Test EhcacheManager close.")).when(storeProvider).createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any());
756+
doThrow(new Error("Test EhcacheManager close.")).when(storeProvider).createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class));
758757

759758
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
760759
DefaultConfiguration config = new DefaultConfiguration(caches, null);
@@ -788,7 +787,7 @@ public void testCloseWhenRuntimeCacheCreationFails() throws Exception {
788787
public void testCloseWhenCacheCreationFailsDuringInitialization() throws Exception {
789788
Store.Provider storeProvider = mock(Store.Provider.class);
790789
when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1);
791-
doThrow(new Error("Test EhcacheManager close.")).when(storeProvider).createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any());
790+
doThrow(new Error("Test EhcacheManager close.")).when(storeProvider).createStore(any(Store.Configuration.class), any(ServiceConfiguration[].class));
792791

793792
CacheConfiguration<Long, String> cacheConfiguration = new TestCacheConfig<>(Long.class, String.class);
794793
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();

ehcache-impl/src/test/java/org/ehcache/impl/internal/store/tiering/TieredStoreTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.ehcache.impl.internal.store.heap.OnHeapStore;
3535
import org.ehcache.impl.internal.store.offheap.OffHeapStore;
3636
import org.ehcache.spi.service.Service;
37+
import org.ehcache.spi.service.ServiceConfiguration;
3738
import org.ehcache.spi.service.ServiceProvider;
3839
import org.hamcrest.Matchers;
3940
import org.junit.Test;
@@ -867,15 +868,15 @@ public void testReleaseStoreFlushes() throws Exception {
867868
OnHeapStore.Provider onHeapStoreProvider = mock(OnHeapStore.Provider.class);
868869
Set<ResourceType<?>> cachingResources = Collections.<ResourceType<?>>singleton( ResourceType.Core.HEAP);
869870
when(onHeapStoreProvider.rankCachingTier(eq(cachingResources), any(Collection.class))).thenReturn(1);
870-
when(onHeapStoreProvider.createCachingTier(eq(cachingResources), any(Store.Configuration.class),
871-
ArgumentMatchers.any()))
871+
when(onHeapStoreProvider.createCachingTier(any(Set.class), any(Store.Configuration.class),
872+
any(ServiceConfiguration[].class)))
872873
.thenReturn(stringCachingTier);
873874

874875
OffHeapStore.Provider offHeapStoreProvider = mock(OffHeapStore.Provider.class);
875876
Set<ResourceType<?>> authorityResources = Collections.<ResourceType<?>>singleton( ResourceType.Core.OFFHEAP);
876877
when(offHeapStoreProvider.rankAuthority(eq(authorityResources), any(Collection.class))).thenReturn(1);
877-
when(offHeapStoreProvider.createAuthoritativeTier(eq(authorityResources),
878-
any(Store.Configuration.class), ArgumentMatchers.any()))
878+
when(offHeapStoreProvider.createAuthoritativeTier(any(Set.class),
879+
any(Store.Configuration.class), any(ServiceConfiguration[].class)))
879880
.thenReturn(stringAuthoritativeTier);
880881

881882
Store.Configuration<String, String> configuration = mock(Store.Configuration.class);

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ terracottaUtilitiesVersion = 0.0.19
1616
# Test lib versions
1717
junitVersion = 4.13.1
1818
assertjVersion = 3.27.7
19+
byteBuddyVersion = 1.18.3
1920
hamcrestVersion = 2.2
20-
mockitoVersion = 4.3.1
21+
mockitoVersion = 5.12.0
2122
jcacheTckVersion = 1.1.0
2223

2324
sonatypeUser = OVERRIDE_ME

0 commit comments

Comments
 (0)