ClientPersistentFieldStorageImpl implements ClientPersistentFieldStorage { public void postChange(String pageName, String componentId, String fieldName, Object newValue) { refreshMap(); Key key = new Key(pageName, componentId, fieldName); if (newValue == null) persistedValues.remove(key); else { if (!Serializable.class.isInstance(newValue)) throw new IllegalArgumentException(String.format("State persisted on the client must be serializable, but %s does not implement the Serializable interface.", newValue)); persistedValues.put(key, newValue); } clientData = null; } ClientPersistentFieldStorageImpl(Request request, ClientDataEncoder clientDataEncoder, SessionPersistedObjectAnalyzer analyzer); void updateLink(Link link); Collection<PersistentFieldChange> gatherFieldChanges(String pageName); void discardChanges(String pageName); void postChange(String pageName, String componentId, String fieldName, Object newValue);  }
@Test public void value_not_serializable() { Request request = mockRequest(null); Object badBody = new Object() { @Override public String toString() { return "<BadBoy>"; } }; replay(); ClientPersistentFieldStorage storage = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer); try { storage.postChange("Foo", "bar.baz", "woops", badBody); unreachable(); } catch (IllegalArgumentException ex) { assertEquals( ex.getMessage(), "State persisted on the client must be serializable, but <BadBoy> does not implement the Serializable interface."); } verify(); }
@Test public void corrupt_client_data() { Request request = mockRequest("H4sIAAAAAAAAAEWQsUoDQRCGJxdDTEwRU2hlZ71pBQ"); replay(); ClientPersistentFieldStorage storage = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer); try { storage.postChange("Foo", "bar.baz", "woops", 99); unreachable(); } catch (RuntimeException ex) { assertEquals(ex.getMessage(), "Serialized client state was corrupted. This may indicate that too much state is being stored, which can cause the encoded string to be truncated by the client web browser."); assertNotNull(ex.getCause()); } verify(); }