CacheImpl implements Cache<T> { @Override public void putAll(Map<String, T> values) { List<CacheStore.Entry<T>> cacheValues = new ArrayList<>(values.size()); for (Map.Entry<String, T> entry : values.entrySet()) { cacheValues.add(new CacheStore.Entry<>(cacheKey(entry.getKey()), entry.getValue())); } cacheStore.putAll(cacheValues, duration, context); } CacheImpl(String name, Class<T> cacheClass, Duration duration); @Override T get(String key, Function<String, T> loader); Optional<T> get(String key); @Override Map<String, T> getAll(Collection<String> keys, Function<String, T> loader); @Override void put(String key, T value); @Override void putAll(Map<String, T> values); @Override void evict(String key); @Override void evictAll(Collection<String> keys); final String name; final Class<T> cacheClass; final Duration duration; public CacheStore cacheStore; }
@Test void putAll() { cache.putAll(Map.of("key1", cacheItem("v1"), "key2", cacheItem("v2"))); verify(cacheStore).putAll(argThat(argument -> { Set<String> keys = argument.stream().map(entry -> entry.key).collect(Collectors.toSet()); return argument.size() == 2 && keys.contains("name:key1") && keys.contains("name:key2"); }), eq(Duration.ofHours(1)), eq(cache.context)); }