### Question:
StatelessSessionFactory { public static String getJWTFromSessionID(SessionID sessionID, boolean cleanupC66Encoding) { if (sessionID == null || sessionID.toString().isEmpty()) { return null; } String tail = sessionID.getTail(); if (tail == null) { return null; } if (tail.isEmpty()) { return null; } if (cleanupC66Encoding && sessionID.isC66Encoded()) { tail = tail.replace('=', '.').replace('/', '_').replace('+', '-'); } return tail; } @Inject  StatelessSessionFactory(StatelessJWTCache cache,
                                   SessionServerConfig sessionServerConfig,
                                   SessionServiceConfig sessionServiceConfig); boolean containsJwt(HttpServletRequest request); boolean containsJwt(String tokenId); boolean containsJwt(SessionID sid); StatelessSession generate(String tokenId); SessionInfo getSessionInfo(SessionID sessionID); StatelessSession generate(SessionInfo info); StatelessSession generate(InternalSession internalSession); StatelessSession generate(SessionID sessionID); static String getJWTFromSessionID(SessionID sessionID, boolean cleanupC66Encoding);  }### Answer:
@Test public void shouldExtractJWTFromSessionID() { SessionID id = mock(SessionID.class); given(id.getTail()).willReturn("badger="); given(id.isC66Encoded()).willReturn(true); assertThat(StatelessSessionFactory.getJWTFromSessionID(id, true)).isEqualTo("badger."); }
@Test public void shouldReturnNullIfNoJWTInSessionID() { SessionID id = mock(SessionID.class); given(id.getTail()).willReturn(null); assertThat(StatelessSessionFactory.getJWTFromSessionID(id, true)).isNull(); }
@Test public void shouldReturnNullIfNoSessionIDProvided() { assertThat(StatelessSessionFactory.getJWTFromSessionID(null, true)).isNull(); }
@Test public void shouldUndoC66DecodingDamageToJwt() { final String fullJwtAlphabet = ".-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; final SessionID sessionID = new SessionID("*@" + fullJwtAlphabet); final String result = StatelessSessionFactory.getJWTFromSessionID(sessionID, true); assertThat(result).isEqualTo(fullJwtAlphabet); }
@Test public void shouldNotUndoC66DecodingIfNotAsked() { final String fullJwtAlphabet = ".-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; final SessionID sessionID = new SessionID("*@" + fullJwtAlphabet); final String result = StatelessSessionFactory.getJWTFromSessionID(sessionID, false); assertThat(result).isEqualTo(sessionID.getTail()); }
@Test public void shouldNotUndoC66DecodingIfNotEncoded() { final String fullJwtAlphabet = ".-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; final SessionID sessionID = new SessionID("notencoded@" + fullJwtAlphabet); final String result = StatelessSessionFactory.getJWTFromSessionID(sessionID, true); assertThat(result).isEqualTo(fullJwtAlphabet); assertThat(sessionID.isC66Encoded()).isFalse(); }