RepositoryBackedSession { public void setAttribute(String key, Object value) { assertValid(); if (value == null) { removeAttribute(key); return; } Object oldValue; Attribute attr; if (sessionData.isNonCacheable(key)) { manager.getRepository().setSessionAttribute(sessionData, key, value); attr = getAttributeFromCache(key); } else { attr = retrieveAttribute(key, getAttributeFromCache(key)); } if (attr == null) { attr = new Attribute(value); attrs.put(key, attr); oldValue = null; } else { oldValue = attr.value; attr.value = value; attr.deleted = false; } attr.changed = true; dirty = true; checkUsedAndLock(); if (oldValue != value) { if (oldValue != null) { manager.getNotifier().attributeReplaced(this, key, oldValue); } manager.getNotifier().attributeAdded(this, key, value); } } RepositoryBackedSession(SessionData sessionData, SessionManager manager, SessionFactory factory); protected  RepositoryBackedSession(RepositoryBackedSession linked); void setMaxInactiveInterval(int maxInactiveInterval); Object getAttribute(String key); @SuppressWarnings({ "rawtypes" }) Enumeration getAttributeNames(); List<String> getAttributeNamesWithValues(); long getCreationTime(); String getId(); long getLastAccessedTime(); int getMaxInactiveInterval(); void invalidate(); void doInvalidate(boolean expired); boolean isNew(); void removeAttribute(String name); Attribute getAttributeFromCache(String name); void setAttribute(String key, Object value); synchronized void commit(); boolean isValid(); boolean isExpired(); boolean isDirty(); Runnable getCommitter(); SessionData getSessionData(); boolean isCommitted(); void setCommitted(boolean committed); SessionManager getSessionManager(); int getConcurrentUses();  }
@Test public void testSetAttribute() { RepositoryBackedSession rbs = new RepositoryBackedSession(sessionData, manager, factory); rbs.setAttribute("Test", "value"); verify(repository).getSessionAttribute(sessionData("1"), "Test"); verify(repository, never()).setSessionAttribute(any(SessionData.class), any(String.class), any()); verify(notifier, never()).attributeHasBeenRestored(refEq(rbs), eq("Test"), any()); verify(notifier, never()).attributeReplaced(refEq(rbs), eq("Test"), any()); verify(notifier).attributeAdded(refEq(rbs), eq("Test"), eq("value")); assertEquals("value", rbs.getAttribute("Test")); }
@Test public void testSetNonCachedAttribute() { sessionData.setMandatoryRemoteKeys(Collections.singleton("RemoteAttr")); RepositoryBackedSession rbs = new RepositoryBackedSession(sessionData, manager, factory); rbs.setAttribute("RemoteAttr", "value"); verify(repository).setSessionAttribute(eq(sessionData("1")), eq("RemoteAttr"), eq("value")); verify(notifier).attributeAdded(refEq(rbs), eq("RemoteAttr"), eq("value")); }