HttpSessionTransactionTokenStore implements TransactionTokenStore { @Override public String getAndClear(TransactionToken token) { String key = createSessionAttributeName(token); HttpSession session = getSession(); Object mutex = getMutex(session); TokenHolder tokenHolder; synchronized (mutex) { tokenHolder = (TokenHolder) session.getAttribute(key); if (tokenHolder != null) { session.setAttribute(key, new TokenHolder(null, System .currentTimeMillis())); } } if (tokenHolder != null) { return tokenHolder.getToken(); } return null; } HttpSessionTransactionTokenStore();  HttpSessionTransactionTokenStore(
            int transactionTokenSizePerTokenName);  HttpSessionTransactionTokenStore(
            int transactionTokenSizePerTokenName, int retryCreateTokenName);  HttpSessionTransactionTokenStore(
            final TokenStringGenerator generator,
            final int transactionTokenSizePerTokenName,
            final int retryCreateTokenName); @Override String getAndClear(TransactionToken token); @Override void remove(TransactionToken token); @Override String createAndReserveTokenKey(String tokenName); @Override void store(TransactionToken token); static final String TOKEN_HOLDER_SESSION_ATTRIBUTE_PREFIX; static final int NO_OF_TOKENS_PER_TOKEN_NAME; static final int DEFAULT_RETRY_CREATE_TOKEN_NAME; }
@Test public void testGetAndClear01() { HttpSession session = new MockHttpSession(); request.setSession(session); TransactionToken token = new TransactionToken("TransactionToken"); store = new HttpSessionTransactionTokenStore(); String actuals = store.getAndClear(token); assertThat(actuals, is(nullValue())); }
@Test(expected = IllegalArgumentException.class) public void testGetAndClear_tokenIsNull() throws Exception { try { store = new HttpSessionTransactionTokenStore(); store.getAndClear(null); } catch (Exception e) { assertThat(e.getMessage(), is("token must not be null")); throw e; } }