@Test
public void testEncodeUrl() {

  SessionConfiguration sc = new SessionConfiguration();
  sc.setSessionIdName("asession");
  urlSessionTracking.configure(sc);
  RequestWithSession request = mock(RequestWithSession.class, withSettings().extraInterfaces(HttpServletRequest.class));
  RepositoryBackedSession session = mock(RepositoryBackedSession.class);
  when(request.getRepositoryBackedSession(false)).thenReturn(session);
  when(session.isValid()).thenReturn(Boolean.FALSE);
  String url = urlSessionTracking.encodeUrl(request, "http://www.example.com");
  assertEquals("Session is not valid, so URL should stay the same", "http://www.example.com", url);
  when(session.isValid()).thenReturn(Boolean.TRUE);
  when(session.getId()).thenReturn("1234");
  url = urlSessionTracking.encodeUrl(request, "http://www.example.com");
  assertEquals("Session is valid, so URL should be encoded", "http://www.example.com;asession=1234", url);
  url = urlSessionTracking.encodeUrl(request, "http://www.example.com/abc");
  assertEquals("Session is valid, so URL should be encoded", "http://www.example.com/abc;asession=1234", url);
  url = urlSessionTracking.encodeUrl(request, "http://www.example.com/def?abc");
  assertEquals("Session is valid, so URL should be encoded", "http://www.example.com/def;asession=1234?abc", url);
  url = urlSessionTracking.encodeUrl(request, "http://www.example.com/def?abc?");
  assertEquals("Session is valid, so URL should be encoded", "http://www.example.com/def;asession=1234?abc?", url);
}