//2012-04-19 johnpfeiffer INCOMPLETE , requires EasyMock
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
public class UserSessionTest
{
private static final String CLASSVERSION = "0.3";
private HttpServletRequest testRequest = null;
private HttpSession testSession = null;
@Before public void initializeHttpServlet()
{
HttpServletRequest testRequest = EasyMock.createStrictMock( HttpServletRequest.class ); //strictmock forces correct method order calling
HttpSession testSession = EasyMock.createStrictMock( HttpSession.class );
String sessionId = EasyMock.createStrictMock( String.class );
EasyMock.expect( testRequest.getSession( false ) ).andReturn( null ); //record expected behaviour, e.g. getsession(false) returns null
EasyMock.expect( testRequest.getSession() ).andReturn( testSession ); //record expected behaviour
// EasyMock.expect( testSession.setMaxInactiveInterval( 60 ).andReturn( session ) );
// EasyMock.expect( testSession.getId().andReturn( "1" ) );
// session.setMaxInactiveInterval( minutes * 60 );
//unexpected method calls after this point will throw exceptions
}
@Test public void testUserSessionHttpServletRequest()
{
EasyMock.replay( testRequest );
EasyMock.replay( testSession );
UserSession u = new UserSession( testRequest );
if( u == null ){ fail( "Constructor unable to create UserSession" ); }
// EasyMock.verify( request );
}
@Test public void testUserSessionHttpServletRequestNull()
{
HttpServletRequest h = null;
UserSession u = null;
try{
u = new UserSession( h );
}catch( IllegalArgumentException iae )
{ return;
}
fail( "Expected IllegalArgumentException" );
}
@Test public void testUserSessionHttpServletRequestInt()
{
HttpServletRequest request = EasyMock.createMock( HttpServletRequest.class );
UserSession u = new UserSession( request , 10 );
if( u == null ){ fail( "Constructor unable to create UserSession" ); }
// long test = u.getInactiveExpiration();
// assertEquals( 10 , test );
}
@Test public void testGetVersion()
{
HttpServletRequest h = null;
UserSession u = new UserSession( h );
if( u != null )
{
assertEquals( CLASSVERSION , u.getClass() );
}
}
@Test
public void testIsValid()
{
fail("Not yet implemented");
}
@Test
public void testGetInactiveExpiration()
{
fail("Not yet implemented");
}
@Test
public void testGetLastAccess()
{
fail("Not yet implemented");
}
@Test
public void testIsExpired()
{
fail("Not yet implemented");
}
@Test
public void testSetValid()
{
fail("Not yet implemented");
}
@Test
public void testSetInvalid()
{
fail("Not yet implemented");
}
}