Create ExpiringSession which extends Session

This provides a better separation for consumers of the API. Most users are
likely not interested in checking to see if a session is expired so they
can focus on the Session API.

Fixes #28
This commit is contained in:
Rob Winch
2014-07-30 11:56:43 -05:00
parent f1fa380bdd
commit 903017285b
11 changed files with 73 additions and 59 deletions

View File

@@ -50,7 +50,7 @@ public class MapSessionTests {
assertThat(session.hashCode()).isEqualTo(session.getId().hashCode());
}
static class CustomSession implements Session {
static class CustomSession implements ExpiringSession {
@Override
public long getCreationTime() {

View File

@@ -17,6 +17,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession;
@@ -25,7 +26,7 @@ import org.springframework.session.data.redis.RedisOperationsSessionRepository.R
@RunWith(MockitoJUnitRunner.class)
public class RedisOperationsSessionRepositoryTests {
@Mock
RedisOperations<String,Session> redisOperations;
RedisOperations<String,ExpiringSession> redisOperations;
@Mock
BoundHashOperations<String, Object, Object> boundHashOperations;
@Captor
@@ -40,7 +41,7 @@ public class RedisOperationsSessionRepositoryTests {
@Test
public void createSessionDefaultMaxInactiveInterval() throws Exception {
Session session = redisRepository.createSession();
ExpiringSession session = redisRepository.createSession();
assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession().getMaxInactiveInterval());
}
@@ -48,7 +49,7 @@ public class RedisOperationsSessionRepositoryTests {
public void createSessionCustomMaxInactiveInterval() throws Exception {
int interval = 1;
redisRepository.setDefaultMaxInactiveInterval(interval);
Session session = redisRepository.createSession();
ExpiringSession session = redisRepository.createSession();
assertThat(session.getMaxInactiveInterval()).isEqualTo(interval);
}