RedisCacheService extends DefaultService implements CacheService { @SuppressWarnings("unchecked") @Override public <V> List<V> getRange(String key, int startOffset, int endOffset) { List<V> returnValue = null; try { returnValue = (List<V>) _jedisClusterClient.lrange(key, startOffset, endOffset); } catch (Exception ex) { _logger.error("Exception in cache service: {} ", ex.getMessage()); returnValue = null; } return returnValue; } @Inject  RedisCacheService(SystemConfiguration config, CacheRedisClient cacheRedisClient); @SuppressWarnings("unchecked") @Override V get(String key); @SuppressWarnings("unchecked") @Override Map<String, V> get(Set<String> keySet); @Override void put(String key, V value, int ttl); @Override void put(Map<String, V> entries, int ttl); @Override void expire(String key, int ttl); @Override void expire(Set<String> keys, int ttl); @Override boolean exist(String key); @Override Map<String, Boolean> exist(Set<String> keys); @Override Set<String> getKeysByPattern(String pattern); @Override Map<String, V> getByPattern(String pattern); @Override void delete(String key); @Override void delete(Set<String> keySet); @Override void append(String key, V value); @SuppressWarnings("unchecked") @Override List<V> getRange(String key, int startOffset, int endOffset); @Override void append(String key, V value, int ttl); @SuppressWarnings("unchecked") @Override Map<String, V> getRange(Set<String> keys, int startOffset, int endOffset); @Override int getCacheExpirationTime(); @Override Properties getServiceProperties(); @Override void dispose();  }
@Test public void testGetRange() { JedisCluster mockJedisClient = mock(JedisCluster.class); CacheRedisClient mockedCachedRedisClient = mock(CacheRedisClient.class); when(mockedCachedRedisClient.getJedisClusterClient()).thenReturn(mockJedisClient); RedisCacheService redisCacheService = new RedisCacheService(config, mockedCachedRedisClient); redisCacheService.getRange("key1", 2, 10); verify(mockJedisClient, times(1)).lrange("key1", 2, 10); }
@Test public void testGetRangeSet() { JedisCluster mockJedisClient = mock(JedisCluster.class); CacheRedisClient mockedCachedRedisClient = mock(CacheRedisClient.class); when(mockedCachedRedisClient.getJedisClusterClient()).thenReturn(mockJedisClient); RedisCacheService redisCacheService = new RedisCacheService(config, mockedCachedRedisClient); Set<String> keys = new HashSet<>(Arrays.asList("key1", "key2")); redisCacheService.getRange(keys, 2, 10); verify(mockJedisClient, times(1)).lrange("key1", 2, 10); verify(mockJedisClient, times(1)).lrange("key2", 2, 10); }