mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-18 00:00:03 -04:00
Fixed nested tests
This commit is contained in:
@@ -284,20 +284,6 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
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
|
||||
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);
|
||||
}
|
||||
public boolean remove(Object o) {
|
||||
return AbstractDecoratedMap.this.remove(o) != null;
|
||||
return AbstractDecoratedMap.this.removeEntry(getEntry((K) o)) != null;
|
||||
}
|
||||
public void 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 final Iterator<PropertyDescriptor> mIterator;
|
||||
private final Iterator<PropertyDescriptor> iterator;
|
||||
|
||||
public BeanIterator(final Iterator<PropertyDescriptor> pIterator) {
|
||||
mIterator = pIterator;
|
||||
iterator = pIterator;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return mIterator.hasNext();
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
public BeanEntry next() {
|
||||
return new BeanEntry(mIterator.next());
|
||||
return new BeanEntry(iterator.next());
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
mIterator.remove();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private class BeanEntry implements Entry<String, Object> {
|
||||
private final PropertyDescriptor mDescriptor;
|
||||
private final PropertyDescriptor descriptor;
|
||||
|
||||
public BeanEntry(final PropertyDescriptor pDescriptor) {
|
||||
this.mDescriptor = pDescriptor;
|
||||
this.descriptor = pDescriptor;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return mDescriptor.getName();
|
||||
return descriptor.getName();
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return unwrap(new Wrapped() {
|
||||
public Object run() throws IllegalAccessException, InvocationTargetException {
|
||||
final Method method = mDescriptor.getReadMethod();
|
||||
final Method method = descriptor.getReadMethod();
|
||||
// A write-only bean.
|
||||
if (method == null) {
|
||||
throw new UnsupportedOperationException("No getter: " + mDescriptor.getName());
|
||||
throw new UnsupportedOperationException("No getter: " + descriptor.getName());
|
||||
}
|
||||
|
||||
return method.invoke(bean);
|
||||
@@ -184,10 +184,10 @@ public final class BeanMap extends AbstractMap<String, Object> implements Serial
|
||||
public Object setValue(final Object pValue) {
|
||||
return unwrap(new Wrapped() {
|
||||
public Object run() throws IllegalAccessException, InvocationTargetException {
|
||||
final Method method = mDescriptor.getWriteMethod();
|
||||
final Method method = descriptor.getWriteMethod();
|
||||
// A read-only bean.
|
||||
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();
|
||||
|
||||
@@ -327,5 +327,4 @@ public abstract class ObjectAbstractTest {
|
||||
return new Cloneable() {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
@@ -172,4 +174,16 @@ public class BeanMapTest extends MapAbstractTest {
|
||||
}
|
||||
|
||||
static class NullBean implements Serializable { }
|
||||
|
||||
@Nested
|
||||
public class TestBeanMapEntrySet extends TestMapEntrySet {
|
||||
}
|
||||
|
||||
@Nested
|
||||
public class TestBeanMapKeySet extends TestMapKeySet {
|
||||
}
|
||||
|
||||
@Nested
|
||||
public class TestBeanMapValues extends TestMapValues {
|
||||
}
|
||||
}
|
||||
|
||||
+16
-17
@@ -436,24 +436,24 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
*/
|
||||
public Object[] getFullNonNullElements() {
|
||||
return new Object[] {
|
||||
new String(""),
|
||||
new String("One"),
|
||||
new Integer(2),
|
||||
"Three",
|
||||
new Integer(4),
|
||||
"",
|
||||
"One",
|
||||
new Double(5),
|
||||
new Float(6),
|
||||
2,
|
||||
"Three",
|
||||
4,
|
||||
"One",
|
||||
5.0,
|
||||
6F,
|
||||
"Seven",
|
||||
"Eight",
|
||||
new String("Nine"),
|
||||
new Integer(10),
|
||||
new Short((short)11),
|
||||
new Long(12),
|
||||
"Nine",
|
||||
10,
|
||||
(short) 11,
|
||||
12L,
|
||||
"Thirteen",
|
||||
"14",
|
||||
"15",
|
||||
new Byte((byte)16)
|
||||
(byte) 16
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1149,7 +1149,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
public void testUnsupportedRemove() {
|
||||
if (isRemoveSupported()) return;
|
||||
|
||||
resetEmpty();
|
||||
resetFull();
|
||||
try {
|
||||
collection.clear();
|
||||
fail("clear should raise UnsupportedOperationException");
|
||||
@@ -1159,7 +1159,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
verifyAll();
|
||||
|
||||
try {
|
||||
collection.remove(null);
|
||||
collection.remove(getFullElements()[0]);
|
||||
fail("remove should raise UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected
|
||||
@@ -1167,7 +1167,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
verifyAll();
|
||||
|
||||
try {
|
||||
collection.removeAll(null);
|
||||
collection.removeAll(Arrays.asList(getFullElements()));
|
||||
fail("removeAll should raise UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected
|
||||
@@ -1175,7 +1175,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
verifyAll();
|
||||
|
||||
try {
|
||||
collection.retainAll(null);
|
||||
collection.retainAll(Collections.emptySet());
|
||||
fail("removeAll should raise UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected
|
||||
@@ -1192,7 +1192,6 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
// expected
|
||||
}
|
||||
verifyAll();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -212,5 +212,17 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
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 {
|
||||
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
|
||||
public class TestMapEntrySet extends SetAbstractTest {
|
||||
protected abstract class TestMapEntrySet extends SetAbstractTest {
|
||||
|
||||
// Have to implement manually; entrySet doesn't support addAll
|
||||
public Object[] getFullElements() {
|
||||
@@ -1430,8 +1429,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
*/
|
||||
|
||||
@Nested
|
||||
public class TestMapKeySet extends SetAbstractTest {
|
||||
protected abstract class TestMapKeySet extends SetAbstractTest {
|
||||
public Object[] getFullElements() {
|
||||
return getSampleKeys();
|
||||
}
|
||||
@@ -1497,8 +1495,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
*/
|
||||
|
||||
@Nested
|
||||
public class TestMapValues extends CollectionAbstractTest {
|
||||
protected abstract class TestMapValues extends CollectionAbstractTest {
|
||||
public Object[] getFullElements() {
|
||||
return getSampleValues();
|
||||
}
|
||||
|
||||
@@ -668,5 +668,17 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
assertFalse(timeoutMap.containsKey("xyz"));
|
||||
assertNull(timeoutMap.get("xyz"));
|
||||
}
|
||||
|
||||
@Nested
|
||||
public class TestTimeoutMapEntrySet extends TestMapEntrySet {
|
||||
}
|
||||
|
||||
@Nested
|
||||
public class TestTimeoutMapKeySet extends TestMapKeySet {
|
||||
}
|
||||
|
||||
@Nested
|
||||
public class TestTimeoutMapValues extends TestMapValues {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user