@@ -0,0 +1,2696 @@
+package com.crimsonhexagon.rsm;%0A%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.never;%0Aimport static org.mockito.Mockito.spy;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport net.bytebuddy.utility.RandomString;%0Aimport org.apache.catalina.Context;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.mockito.Mockito;%0A%0Aimport java.io.IOException;%0A%0Apublic class SessionSizeTest %7B%0A    %0A    @Test%0A    public void testValidAttrSize() throws Exception %7B%0A        RedisSession rs = session(RedisSessionManager.DO_NOT_CHECK, RedisSessionManager.DO_NOT_CHECK, new MockRedisSessionClient());%0A        String s = RandomString.make(128);%0A        rs.setAttribute(%22foo%22, s);%0A        Assert.assertTrue(%22attribute not stored%22, s.equals(rs.getAttribute(%22foo%22)));%0A    %7D%0A%0A    @Test%0A    public void testLargeAttrSize() throws Exception %7B%0A        String s = RandomString.make(128);%0A        final int length = new MockRedisSessionClient().getEncodedSize(s);%0A        RedisSession rs = session(length, RedisSessionManager.DO_NOT_CHECK, new MockRedisSessionClient());%0A        // == to max, should be stored%0A        rs.setAttribute(%22foo%22, s);%0A        Assert.assertTrue(%22attribute not stored%22, s.equals(rs.getAttribute(%22foo%22)));%0A        %0A        s = RandomString.make(length + 1);%0A        rs.setAttribute(%22bar%22, s);%0A        Assert.assertNull(%22attribute %3E max length stored%22, rs.getAttribute(%22bar%22));%0A    %7D%0A    %0A    @Test%0A    public void testLargeSessionSize() throws Exception %7B%0A        String s = RandomString.make(128);%0A        RedisSessionClient c = mock(RedisSessionClient.class);%0A        when(c.getEncodedSize(Mockito.any())).thenReturn(Integer.MAX_VALUE);%0A        RedisSession rs = session(RedisSessionManager.DO_NOT_CHECK, 1, new MockRedisSessionClient());%0A        // not checking attr, should be stored%0A        rs.setAttribute(%22foo%22, s);%0A        Assert.assertTrue(%22attribute not stored%22, s.equals(rs.getAttribute(%22foo%22)));%0A        rs.setId(%22sessionId%22);%0A        rs.getManager().save(rs, true);%0A        verify(c, never()).save(Mockito.anyString(), Mockito.any());%0A    %7D%0A    %0A    private RedisSession session(int maxAttrSize, int maxSessionSize, RedisSessionClient client) throws IOException %7B%0A        RedisSession rs = new RedisSession();%0A        RedisSessionManager mgr = spy(RedisSessionManager.class);%0A        when(mgr.getMaxSessionAttributeSize()).thenReturn(maxAttrSize);%0A        when(mgr.getMaxSessionSize()).thenReturn(maxSessionSize);%0A        when(mgr.getContext()).thenReturn(mock(Context.class));%0A        when(mgr.getClient()).thenReturn(client);%0A        rs.setManager(mgr);%0A        rs.setValid(true);%0A        return rs;%0A    %7D%0A    %0A%7D%0A

add unit test for session size checking.