Merge branch 'pr-250'

This closes #250
This commit is contained in:
Bruno P. Kinoshita 2021-10-09 14:53:22 +13:00
commit 5b0f22a750
4 changed files with 40 additions and 42 deletions

View File

@ -455,6 +455,9 @@
<contributor> <contributor>
<name>Chen Guoping</name> <name>Chen Guoping</name>
</contributor> </contributor>
<contributor>
<name>Stefano Cordio</name>
</contributor>
</contributors> </contributors>
<dependencies> <dependencies>

View File

@ -79,6 +79,9 @@
<action issue="COLLECTIONS-796" type="fix" dev="kinow" due-to="Clemens Kurz"> <action issue="COLLECTIONS-796" type="fix" dev="kinow" due-to="Clemens Kurz">
SetUniqueList.createSetBasedOnList doesn't add list elements to return value. SetUniqueList.createSetBasedOnList doesn't add list elements to return value.
</action> </action>
<action issue="COLLECTIONS-799" type="fix" dev="kinow" due-to="Stefano Cordio">
UnmodifiableNavigableSet can be modified by pollFirst() and pollLast().
</action>
<!-- ADD --> <!-- ADD -->
<action issue="COLLECTIONS-760" dev="kinow" type="add" due-to="Isira Seneviratne"> <action issue="COLLECTIONS-760" dev="kinow" type="add" due-to="Isira Seneviratne">
Add tests for MapUtils. Add tests for MapUtils.

View File

@ -107,6 +107,22 @@ public final class UnmodifiableNavigableSet<E>
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/**
* @since 4.5
*/
@Override
public E pollFirst() {
throw new UnsupportedOperationException();
}
/**
* @since 4.5
*/
@Override
public E pollLast() {
throw new UnsupportedOperationException();
}
@Override @Override
public boolean retainAll(final Collection<?> coll) { public boolean retainAll(final Collection<?> coll) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -27,6 +27,8 @@ import junit.framework.Test;
import org.apache.commons.collections4.BulkTest; import org.apache.commons.collections4.BulkTest;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Extension of {@link AbstractNavigableSetTest} for exercising the * Extension of {@link AbstractNavigableSetTest} for exercising the
* {@link UnmodifiableNavigableSet} implementation. * {@link UnmodifiableNavigableSet} implementation.
@ -48,7 +50,7 @@ public class UnmodifiableNavigableSetTest<E> extends AbstractNavigableSetTest<E>
//------------------------------------------------------------------- //-------------------------------------------------------------------
@Override @Override
public NavigableSet<E> makeObject() { public NavigableSet<E> makeObject() {
return UnmodifiableNavigableSet.unmodifiableNavigableSet(new TreeSet<E>()); return UnmodifiableNavigableSet.unmodifiableNavigableSet(new TreeSet<>());
} }
@Override @Override
@ -95,11 +97,7 @@ public class UnmodifiableNavigableSetTest<E> extends AbstractNavigableSetTest<E>
public void testDecorateFactory() { public void testDecorateFactory() {
final NavigableSet<E> set = makeFullCollection(); final NavigableSet<E> set = makeFullCollection();
assertSame(set, UnmodifiableNavigableSet.unmodifiableNavigableSet(set)); assertSame(set, UnmodifiableNavigableSet.unmodifiableNavigableSet(set));
assertThrows(NullPointerException.class, () -> UnmodifiableNavigableSet.unmodifiableNavigableSet(null));
try {
UnmodifiableNavigableSet.unmodifiableNavigableSet(null);
fail();
} catch (final NullPointerException ex) {}
} }
/** /**
@ -107,48 +105,26 @@ public class UnmodifiableNavigableSetTest<E> extends AbstractNavigableSetTest<E>
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void verifyUnmodifiable(final Set<E> set) { public void verifyUnmodifiable(final Set<E> set) {
try { assertThrows(UnsupportedOperationException.class, () -> set.add((E) "value"));
set.add((E) "value"); assertThrows(UnsupportedOperationException.class, () -> set.addAll(new TreeSet<>()));
fail("Expecting UnsupportedOperationException."); assertThrows(UnsupportedOperationException.class, () -> set.clear());
} catch (final UnsupportedOperationException e) { assertThrows(UnsupportedOperationException.class, () -> set.iterator().remove());
// expected assertThrows(UnsupportedOperationException.class, () -> set.remove("x"));
} assertThrows(UnsupportedOperationException.class, () -> set.removeAll(array));
try { assertThrows(UnsupportedOperationException.class, () -> set.removeIf(element -> true));
set.addAll(new TreeSet<E>()); assertThrows(UnsupportedOperationException.class, () -> set.retainAll(array));
fail("Expecting UnsupportedOperationException.");
} catch (final UnsupportedOperationException e) { if (set instanceof NavigableSet) {
// expected final NavigableSet<E> navigableSet = (NavigableSet<E>) set;
} assertThrows(UnsupportedOperationException.class, () -> navigableSet.pollFirst());
try { assertThrows(UnsupportedOperationException.class, () -> navigableSet.pollLast());
set.clear();
fail("Expecting UnsupportedOperationException.");
} catch (final UnsupportedOperationException e) {
// expected
}
try {
set.remove("x");
fail("Expecting UnsupportedOperationException.");
} catch (final UnsupportedOperationException e) {
// expected
}
try {
set.removeAll(array);
fail("Expecting UnsupportedOperationException.");
} catch (final UnsupportedOperationException e) {
// expected
}
try {
set.retainAll(array);
fail("Expecting UnsupportedOperationException.");
} catch (final UnsupportedOperationException e) {
// expected
} }
} }
public void testComparator() { public void testComparator() {
setupSet(); setupSet();
final Comparator<? super E> c = set.comparator(); final Comparator<? super E> c = set.comparator();
assertTrue("natural order, so comparator should be null", c == null); assertNull("natural order, so comparator should be null", c);
} }