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

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1762912 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Julian Sedding 2016-09-30 14:02:33 +00:00
parent faf00d87f6
commit 4918d66253
2 changed files with 16 additions and 0 deletions

View File

@ -62,6 +62,11 @@ public boolean add(final T 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 void testWeakList() {
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());
}
}