@Test public void simpleDetach() { List<String> original = ImmutableList.of("HELLO", "THERE"); underTest = new DetachingList<>(original, allowDetach, detach); when(allowDetach.getAsBoolean()).thenReturn(true); when(detach.apply(anyObject())).thenAnswer(returnsFirstArg()); assertThat(underTest.remove("THERE"), is(true)); assertThat(underTest.add("WORLD"), is(true)); assertThat(underTest, contains("HELLO", "WORLD")); assertThat(original, contains("HELLO", "THERE")); InOrder inOrder = inOrder(allowDetach, detach); inOrder.verify(allowDetach).getAsBoolean(); inOrder.verify(detach).apply("HELLO"); inOrder.verify(detach).apply("THERE"); verifyNoMoreInteractions(allowDetach, detach); }
@Override public boolean contains(final Object key) { return backing.contains(key); }
DetachingList extends ForwardingList<V> { @Override public boolean contains(final Object key) { return backing.contains(key); } }
DetachingList extends ForwardingList<V> { @Override public boolean contains(final Object key) { return backing.contains(key); } DetachingList(final List<V> backing, final BooleanSupplier allowDetach, final Function<V, V> detach);  DetachingList(final List<V> backing, final Function<V, V> detach); }
DetachingList extends ForwardingList<V> { @Override public boolean contains(final Object key) { return backing.contains(key); } DetachingList(final List<V> backing, final BooleanSupplier allowDetach, final Function<V, V> detach);  DetachingList(final List<V> backing, final Function<V, V> detach); @Override boolean contains(final Object key); @Override boolean containsAll(final Collection<?> collection); @Override int indexOf(final Object element); @Override int lastIndexOf(final Object element); @Override boolean isEmpty(); @Override int size(); @Override boolean equals(final Object object); @Override int hashCode(); @Override String toString(); }
DetachingList extends ForwardingList<V> { @Override public boolean contains(final Object key) { return backing.contains(key); } DetachingList(final List<V> backing, final BooleanSupplier allowDetach, final Function<V, V> detach);  DetachingList(final List<V> backing, final Function<V, V> detach); @Override boolean contains(final Object key); @Override boolean containsAll(final Collection<?> collection); @Override int indexOf(final Object element); @Override int lastIndexOf(final Object element); @Override boolean isEmpty(); @Override int size(); @Override boolean equals(final Object object); @Override int hashCode(); @Override String toString();  }