package com.github.gabrielruiu.spring.cloud.config.redis;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Map;

/**
 * @author Gabriel Mihai Ruiu (gabriel.ruiu@mail.com)
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public abstract class BaseRedisEnvironmentRepositoryTest {

    @LocalServerPort
    int port;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Autowired
    TestRestTemplate testRestTemplate;

    protected void injectPropertiesIntoRedis(Map<String, String> properties) {
        for (Map.Entry<String, String> propertyEntry : properties.entrySet()) {
            stringRedisTemplate.opsForValue().set(propertyEntry.getKey(), propertyEntry.getValue());
        }
    }
}

@@ -52,16 +52,41 @@
 redis;%0A%0A
+import org.junit.Before;%0A
 import o
@@ -110,16 +110,16 @@
 unWith;%0A
-
 import o
@@ -513,16 +513,38 @@
 til.Map;
+%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -872,24 +872,24 @@
  @Autowired%0A
-
     TestRest
@@ -912,24 +912,176 @@
 tTemplate;%0A%0A
+    @Before%0A    public void cleanUpRedis() %7B%0A        Set%3CString%3E keys = stringRedisTemplate.keys(%22*%22);%0A        stringRedisTemplate.delete(keys);%0A    %7D%0A%0A
     protecte

Add @Before method so that all extending tests cleanup the Redis database before executing This makes sure we work starting from an empty database