RedisRepository implements IDbRepository<T> { @Override public T add(T entry) { if (entry == null) { return null; } T result = null; try (Jedis jedis = this.jedisPool.getResource()) { T existingObject = this.getById(entry.getId()); if (existingObject == null) { String entryKey = String.format("%s:%s", this.entryNamespace, entry.getId()); String entryValue = jedis.set(entryKey, this.jsonConverter.toJson(entry)); Long entryId = jedis.sadd(this.idNamespace, entry.getId()); result = this.getById(entry.getId()); } } return result; } RedisRepository(Class<T> type);  RedisRepository(Class<T> entry, JedisPool pool); @Override T getById(String id); @Override List<T> getAll(); @Override T add(T entry); @Override T update(T entry); @Override T delete(String id);  }
@Test public void add() { Entity entry = new Entity(); String expectedResult = entry.getId(); String actualResult = this.repository.add(entry).getId(); Assert.assertEquals(expectedResult, actualResult); }