HTTPCLIENT-1772: [OSGi] WeakList needs to support "clear" method

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1762913 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Julian Sedding 2016-09-30 14:08:12 +00:00
parent 07fe1b7cdb
commit b99a5138cc
2 changed files with 16 additions and 0 deletions

View File

@ -62,6 +62,11 @@ class WeakList<T> extends AbstractList<T> {
return innerList.add(new WeakReference<T>(t));
}
@Override
public void clear() {
innerList.clear();
}
private void checkReferences() {
final ListIterator<WeakReference<T>> references = innerList.listIterator();
while (references.hasNext()) {

View File

@ -59,4 +59,15 @@ public class WeakListTest {
assertTrue(thrown);
}
@Test
public void clearSupported() {
final WeakList<Object> list = new WeakList<Object>();
list.add("hello");
assertEquals(1, list.size());
list.clear();
assertEquals(0, list.size());
}
}