项目作者: incu6us

项目描述 :
Redis Mock (Stateful) for Java based apps & tests
高级语言: Java
项目地址: git://github.com/incu6us/redis-mock-template.git
创建时间: 2019-11-27T10:05:23Z
项目社区:https://github.com/incu6us/redis-mock-template

开源协议:MIT License

下载


redis-mock-template

Maven Central
test status
build status
Codacy Badge

Redis Stateful Mock for testing specific cases(based on mock-jedis).

Additional details you could find on Medium.

Add dependency to project

  1. <dependency>
  2. <groupId>com.github.incu6us.redis</groupId>
  3. <artifactId>redis-mock-template</artifactId>
  4. <version>0.0.2</version>
  5. </dependency>

Example of usage

  1. import org.junit.Test;
  2. import org.junit.runner.RunWith;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.data.redis.core.RedisTemplate;
  5. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  6. import static org.assertj.core.api.Assertions.assertThat;
  7. @RunWith(SpringJUnit4ClassRunner.class)
  8. @EnableRedisMockTemplate
  9. public class EnableRedisMockTemplateTest {
  10. @Autowired
  11. private RedisTemplate redisTemplate;
  12. @Test
  13. public void isRedisTemplateLoaded() {
  14. assertThat(redisTemplate).isNotNull();
  15. }
  16. @Test
  17. public void storeAndFind() {
  18. redisTemplate.opsForHash().put("test-key", "test-hash-key", "value123");
  19. assertThat(redisTemplate.opsForHash().get("test-key", "test-hash-key")).isEqualTo("value123");
  20. }
  21. @Test
  22. public void delete() {
  23. redisTemplate.opsForHash().put("test-key", "test-hash-key", "value123");
  24. redisTemplate.opsForHash().delete("test-key", "test-hash-key");
  25. assertThat(redisTemplate.opsForHash().get("test-key", "test-hash-key")).isNull();
  26. }
  27. }