RetainState implements Iterable<Object> { @SuppressWarnings("unchecked") public <T> T remove(int id) { if (state != null) { Object value = state.get(id); state.remove(id); if (value instanceof RetainState) { ((RetainState) value).setIsRetaining(false); } return (T) value; } return null; } @SuppressWarnings("unchecked")  RetainState(Object retainedState); static RetainState from(Object host); Object onRetain(); boolean isRetaining(); void destroy(); @SuppressWarnings("unchecked") T retain(int id, OnCreate<T> onCreate); @SuppressWarnings("unchecked") T get(int id); @SuppressWarnings("unchecked") T remove(int id); @Override @SuppressWarnings("unchecked") Iterator<Object> iterator(); static final OnCreate<RetainState> CREATE; }
@Test public void remove_returns_null_for_nonexistent_object() throws Exception { RetainState retainState = new RetainState(null); Object result = retainState.remove(0); assertNull(result); }