### Question:
SessionAdapter implements TokenAdapter<InternalSession> { public InternalSession fromToken(Token token) { String jsonBlob = blobUtils.getBlobAsString(token); int index = findIndexOfValidField(jsonBlob); String latestAccessTime = token.getValue(SessionTokenField.LATEST_ACCESS_TIME.getField()); if (latestAccessTime != null && index != -1) { String fieldName = SessionTokenField.LATEST_ACCESS_TIME.getInternalSessionFieldName(); String jsonField = JSONSerialisation.jsonAttributeName(fieldName); String addition = jsonField + latestAccessTime + ","; jsonBlob = jsonBlob.substring(0, index) + addition + jsonBlob.substring(index, jsonBlob.length()); } InternalSession session = serialisation.deserialise(jsonBlob, InternalSession.class); if (session.getSessionHandle() == null) { session.setSessionHandle(token.<String>getValue(SessionTokenField.SESSION_HANDLE.getField())); } return session; } @Inject  SessionAdapter(TokenIdFactory tokenIdFactory, CoreTokenConfig config,
                          JSONSerialisation serialisation, TokenBlobUtils blobUtils); Token toToken(InternalSession session); InternalSession fromToken(Token token); int findIndexOfValidField(String blob); String filterLatestAccessTime(Token token);  }### Answer:
@Test public void shouldRestoreLatestAccessTimeFromAttribute() { String latestAccessTime = "12345"; Token token = new Token("badger", TokenType.SESSION); token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); token.setBlob("{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true,\"maxCachingTime\":3}".getBytes()); ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); JSONSerialisation serialisation = new JSONSerialisation(mapper); adapter = new SessionAdapter(tokenIdFactory, coreTokenConfig, serialisation, blobUtils); InternalSession session = adapter.fromToken(token); long epochedSeconds = currentTimeMillis() / 1000; long idleTime = session.getIdleTime(); assertTrue(idleTime < epochedSeconds); }
@Test public void shouldRestoreLatestAccessTimeFromAttribute() { String latestAccessTime = "12345"; Token token = new Token("badger", TokenType.SESSION); token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); token.setBlob("{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true,\"maxCachingTime\":3}".getBytes()); ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); JSONSerialisation serialisation = new JSONSerialisation(mapper); adapter = new SessionAdapter(tokenIdFactory, coreTokenConfig, serialisation, blobUtils); InternalSession session = adapter.fromToken(token); long epochedSeconds = System.currentTimeMillis() / 1000; long idleTime = session.getIdleTime(); assertTrue(idleTime < epochedSeconds); }