### Question:
RqueueListenerBaseConfig { @Bean public RqueueConfig rqueueConfig( ConfigurableBeanFactory beanFactory, @Value("${rqueue.version.key:__rq::version}") String versionKey, @Value("${rqueue.db.version:}") Integer dbVersion) { boolean sharedConnection = false; if (simpleRqueueListenerContainerFactory.getRedisConnectionFactory() == null) { sharedConnection = true; simpleRqueueListenerContainerFactory.setRedisConnectionFactory( beanFactory.getBean(RedisConnectionFactory.class)); } RedisConnectionFactory connectionFactory = simpleRqueueListenerContainerFactory.getRedisConnectionFactory(); int version; if (dbVersion == null) { version = RedisUtils.updateAndGetVersion(connectionFactory, versionKey, 2); } else if (dbVersion >= 1 && dbVersion <= MAX_DB_VERSION) { RedisUtils.setVersion(connectionFactory, versionKey, dbVersion); version = dbVersion; } else { throw new IllegalStateException("Rqueue db version '" + dbVersion + "' is not correct"); } return new RqueueConfig(connectionFactory, sharedConnection, version); }  @Bean RqueueConfig rqueueConfig(
      ConfigurableBeanFactory beanFactory,
      @Value("${rqueue.version.key:__rq::version}") String versionKey,
      @Value("${rqueue.db.version:}") Integer dbVersion); @Bean RqueueWebConfig rqueueWebConfig(); @Bean RqueueSchedulerConfig rqueueSchedulerConfig(); @Bean RedisTemplate<String, Long> rqueueRedisLongTemplate(RqueueConfig rqueueConfig); @Bean RqueueRedisListenerContainerFactory rqueueRedisListenerContainerFactory(); @Bean DelayedMessageScheduler delayedMessageScheduler(); @Bean ProcessingMessageScheduler processingMessageScheduler(); @Bean RqueueRedisTemplate<String> stringRqueueRedisTemplate(RqueueConfig rqueueConfig); @Bean RqueueLockManager rqueueLockManager(
      @Qualifier("stringRqueueRedisTemplate") RqueueRedisTemplate<String> rqueueRedisTemplate); @Bean JtwigViewResolver rqueueViewResolver(); static final int MAX_DB_VERSION; }### Answer:
@Test public void testRqueueConfigSetConnectionFactoryFromBeanFactory() throws IllegalAccessException { doReturn(redisConnection).when(redisConnectionFactory).getConnection(); SimpleRqueueListenerContainerFactory factory = new SimpleRqueueListenerContainerFactory(); RqueueListenerConfig rqueueSystemConfig = createConfig(factory); doReturn(redisConnectionFactory).when(beanFactory).getBean(RedisConnectionFactory.class); assertNotNull(rqueueSystemConfig.rqueueConfig(beanFactory, "__rq::version", null)); assertNotNull(factory.getRedisConnectionFactory()); }
@Test public void testRqueueConfigSetConnectionFactoryFromBeanFactoryWithDbVersion() throws IllegalAccessException { doReturn(redisConnection).when(redisConnectionFactory).getConnection(); SimpleRqueueListenerContainerFactory factory = new SimpleRqueueListenerContainerFactory(); RqueueListenerConfig rqueueSystemConfig = createConfig(factory); doReturn(redisConnectionFactory).when(beanFactory).getBean(RedisConnectionFactory.class); assertNotNull(rqueueSystemConfig.rqueueConfig(beanFactory, "__rq::version", 1)); assertNotNull(factory.getRedisConnectionFactory()); }
@Test public void testRqueueConfigInvalidDbVersion() throws IllegalAccessException { SimpleRqueueListenerContainerFactory factory = new SimpleRqueueListenerContainerFactory(); RqueueListenerConfig rqueueSystemConfig = createConfig(factory); doReturn(redisConnectionFactory).when(beanFactory).getBean(RedisConnectionFactory.class); Assertions.assertThrows( IllegalStateException.class, () -> rqueueSystemConfig.rqueueConfig(beanFactory, "__rq::version", 3)); }
@Test public void testRqueueConfigDoesNotChangeConnectionFactory() throws IllegalAccessException { doReturn(redisConnection).when(redisConnectionFactory).getConnection(); SimpleRqueueListenerContainerFactory factory = new SimpleRqueueListenerContainerFactory(); factory.setRedisConnectionFactory(redisConnectionFactory); RqueueListenerConfig rqueueSystemConfig = createConfig(factory); assertNotNull(rqueueSystemConfig.rqueueConfig(beanFactory, "__rq::version", null)); assertNotNull(factory.getRedisConnectionFactory()); assertEquals(redisConnectionFactory, factory.getRedisConnectionFactory()); verify(beanFactory, times(0)).getBean(RedisConnectionFactory.class); }