Add a test case in AbstractMultiValuedMapTest for AbstractMultiValuedMapTest.MultiValuedMapIterator (#108)

This commit is contained in:
dota17 2019-11-01 23:42:00 +08:00 committed by Gary Gregory
parent 37c770f29e
commit 954c29f969
2 changed files with 66 additions and 0 deletions

View File

@ -104,6 +104,17 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
return true;
}
/**
* Returns true if the maps produced by {@link #makeObject()} and
* {@link #makeFullMap()} supports set value.
* <p>
* Default implementation returns false. Override if your collection class
* supports set value.
*/
public boolean isHashSetValue() {
return false;
}
@Override
public boolean isTestSerialization() {
return true;
@ -778,6 +789,56 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
}
}
public void testMultiValuedMapIterator() {
final MultiValuedMap<K, V> map = makeFullMap();
final MapIterator<K, V> it = map.mapIterator();
try {
it.getKey();
fail();
} catch (final IllegalStateException ise) {
}
try {
it.getValue();
fail();
} catch (final IllegalStateException ise) {
}
if (isAddSupported()) {
try {
it.setValue((V) "V");
fail();
} catch (final IllegalStateException ise) {
}
}
if (!isHashSetValue() && isAddSupported()) {
assertTrue(it.hasNext() );
assertEquals("one", it.next());
assertEquals("one", it.getKey());
assertEquals("uno", it.getValue());
assertEquals("one", it.next());
assertEquals("one", it.getKey());
assertEquals("un", it.getValue());
assertEquals("two", it.next());
assertEquals("two", it.getKey());
assertEquals("dos", it.getValue());
assertEquals("two", it.next());
assertEquals("two", it.getKey());
assertEquals("deux", it.getValue());
assertEquals("three", it.next());
assertEquals("three", it.getKey());
assertEquals("tres", it.getValue());
assertEquals("three", it.next());
assertEquals("three", it.getKey());
assertEquals("trois", it.getValue());
try {
it.setValue((V) "threetrois");
fail();
} catch (final UnsupportedOperationException e) {
}
}
}
// -----------------------------------------------------------------------
// Manual serialization testing as this class cannot easily
// extend the AbstractTestMap

View File

@ -53,6 +53,11 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
return new HashSetValuedHashMap<>();
}
@Override
public boolean isHashSetValue() {
return true;
}
// -----------------------------------------------------------------------
@SuppressWarnings("unchecked")
public void testSetValuedMapAdd() {