### Question:
SessionLogoutGuardFactory { public static Session useBestWrapper(final Session session) { if (session instanceof JackrabbitWrapper || session instanceof JcrWrapper) { return session; } else if (session instanceof JackrabbitSession) { return new JackrabbitWrapper((JackrabbitSession) session); } else if (session != null) { return new JcrWrapper(session); } return null; } private  SessionLogoutGuardFactory(); static Session useBestWrapper(final Session session);  }### Answer:
@Test public void testUseBestWrapper() { assertNull("null should pass through", SessionLogoutGuardFactory.useBestWrapper(null)); JackrabbitSession mockJackSession = mock(JackrabbitSession.class); Session jackWrapper = SessionLogoutGuardFactory.useBestWrapper(mockJackSession); assertNotNull("wrap jackSession should not be null", jackWrapper); assertTrue("jackWrapper instance of JackrabbitSessionIWrap: " + jackWrapper.getClass().getName(), jackWrapper instanceof JackrabbitSessionIWrap); assertNotNull("jackWrapper.unwrapSession() instanceof JackrabbitSession", ((JackrabbitSessionIWrap) jackWrapper).unwrapSession()); jackWrapper.logout(); verify(mockJackSession, times(0)).logout(); assertSame("jackWrapper should not get rewrapped", jackWrapper, SessionLogoutGuardFactory.useBestWrapper(jackWrapper)); Session mockJcrSession = mock(Session.class); Session jcrWrapper = SessionLogoutGuardFactory.useBestWrapper(mockJcrSession); assertNotNull("wrap jcrSession should not be null", jcrWrapper); assertTrue("jcrWrapper instance of SessionIWrap: " + jcrWrapper.getClass().getName(), jcrWrapper instanceof SessionIWrap); assertNotNull("jcrWrapper.unwrapSession() instanceof Session", ((SessionIWrap) jcrWrapper).unwrapSession()); jcrWrapper.logout(); verify(mockJcrSession, times(0)).logout(); assertSame("jcrWrapper should not get rewrapped", jcrWrapper, SessionLogoutGuardFactory.useBestWrapper(jcrWrapper)); }