package org.apereo.cas.redis.core.util;

import lombok.val;
import org.apereo.cas.redis.core.config.CasRedisServerConfiguration;
import org.apereo.cas.util.junit.EnabledIfPortOpen;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * This is {@link RedisUtilsTests}.
 *
 * @author Fireborn Z
 * @since 6.5.0
 */
@SpringBootTest(classes = {
    CasRedisServerConfiguration.class
})
@Tag("Redis")
@EnabledIfPortOpen(port = 6379)
public class RedisUtilsTests {
    private static final int KEY_SIZE = 10;

    @Autowired
    @Qualifier("stringRedisTemplate")
    protected RedisTemplate<String, String> stringRedisTemplate;

    @Test
    public void verifyGetKeys() {
        val redisKeyPrefix = "CAS_TEST:";
        IntStream.range(0, KEY_SIZE)
            .forEach(i -> stringRedisTemplate.boundValueOps(redisKeyPrefix + i).set(String.valueOf(i)));
        val keySet = RedisUtils.keys(stringRedisTemplate, redisKeyPrefix + "*").collect(Collectors.toSet());
        assertEquals(KEY_SIZE, keySet.size());
        stringRedisTemplate.delete(keySet);
        val stream = RedisUtils.keys(stringRedisTemplate, redisKeyPrefix + "*");
        assertEquals(0, stream.count());
    }
}

@@ -493,44 +493,8 @@
 e;%0A%0A
-import java.util.stream.Collectors;%0A
 impo
@@ -524,16 +524,16 @@
 Stream;%0A
+
 %0Aimport 
@@ -822,53 +822,8 @@
 s %7B%0A
-    private static final int KEY_SIZE = 10;%0A%0A
     
@@ -973,11 +973,8 @@
 rify
-Get
 Keys
@@ -1020,16 +1020,42 @@
 TEST:%22;%0A
+        val keySize = 10;%0A
         
@@ -1077,30 +1077,16 @@
 (0, 
-KEY_SIZE)%0A            
+keySize)
 .for
@@ -1157,25 +1157,14 @@
 set(
-String.valueOf(i)
+%22TEST%22
 ));%0A
@@ -1178,19 +1178,17 @@
  val key
-Set
+s
  = Redis
@@ -1244,240 +1244,44 @@
 %22*%22)
-.collect(Collectors.toSet());%0A        assertEquals(KEY_SIZE, keySet.size());%0A        stringRedisTemplate.delete(keySet);%0A        val stream = RedisUtils.keys(stringRedisTemplate, redisKeyPrefix + %22*%22);%0A        assertEquals(0, stream
+;%0A        assertEquals(keySize, keys
 .cou

clean up testcase