/*
 * Copyright 2014-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.session.data.redis.config.annotation.web.http;

import org.junit.Test;

import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.session.data.redis.config.ConfigureRedisAction;
import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration.EnableRedisKeyspaceNotificationsInitializer;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyZeroInteractions;

public class RedisHttpSessionConfigurationTests {

	@Test
	public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenNoOpThenNoInteractionWithConnectionFactory()
			throws Exception {
		RedisConnectionFactory factory = mock(RedisConnectionFactory.class);

		EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer(factory,
				ConfigureRedisAction.NO_OP);

		init.afterPropertiesSet();

		verifyZeroInteractions(factory);
	}

}

@@ -711,14 +711,210 @@
 nit.
-Test;%0A
+Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0A%0Aimport org.springframework.data.redis.connection.RedisConnection;
 %0Aimp
@@ -1229,28 +1229,242 @@
 org.
-mockito.Mockito.mock
+assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;%0Aimport static org.mockito.BDDMockito.given;%0Aimport static org.mockito.BDDMockito.willThrow;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.verify
 ;%0Aim
@@ -1520,16 +1520,51 @@
 tions;%0A%0A
+@RunWith(MockitoJUnitRunner.class)%0A
 public c
@@ -1609,444 +1609,1550 @@
 s %7B%0A
-%0A%09@Test%0A%09public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenNoOpThenNoInteractionWithConnectionFactory()%0A%09%09%09throws Exception %7B%0A%09%09RedisConnectionFactory factory = mock(RedisConnectionFactory.class);%0A%0A%09%09EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer(factory,%0A%09%09%09%09ConfigureRedisAction.NO_OP);%0A%0A%09%09init.afterPropertiesSet();%0A%0A%09%09verifyZeroInteractions(factory);%0A%09%7D%0A
+%09@Mock%0A%09RedisConnectionFactory factory;%0A%09@Mock%0A%09RedisConnection connection;%0A%0A%09@Before%0A%09public void setup() %7B%0A%09%09given(this.factory.getConnection()).willReturn(this.connection);%0A%09%7D%0A%0A%09@Test%0A%09public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenNoOpThenNoInteractionWithConnectionFactory()%0A%09%09%09throws Exception %7B%0A%09%09EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer(%0A%09%09%09%09this.factory, ConfigureRedisAction.NO_OP);%0A%0A%09%09init.afterPropertiesSet();%0A%0A%09%09verifyZeroInteractions(this.factory);%0A%09%7D%0A%0A%09@Test%0A%09public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenExceptionThenCloseConnection()%0A%09%09%09throws Exception %7B%0A%09%09ConfigureRedisAction action = mock(ConfigureRedisAction.class);%0A%09%09willThrow(new RuntimeException()).given(action).configure(this.connection);%0A%0A%09%09EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer(%0A%09%09%09%09this.factory, action);%0A%0A%09%09try %7B%0A%09%09%09init.afterPropertiesSet();%0A%09%09%09failBecauseExceptionWasNotThrown(Throwable.class);%0A%09%09%7D%0A%09%09catch (Throwable success) %7B%0A%09%09%7D%0A%0A%09%09verify(this.connection).close();%0A%09%7D%0A%0A%09@Test%0A%09public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenNoExceptionThenCloseConnection()%0A%09%09%09throws Exception %7B%0A%09%09ConfigureRedisAction action = mock(ConfigureRedisAction.class);%0A%0A%09%09EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer(%0A%09%09%09%09this.factory, action);%0A%0A%09%09init.afterPropertiesSet();%0A%0A%09%09verify(this.connection).close();%0A%09%7D
 %0A%7D%0A

Add Tests for Closing RedisConnection