Fixed nested tests

This commit is contained in:
Harald Kuhr
2026-05-04 17:20:57 +02:00
committed by Harald Kuhr
parent 132105b97a
commit d0d0b1afa3
9 changed files with 82 additions and 51 deletions
@@ -284,20 +284,6 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
return false; return false;
} }
/*
// NOTE: Extra cautions is taken, to only remove the entry if it
// equals the entry in the map
Object key = ((Entry) o).getKey();
Entry entry = (Entry) entries.get(key);
// Same entry?
if (entry != null && entry.equals(o)) {
return AbstractWrappedMap.this.remove(key) != null;
}
return false;
*/
//noinspection unchecked //noinspection unchecked
return AbstractDecoratedMap.this.removeEntry((Entry) o) != null; return AbstractDecoratedMap.this.removeEntry((Entry) o) != null;
} }
@@ -322,7 +308,7 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
return containsKey(o); return containsKey(o);
} }
public boolean remove(Object o) { public boolean remove(Object o) {
return AbstractDecoratedMap.this.remove(o) != null; return AbstractDecoratedMap.this.removeEntry(getEntry((K) o)) != null;
} }
public void clear() { public void clear() {
AbstractDecoratedMap.this.clear(); AbstractDecoratedMap.this.clear();
@@ -137,43 +137,43 @@ public final class BeanMap extends AbstractMap<String, Object> implements Serial
} }
private class BeanIterator implements Iterator<Entry<String, Object>> { private class BeanIterator implements Iterator<Entry<String, Object>> {
private final Iterator<PropertyDescriptor> mIterator; private final Iterator<PropertyDescriptor> iterator;
public BeanIterator(final Iterator<PropertyDescriptor> pIterator) { public BeanIterator(final Iterator<PropertyDescriptor> pIterator) {
mIterator = pIterator; iterator = pIterator;
} }
public boolean hasNext() { public boolean hasNext() {
return mIterator.hasNext(); return iterator.hasNext();
} }
public BeanEntry next() { public BeanEntry next() {
return new BeanEntry(mIterator.next()); return new BeanEntry(iterator.next());
} }
public void remove() { public void remove() {
mIterator.remove(); iterator.remove();
} }
} }
private class BeanEntry implements Entry<String, Object> { private class BeanEntry implements Entry<String, Object> {
private final PropertyDescriptor mDescriptor; private final PropertyDescriptor descriptor;
public BeanEntry(final PropertyDescriptor pDescriptor) { public BeanEntry(final PropertyDescriptor pDescriptor) {
this.mDescriptor = pDescriptor; this.descriptor = pDescriptor;
} }
public String getKey() { public String getKey() {
return mDescriptor.getName(); return descriptor.getName();
} }
public Object getValue() { public Object getValue() {
return unwrap(new Wrapped() { return unwrap(new Wrapped() {
public Object run() throws IllegalAccessException, InvocationTargetException { public Object run() throws IllegalAccessException, InvocationTargetException {
final Method method = mDescriptor.getReadMethod(); final Method method = descriptor.getReadMethod();
// A write-only bean. // A write-only bean.
if (method == null) { if (method == null) {
throw new UnsupportedOperationException("No getter: " + mDescriptor.getName()); throw new UnsupportedOperationException("No getter: " + descriptor.getName());
} }
return method.invoke(bean); return method.invoke(bean);
@@ -184,10 +184,10 @@ public final class BeanMap extends AbstractMap<String, Object> implements Serial
public Object setValue(final Object pValue) { public Object setValue(final Object pValue) {
return unwrap(new Wrapped() { return unwrap(new Wrapped() {
public Object run() throws IllegalAccessException, InvocationTargetException { public Object run() throws IllegalAccessException, InvocationTargetException {
final Method method = mDescriptor.getWriteMethod(); final Method method = descriptor.getWriteMethod();
// A read-only bean. // A read-only bean.
if (method == null) { if (method == null) {
throw new UnsupportedOperationException("No write method for property: " + mDescriptor.getName()); throw new UnsupportedOperationException("No write method for property: " + descriptor.getName());
} }
final Object old = getValue(); final Object old = getValue();
@@ -327,5 +327,4 @@ public abstract class ObjectAbstractTest {
return new Cloneable() {}; return new Cloneable() {};
} }
} }
} }
@@ -30,6 +30,8 @@
package com.twelvemonkeys.util; package com.twelvemonkeys.util;
import org.junit.jupiter.api.Nested;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
@@ -172,4 +174,16 @@ public class BeanMapTest extends MapAbstractTest {
} }
static class NullBean implements Serializable { } static class NullBean implements Serializable { }
@Nested
public class TestBeanMapEntrySet extends TestMapEntrySet {
}
@Nested
public class TestBeanMapKeySet extends TestMapKeySet {
}
@Nested
public class TestBeanMapValues extends TestMapValues {
}
} }
@@ -436,24 +436,24 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
*/ */
public Object[] getFullNonNullElements() { public Object[] getFullNonNullElements() {
return new Object[] { return new Object[] {
new String(""), "",
new String("One"),
new Integer(2),
"Three",
new Integer(4),
"One", "One",
new Double(5), 2,
new Float(6), "Three",
4,
"One",
5.0,
6F,
"Seven", "Seven",
"Eight", "Eight",
new String("Nine"), "Nine",
new Integer(10), 10,
new Short((short)11), (short) 11,
new Long(12), 12L,
"Thirteen", "Thirteen",
"14", "14",
"15", "15",
new Byte((byte)16) (byte) 16
}; };
} }
@@ -1149,7 +1149,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
public void testUnsupportedRemove() { public void testUnsupportedRemove() {
if (isRemoveSupported()) return; if (isRemoveSupported()) return;
resetEmpty(); resetFull();
try { try {
collection.clear(); collection.clear();
fail("clear should raise UnsupportedOperationException"); fail("clear should raise UnsupportedOperationException");
@@ -1159,7 +1159,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
verifyAll(); verifyAll();
try { try {
collection.remove(null); collection.remove(getFullElements()[0]);
fail("remove should raise UnsupportedOperationException"); fail("remove should raise UnsupportedOperationException");
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
// expected // expected
@@ -1167,7 +1167,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
verifyAll(); verifyAll();
try { try {
collection.removeAll(null); collection.removeAll(Arrays.asList(getFullElements()));
fail("removeAll should raise UnsupportedOperationException"); fail("removeAll should raise UnsupportedOperationException");
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
// expected // expected
@@ -1175,7 +1175,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
verifyAll(); verifyAll();
try { try {
collection.retainAll(null); collection.retainAll(Collections.emptySet());
fail("removeAll should raise UnsupportedOperationException"); fail("removeAll should raise UnsupportedOperationException");
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
// expected // expected
@@ -1192,7 +1192,6 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
// expected // expected
} }
verifyAll(); verifyAll();
} }
@@ -212,5 +212,17 @@ public class LRUMapTest extends LinkedMapTest {
list.add(pEntry.getKey()); list.add(pEntry.getKey());
} }
} }
@Nested
public class TestLRUMapEntrySet extends TestMapEntrySet {
}
@Nested
public class TestLRUMapKeySet extends TestMapKeySet {
}
@Nested
public class TestLRUMapValues extends TestMapValues {
}
} }
@@ -201,4 +201,16 @@ public class LinkedMapTest extends MapAbstractTest {
public void tearDown() throws Exception { public void tearDown() throws Exception {
labRat = null; labRat = null;
} }
@Nested
public class TestLinkedMapEntrySet extends TestMapEntrySet {
}
@Nested
public class TestLinkedMapKeySet extends TestMapKeySet {
}
@Nested
public class TestLinkedMapValues extends TestMapValues {
}
} }
@@ -1255,8 +1255,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
} }
*/ */
@Nested protected abstract class TestMapEntrySet extends SetAbstractTest {
public class TestMapEntrySet extends SetAbstractTest {
// Have to implement manually; entrySet doesn't support addAll // Have to implement manually; entrySet doesn't support addAll
public Object[] getFullElements() { public Object[] getFullElements() {
@@ -1430,8 +1429,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
} }
*/ */
@Nested protected abstract class TestMapKeySet extends SetAbstractTest {
public class TestMapKeySet extends SetAbstractTest {
public Object[] getFullElements() { public Object[] getFullElements() {
return getSampleKeys(); return getSampleKeys();
} }
@@ -1497,8 +1495,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
} }
*/ */
@Nested protected abstract class TestMapValues extends CollectionAbstractTest {
public class TestMapValues extends CollectionAbstractTest {
public Object[] getFullElements() { public Object[] getFullElements() {
return getSampleValues(); return getSampleValues();
} }
@@ -668,5 +668,17 @@ public class TimeoutMapTest extends MapAbstractTest {
assertFalse(timeoutMap.containsKey("xyz")); assertFalse(timeoutMap.containsKey("xyz"));
assertNull(timeoutMap.get("xyz")); assertNull(timeoutMap.get("xyz"));
} }
@Nested
public class TestTimeoutMapEntrySet extends TestMapEntrySet {
}
@Nested
public class TestTimeoutMapKeySet extends TestMapKeySet {
}
@Nested
public class TestTimeoutMapValues extends TestMapValues {
}
} }