RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
final StringRedisTemplate template = spy(new StringRedisTemplate(factory));
when(factory.getConnection()).thenReturn(conn);
doReturn(stringConn).when(template).preProcessConnection(eq(conn), anyBoolean());
template.execute(new SessionCallback<Object>() {
@SuppressWarnings("rawtypes")
public Object execute(RedisOperations operations) {
checkConnection(template, stringConn);
template.discard();
assertSame(template, operations);