Convert control statement bodies to block.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1429895 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2013-01-07 16:55:07 +00:00
parent 49501d2f3c
commit 784f4752fc
16 changed files with 352 additions and 119 deletions

View File

@ -131,11 +131,17 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
switch (size) { switch (size) {
// drop through // drop through
case 3: case 3:
if (key3 == null) return value3; if (key3 == null) {
return value3;
}
case 2: case 2:
if (key2 == null) return value2; if (key2 == null) {
return value2;
}
case 1: case 1:
if (key1 == null) return value1; if (key1 == null) {
return value1;
}
} }
} else { } else {
if (size > 0) { if (size > 0) {
@ -143,11 +149,17 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
switch (size) { switch (size) {
// drop through // drop through
case 3: case 3:
if (hash3 == hashCode && key.equals(key3)) return value3; if (hash3 == hashCode && key.equals(key3)) {
return value3;
}
case 2: case 2:
if (hash2 == hashCode && key.equals(key2)) return value2; if (hash2 == hashCode && key.equals(key2)) {
return value2;
}
case 1: case 1:
if (hash1 == hashCode && key.equals(key1)) return value1; if (hash1 == hashCode && key.equals(key1)) {
return value1;
}
} }
} }
} }
@ -189,22 +201,34 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
if (key == null) { if (key == null) {
switch (size) { // drop through switch (size) { // drop through
case 3: case 3:
if (key3 == null) return true; if (key3 == null) {
return true;
}
case 2: case 2:
if (key2 == null) return true; if (key2 == null) {
return true;
}
case 1: case 1:
if (key1 == null) return true; if (key1 == null) {
return true;
}
} }
} else { } else {
if (size > 0) { if (size > 0) {
int hashCode = key.hashCode(); int hashCode = key.hashCode();
switch (size) { // drop through switch (size) { // drop through
case 3: case 3:
if (hash3 == hashCode && key.equals(key3)) return true; if (hash3 == hashCode && key.equals(key3)) {
return true;
}
case 2: case 2:
if (hash2 == hashCode && key.equals(key2)) return true; if (hash2 == hashCode && key.equals(key2)) {
return true;
}
case 1: case 1:
if (hash1 == hashCode && key.equals(key1)) return true; if (hash1 == hashCode && key.equals(key1)) {
return true;
}
} }
} }
} }
@ -224,20 +248,32 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
if (value == null) { // drop through if (value == null) { // drop through
switch (size) { switch (size) {
case 3: case 3:
if (value3 == null) return true; if (value3 == null) {
return true;
}
case 2: case 2:
if (value2 == null) return true; if (value2 == null) {
return true;
}
case 1: case 1:
if (value1 == null) return true; if (value1 == null) {
return true;
}
} }
} else { } else {
switch (size) { // drop through switch (size) { // drop through
case 3: case 3:
if (value.equals(value3)) return true; if (value.equals(value3)) {
return true;
}
case 2: case 2:
if (value.equals(value2)) return true; if (value.equals(value2)) {
return true;
}
case 1: case 1:
if (value.equals(value1)) return true; if (value.equals(value1)) {
return true;
}
} }
} }
return false; return false;

View File

@ -71,7 +71,9 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testLinkedListAddFirst() { public void testLinkedListAddFirst() {
if (!isAddSupported()) return; if (!isAddSupported()) {
return;
}
T o = (T) "hello"; T o = (T) "hello";
resetEmpty(); resetEmpty();
@ -90,7 +92,9 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testLinkedListAddLast() { public void testLinkedListAddLast() {
if (!isAddSupported()) return; if (!isAddSupported()) {
return;
}
T o = (T) "hello"; T o = (T) "hello";
resetEmpty(); resetEmpty();
@ -152,7 +156,9 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
* Tests {@link LinkedList#removeFirst()}. * Tests {@link LinkedList#removeFirst()}.
*/ */
public void testLinkedListRemoveFirst() { public void testLinkedListRemoveFirst() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
try { try {
@ -176,7 +182,9 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
* Tests {@link LinkedList#removeLast()}. * Tests {@link LinkedList#removeLast()}.
*/ */
public void testLinkedListRemoveLast() { public void testLinkedListRemoveLast() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
try { try {

View File

@ -324,8 +324,12 @@ class BulkTestSuiteMaker {
Class<? extends BulkTest> c = bulk.getClass(); Class<? extends BulkTest> c = bulk.getClass();
Method[] all = c.getMethods(); Method[] all = c.getMethods();
for (Method element : all) { for (Method element : all) {
if (isTest(element)) addTest(bulk, element); if (isTest(element)) {
if (isBulk(element)) addBulk(bulk, element); addTest(bulk, element);
}
if (isBulk(element)) {
addBulk(bulk, element);
}
} }
} }
@ -341,7 +345,9 @@ class BulkTestSuiteMaker {
BulkTest bulk2 = (BulkTest)bulk.clone(); BulkTest bulk2 = (BulkTest)bulk.clone();
bulk2.setName(m.getName()); bulk2.setName(m.getName());
bulk2.verboseName = prefix + "." + m.getName(); bulk2.verboseName = prefix + "." + m.getName();
if (ignored.contains(bulk2.verboseName)) return; if (ignored.contains(bulk2.verboseName)) {
return;
}
result.addTest(bulk2); result.addTest(bulk2);
} }
@ -356,12 +362,16 @@ class BulkTestSuiteMaker {
*/ */
void addBulk(BulkTest bulk, Method m) { void addBulk(BulkTest bulk, Method m) {
String verboseName = prefix + "." + m.getName(); String verboseName = prefix + "." + m.getName();
if (ignored.contains(verboseName)) return; if (ignored.contains(verboseName)) {
return;
}
BulkTest bulk2; BulkTest bulk2;
try { try {
bulk2 = (BulkTest)m.invoke(bulk, (Object[]) null); bulk2 = (BulkTest)m.invoke(bulk, (Object[]) null);
if (bulk2 == null) return; if (bulk2 == null) {
return;
}
} catch (InvocationTargetException ex) { } catch (InvocationTargetException ex) {
ex.getTargetException().printStackTrace(); ex.getTargetException().printStackTrace();
throw new Error(); // FIXME; throw new Error(); // FIXME;
@ -432,7 +442,9 @@ class BulkTestSuiteMaker {
private static <T extends BulkTest> BulkTest makeFirstTestCase(Class<T> c) { private static <T extends BulkTest> BulkTest makeFirstTestCase(Class<T> c) {
Method[] all = c.getMethods(); Method[] all = c.getMethods();
for (Method element : all) { for (Method element : all) {
if (isTest(element)) return makeTestCase(c, element); if (isTest(element)) {
return makeTestCase(c, element);
}
} }
throw new IllegalArgumentException(c.getName() + " must provide " throw new IllegalArgumentException(c.getName() + " must provide "
+ " at least one test method."); + " at least one test method.");
@ -442,12 +454,22 @@ class BulkTestSuiteMaker {
* Returns true if the given method is a simple test method. * Returns true if the given method is a simple test method.
*/ */
private static boolean isTest(Method m) { private static boolean isTest(Method m) {
if (!m.getName().startsWith("test")) return false; if (!m.getName().startsWith("test")) {
if (m.getReturnType() != Void.TYPE) return false; return false;
if (m.getParameterTypes().length != 0) return false; }
if (m.getReturnType() != Void.TYPE) {
return false;
}
if (m.getParameterTypes().length != 0) {
return false;
}
int mods = m.getModifiers(); int mods = m.getModifiers();
if (Modifier.isStatic(mods)) return false; if (Modifier.isStatic(mods)) {
if (Modifier.isAbstract(mods)) return false; return false;
}
if (Modifier.isAbstract(mods)) {
return false;
}
return true; return true;
} }
@ -455,12 +477,22 @@ class BulkTestSuiteMaker {
* Returns true if the given method is a bulk test method. * Returns true if the given method is a bulk test method.
*/ */
private static boolean isBulk(Method m) { private static boolean isBulk(Method m) {
if (!m.getName().startsWith("bulkTest")) return false; if (!m.getName().startsWith("bulkTest")) {
if (m.getReturnType() != BulkTest.class) return false; return false;
if (m.getParameterTypes().length != 0) return false; }
if (m.getReturnType() != BulkTest.class) {
return false;
}
if (m.getParameterTypes().length != 0) {
return false;
}
int mods = m.getModifiers(); int mods = m.getModifiers();
if (Modifier.isStatic(mods)) return false; if (Modifier.isStatic(mods)) {
if (Modifier.isAbstract(mods)) return false; return false;
}
if (Modifier.isAbstract(mods)) {
return false;
}
return true; return true;
} }

View File

@ -454,7 +454,9 @@ public abstract class AbstractBagTest<T> extends AbstractObjectTest {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testEmptyBagSerialization() throws IOException, ClassNotFoundException { public void testEmptyBagSerialization() throws IOException, ClassNotFoundException {
Bag<T> bag = makeObject(); Bag<T> bag = makeObject();
if (!(bag instanceof Serializable && isTestSerialization())) return; if (!(bag instanceof Serializable && isTestSerialization())) {
return;
}
byte[] objekt = writeExternalFormToBytes((Serializable) bag); byte[] objekt = writeExternalFormToBytes((Serializable) bag);
Bag<?> bag2 = (Bag<?>) readExternalFormFromBytes(objekt); Bag<?> bag2 = (Bag<?>) readExternalFormFromBytes(objekt);
@ -472,7 +474,9 @@ public abstract class AbstractBagTest<T> extends AbstractObjectTest {
bag.add((T) "B"); bag.add((T) "B");
bag.add((T) "C"); bag.add((T) "C");
int size = bag.size(); int size = bag.size();
if (!(bag instanceof Serializable && isTestSerialization())) return; if (!(bag instanceof Serializable && isTestSerialization())) {
return;
}
byte[] objekt = writeExternalFormToBytes((Serializable) bag); byte[] objekt = writeExternalFormToBytes((Serializable) bag);
Bag<?> bag2 = (Bag<?>) readExternalFormFromBytes(objekt); Bag<?> bag2 = (Bag<?>) readExternalFormFromBytes(objekt);

View File

@ -80,7 +80,9 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testBidiPut() { public void testBidiPut() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return; if (isPutAddSupported() == false || isPutChangeSupported() == false) {
return;
}
BidiMap<K, V> map = makeObject(); BidiMap<K, V> map = makeObject();
BidiMap<V, K> inverse = map.inverseBidiMap(); BidiMap<V, K> inverse = map.inverseBidiMap();
@ -179,7 +181,9 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiModifyEntrySet() { public void testBidiModifyEntrySet() {
if (isSetValueSupported() == false) return; if (isSetValueSupported() == false) {
return;
}
modifyEntrySet(makeFullMap()); modifyEntrySet(makeFullMap());
modifyEntrySet(makeFullMap().inverseBidiMap()); modifyEntrySet(makeFullMap().inverseBidiMap());
@ -282,7 +286,9 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveByKeySet() { public void testBidiRemoveByKeySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
removeByKeySet(makeFullMap(), getSampleKeys()[0], getSampleValues()[0]); removeByKeySet(makeFullMap(), getSampleKeys()[0], getSampleValues()[0]);
removeByKeySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]); removeByKeySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]);
@ -304,7 +310,9 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveByEntrySet() { public void testBidiRemoveByEntrySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
removeByEntrySet(makeFullMap(), getSampleKeys()[0], getSampleValues()[0]); removeByEntrySet(makeFullMap(), getSampleKeys()[0], getSampleValues()[0]);
removeByEntrySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]); removeByEntrySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]);

View File

@ -129,7 +129,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiClearByHeadMap() { public void testBidiClearByHeadMap() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -174,7 +176,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveByHeadMap() { public void testBidiRemoveByHeadMap() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -216,7 +220,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveByHeadMapEntrySet() { public void testBidiRemoveByHeadMapEntrySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -297,7 +303,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiClearByTailMap() { public void testBidiClearByTailMap() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -344,7 +352,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveByTailMap() { public void testBidiRemoveByTailMap() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -387,7 +397,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveByTailMapEntrySet() { public void testBidiRemoveByTailMapEntrySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -475,7 +487,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiClearBySubMap() { public void testBidiClearBySubMap() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -530,7 +544,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveBySubMap() { public void testBidiRemoveBySubMap() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();
@ -574,7 +590,9 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testBidiRemoveBySubMapEntrySet() { public void testBidiRemoveBySubMapEntrySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
// extra test as other tests get complex // extra test as other tests get complex
SortedBidiMap<K, V> sm = makeFullMap(); SortedBidiMap<K, V> sm = makeFullMap();

View File

@ -329,8 +329,9 @@ public class PriorityBufferTest<E> extends AbstractCollectionTest<E> {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
for (int offset = 1; count < h.size() + 1; offset *= 2) { for (int offset = 1; count < h.size() + 1; offset *= 2) {
for (int i = offset; i < offset * 2; i++) { for (int i = offset; i < offset * 2; i++) {
if (i < h.elements.length && h.elements[i] != null) if (i < h.elements.length && h.elements[i] != null) {
buffer.append(h.elements[i] + " "); buffer.append(h.elements[i] + " ");
}
count++; count++;
} }
buffer.append('\n'); buffer.append('\n');

View File

@ -497,7 +497,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* Tests {@link Collection#add(Object)}. * Tests {@link Collection#add(Object)}.
*/ */
public void testCollectionAdd() { public void testCollectionAdd() {
if (!isAddSupported()) return; if (!isAddSupported()) {
return;
}
E[] elements = getFullElements(); E[] elements = getFullElements();
for (E element : elements) { for (E element : elements) {
@ -515,7 +517,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
boolean r = getCollection().add(element); boolean r = getCollection().add(element);
getConfirmed().add(element); getConfirmed().add(element);
verify(); verify();
if (r) size++; if (r) {
size++;
}
assertEquals("Collection size should grow after add", size, getCollection().size()); assertEquals("Collection size should grow after add", size, getCollection().size());
assertTrue("Collection should contain added element", getCollection().contains(element)); assertTrue("Collection should contain added element", getCollection().contains(element));
} }
@ -525,7 +529,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* Tests {@link Collection#addAll(Collection)}. * Tests {@link Collection#addAll(Collection)}.
*/ */
public void testCollectionAddAll() { public void testCollectionAddAll() {
if (!isAddSupported()) return; if (!isAddSupported()) {
return;
}
resetEmpty(); resetEmpty();
E[] elements = getFullElements(); E[] elements = getFullElements();
@ -567,7 +573,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* raise <code>UnsupportedOperationException. * raise <code>UnsupportedOperationException.
*/ */
public void testUnsupportedAdd() { public void testUnsupportedAdd() {
if (isAddSupported()) return; if (isAddSupported()) {
return;
}
resetEmpty(); resetEmpty();
try { try {
@ -616,7 +624,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* Test {@link Collection#clear()}. * Test {@link Collection#clear()}.
*/ */
public void testCollectionClear() { public void testCollectionClear() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
getCollection().clear(); // just to make sure it doesn't raise anything getCollection().clear(); // just to make sure it doesn't raise anything
@ -776,7 +786,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testCollectionIteratorRemove() { public void testCollectionIteratorRemove() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
try { try {
@ -844,7 +856,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* Tests {@link Collection#remove(Object)}. * Tests {@link Collection#remove(Object)}.
*/ */
public void testCollectionRemove() { public void testCollectionRemove() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
E[] elements = getFullElements(); E[] elements = getFullElements();
@ -888,7 +902,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* Tests {@link Collection#removeAll(Collection)}. * Tests {@link Collection#removeAll(Collection)}.
*/ */
public void testCollectionRemoveAll() { public void testCollectionRemoveAll() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
assertTrue("Empty collection removeAll should return false for empty input", assertTrue("Empty collection removeAll should return false for empty input",
@ -935,7 +951,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* Tests {@link Collection#retainAll(Collection)}. * Tests {@link Collection#retainAll(Collection)}.
*/ */
public void testCollectionRetainAll() { public void testCollectionRetainAll() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
List<E> elements = Arrays.asList(getFullElements()); List<E> elements = Arrays.asList(getFullElements());
@ -1029,8 +1047,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
// find a match in the confirmed array // find a match in the confirmed array
for (int j = 0; j < array.length; j++) { for (int j = 0; j < array.length; j++) {
// skip already matched // skip already matched
if (matched[j]) if (matched[j]) {
continue; continue;
}
if (array[i] == confirmedArray[j] if (array[i] == confirmedArray[j]
|| (array[i] != null && array[i].equals(confirmedArray[j]))) { || (array[i] != null && array[i].equals(confirmedArray[j]))) {
matched[j] = true; matched[j] = true;
@ -1088,7 +1107,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
for (Object element : array) { for (Object element : array) {
classes.add((element == null) ? null : element.getClass()); classes.add((element == null) ? null : element.getClass());
} }
if (classes.size() > 1) return; if (classes.size() > 1) {
return;
}
Class<?> cl = classes.iterator().next(); Class<?> cl = classes.iterator().next();
if (Map.Entry.class.isAssignableFrom(cl)) { // check needed for protective cases like Predicated/Unmod map entrySet if (Map.Entry.class.isAssignableFrom(cl)) { // check needed for protective cases like Predicated/Unmod map entrySet
@ -1120,7 +1141,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* operations raise an UnsupportedOperationException. * operations raise an UnsupportedOperationException.
*/ */
public void testUnsupportedRemove() { public void testUnsupportedRemove() {
if (isRemoveSupported()) return; if (isRemoveSupported()) {
return;
}
resetEmpty(); resetEmpty();
try { try {
@ -1172,7 +1195,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* Tests that the collection's iterator is fail-fast. * Tests that the collection's iterator is fail-fast.
*/ */
public void testCollectionIteratorFailFast() { public void testCollectionIteratorFailFast() {
if (!isFailFastSupported()) return; if (!isFailFastSupported()) {
return;
}
if (isAddSupported()) { if (isAddSupported()) {
resetFull(); resetFull();
@ -1201,7 +1226,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
verify(); verify();
} }
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetFull(); resetFull();
try { try {

View File

@ -115,7 +115,9 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testRemoveNode() { public void testRemoveNode() {
resetEmpty(); resetEmpty();
if (isAddSupported() == false || isRemoveSupported() == false) return; if (isAddSupported() == false || isRemoveSupported() == false) {
return;
}
AbstractLinkedList<E> list = getCollection(); AbstractLinkedList<E> list = getCollection();
list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" }));

View File

@ -572,7 +572,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* full list. * full list.
*/ */
public void testListSetByIndexBoundsChecking2() { public void testListSetByIndexBoundsChecking2() {
if (!isSetSupported()) return; if (!isSetSupported()) {
return;
}
List<E> list = makeFullCollection(); List<E> list = makeFullCollection();
E element = getOtherElements()[0]; E element = getOtherElements()[0];
@ -613,7 +615,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Test {@link List#set(int,Object)}. * Test {@link List#set(int,Object)}.
*/ */
public void testListSetByIndex() { public void testListSetByIndex() {
if (!isSetSupported()) return; if (!isSetSupported()) {
return;
}
resetFull(); resetFull();
E[] elements = getFullElements(); E[] elements = getFullElements();
@ -633,7 +637,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* raises <Code>UnsupportedOperationException. * raises <Code>UnsupportedOperationException.
*/ */
public void testUnsupportedSet() { public void testUnsupportedSet() {
if (isSetSupported()) return; if (isSetSupported()) {
return;
}
resetFull(); resetFull();
try { try {
@ -652,7 +658,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* empty list. * empty list.
*/ */
public void testListRemoveByIndexBoundsChecking() { public void testListRemoveByIndexBoundsChecking() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
List<E> list = makeObject(); List<E> list = makeObject();
@ -697,7 +705,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* full list. * full list.
*/ */
public void testListRemoveByIndexBoundsChecking2() { public void testListRemoveByIndexBoundsChecking2() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
List<E> list = makeFullCollection(); List<E> list = makeFullCollection();
@ -737,7 +747,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests {@link List#remove(int)}. * Tests {@link List#remove(int)}.
*/ */
public void testListRemoveByIndex() { public void testListRemoveByIndex() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
int max = getFullElements().length; int max = getFullElements().length;
for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
@ -786,9 +798,13 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct. * Tests remove on list iterator is correct.
*/ */
public void testListListIteratorPreviousRemoveNext() { public void testListListIteratorPreviousRemoveNext() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
resetFull(); resetFull();
if (getCollection().size() < 4) return; if (getCollection().size() < 4) {
return;
}
ListIterator<E> it = getCollection().listIterator(); ListIterator<E> it = getCollection().listIterator();
E zero = it.next(); E zero = it.next();
E one = it.next(); E one = it.next();
@ -814,9 +830,13 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct. * Tests remove on list iterator is correct.
*/ */
public void testListListIteratorPreviousRemovePrevious() { public void testListListIteratorPreviousRemovePrevious() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
resetFull(); resetFull();
if (getCollection().size() < 4) return; if (getCollection().size() < 4) {
return;
}
ListIterator<E> it = getCollection().listIterator(); ListIterator<E> it = getCollection().listIterator();
E zero = it.next(); E zero = it.next();
E one = it.next(); E one = it.next();
@ -842,9 +862,13 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct. * Tests remove on list iterator is correct.
*/ */
public void testListListIteratorNextRemoveNext() { public void testListListIteratorNextRemoveNext() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
resetFull(); resetFull();
if (getCollection().size() < 4) return; if (getCollection().size() < 4) {
return;
}
ListIterator<E> it = getCollection().listIterator(); ListIterator<E> it = getCollection().listIterator();
E zero = it.next(); E zero = it.next();
E one = it.next(); E one = it.next();
@ -867,9 +891,13 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct. * Tests remove on list iterator is correct.
*/ */
public void testListListIteratorNextRemovePrevious() { public void testListListIteratorNextRemovePrevious() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
resetFull(); resetFull();
if (getCollection().size() < 4) return; if (getCollection().size() < 4) {
return;
}
ListIterator<E> it = getCollection().listIterator(); ListIterator<E> it = getCollection().listIterator();
E zero = it.next(); E zero = it.next();
E one = it.next(); E one = it.next();
@ -964,7 +992,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* iterator. * iterator.
*/ */
public void testListIteratorAdd() { public void testListIteratorAdd() {
if (!isAddSupported()) return; if (!isAddSupported()) {
return;
}
resetEmpty(); resetEmpty();
List<E> list1 = getCollection(); List<E> list1 = getCollection();
@ -997,7 +1027,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* iterator. * iterator.
*/ */
public void testListIteratorSet() { public void testListIteratorSet() {
if (!isSetSupported()) return; if (!isSetSupported()) {
return;
}
E[] elements = getFullElements(); E[] elements = getFullElements();
@ -1016,7 +1048,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testEmptyListSerialization() throws IOException, ClassNotFoundException { public void testEmptyListSerialization() throws IOException, ClassNotFoundException {
List<E> list = makeObject(); List<E> list = makeObject();
if (!(list instanceof Serializable && isTestSerialization())) return; if (!(list instanceof Serializable && isTestSerialization())) {
return;
}
byte[] objekt = writeExternalFormToBytes((Serializable) list); byte[] objekt = writeExternalFormToBytes((Serializable) list);
List<E> list2 = (List<E>) readExternalFormFromBytes(objekt); List<E> list2 = (List<E>) readExternalFormFromBytes(objekt);
@ -1029,7 +1063,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
public void testFullListSerialization() throws IOException, ClassNotFoundException { public void testFullListSerialization() throws IOException, ClassNotFoundException {
List<E> list = makeFullCollection(); List<E> list = makeFullCollection();
int size = getFullElements().length; int size = getFullElements().length;
if (!(list instanceof Serializable && isTestSerialization())) return; if (!(list instanceof Serializable && isTestSerialization())) {
return;
}
byte[] objekt = writeExternalFormToBytes((Serializable) list); byte[] objekt = writeExternalFormToBytes((Serializable) list);
List<E> list2 = (List<E>) readExternalFormFromBytes(objekt); List<E> list2 = (List<E>) readExternalFormFromBytes(objekt);
@ -1113,7 +1149,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* modified when the sublist is. * modified when the sublist is.
*/ */
public BulkTest bulkTestSubList() { public BulkTest bulkTestSubList() {
if (getFullElements().length - 6 < 10) return null; if (getFullElements().length - 6 < 10) {
return null;
}
return new BulkTestSubList<E>(this); return new BulkTestSubList<E>(this);
} }
@ -1196,8 +1234,12 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* if elements are added to the original list. * if elements are added to the original list.
*/ */
public void testListSubListFailFastOnAdd() { public void testListSubListFailFastOnAdd() {
if (!isFailFastSupported()) return; if (!isFailFastSupported()) {
if (!isAddSupported()) return; return;
}
if (!isAddSupported()) {
return;
}
resetFull(); resetFull();
int size = getCollection().size(); int size = getCollection().size();
@ -1226,8 +1268,12 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* if elements are removed from the original list. * if elements are removed from the original list.
*/ */
public void testListSubListFailFastOnRemove() { public void testListSubListFailFastOnRemove() {
if (!isFailFastSupported()) return; if (!isFailFastSupported()) {
if (!isRemoveSupported()) return; return;
}
if (!isRemoveSupported()) {
return;
}
resetFull(); resetFull();
int size = getCollection().size(); int size = getCollection().size();
@ -1280,7 +1326,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* @param m the method to invoke * @param m the method to invoke
*/ */
protected void failFastMethod(List<E> list, Method m) { protected void failFastMethod(List<E> list, Method m) {
if (m.getName().equals("equals")) return; if (m.getName().equals("equals")) {
return;
}
E element = getOtherElements()[0]; E element = getOtherElements()[0];
Collection<E> c = Collections.singleton(element); Collection<E> c = Collections.singleton(element);
@ -1288,10 +1336,15 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
Class<?>[] types = m.getParameterTypes(); Class<?>[] types = m.getParameterTypes();
Object[] params = new Object[types.length]; Object[] params = new Object[types.length];
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
if (types[i] == Integer.TYPE) params[i] = new Integer(0); if (types[i] == Integer.TYPE) {
else if (types[i] == Collection.class) params[i] = c; params[i] = new Integer(0);
else if (types[i] == Object.class) params[i] = element; } else if (types[i] == Collection.class) {
else if (types[i] == Object[].class) params[i] = new Object[0]; params[i] = c;
} else if (types[i] == Object.class) {
params[i] = element;
} else if (types[i] == Object[].class) {
params[i] = new Object[0];
}
} }
try { try {

View File

@ -55,7 +55,9 @@ public class NodeCachingLinkedListTest<E> extends AbstractLinkedListTest<E> {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testShrinkCache() { public void testShrinkCache() {
if (isRemoveSupported() == false || isAddSupported() == false) return; if (isRemoveSupported() == false || isAddSupported() == false) {
return;
}
resetEmpty(); resetEmpty();
NodeCachingLinkedList<E> list = getCollection(); NodeCachingLinkedList<E> list = getCollection();

View File

@ -59,8 +59,12 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testFailFastEntrySet() { public void testFailFastEntrySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
if (isFailFastExpected() == false) return; return;
}
if (isFailFastExpected() == false) {
return;
}
resetFull(); resetFull();
Iterator<Map.Entry<K, V>> it = getMap().entrySet().iterator(); Iterator<Map.Entry<K, V>> it = getMap().entrySet().iterator();
Map.Entry<K, V> val = it.next(); Map.Entry<K, V> val = it.next();
@ -81,8 +85,12 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
} }
public void testFailFastKeySet() { public void testFailFastKeySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
if (isFailFastExpected() == false) return; return;
}
if (isFailFastExpected() == false) {
return;
}
resetFull(); resetFull();
Iterator<K> it = getMap().keySet().iterator(); Iterator<K> it = getMap().keySet().iterator();
K val = it.next(); K val = it.next();
@ -103,8 +111,12 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
} }
public void testFailFastValues() { public void testFailFastValues() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
if (isFailFastExpected() == false) return; return;
}
if (isFailFastExpected() == false) {
return;
}
resetFull(); resetFull();
Iterator<V> it = getMap().values().iterator(); Iterator<V> it = getMap().values().iterator();
it.next(); it.next();

View File

@ -1028,7 +1028,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
* the underlying map for clear(). * the underlying map for clear().
*/ */
public void testValuesClearChangesMap() { public void testValuesClearChangesMap() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
// clear values, reflected in map // clear values, reflected in map
resetFull(); resetFull();
@ -1054,7 +1056,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
* the underlying map for clear(). * the underlying map for clear().
*/ */
public void testKeySetClearChangesMap() { public void testKeySetClearChangesMap() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
// clear values, reflected in map // clear values, reflected in map
resetFull(); resetFull();
@ -1080,7 +1084,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
* the underlying map for clear(). * the underlying map for clear().
*/ */
public void testEntrySetClearChangesMap() { public void testEntrySetClearChangesMap() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
// clear values, reflected in map // clear values, reflected in map
resetFull(); resetFull();
@ -1129,7 +1135,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
} }
public void testEntrySetRemove1() { public void testEntrySetRemove1() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetFull(); resetFull();
int size = getMap().size(); int size = getMap().size();
Set<Map.Entry<K, V>> entrySet = getMap().entrySet(); Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
@ -1142,7 +1150,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
} }
public void testEntrySetRemove2() { public void testEntrySetRemove2() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetFull(); resetFull();
int size = getMap().size(); int size = getMap().size();
Set<Map.Entry<K, V>> entrySet = getMap().entrySet(); Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
@ -1157,7 +1167,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testEntrySetRemove3() { public void testEntrySetRemove3() {
if (!isRemoveSupported()) return; if (!isRemoveSupported()) {
return;
}
resetFull(); resetFull();
int size = getMap().size(); int size = getMap().size();
Set<Map.Entry<K, V>> entrySet = getMap().entrySet(); Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
@ -1684,7 +1696,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
} }
public void testMapEntrySetRemoveNonMapEntry() { public void testMapEntrySetRemoveNonMapEntry() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) {
return;
}
resetFull(); resetFull();
assertEquals(false, getCollection().remove(null)); assertEquals(false, getCollection().remove(null));
assertEquals(false, getCollection().remove(new Object())); assertEquals(false, getCollection().remove(new Object()));

View File

@ -238,7 +238,9 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
return ((SortedMap<K, V>) main.makeFullMap()).headMap(toKey); return ((SortedMap<K, V>) main.makeFullMap()).headMap(toKey);
} }
public void testHeadMapOutOfRange() { public void testHeadMapOutOfRange() {
if (isPutAddSupported() == false) return; if (isPutAddSupported() == false) {
return;
}
resetEmpty(); resetEmpty();
try { try {
getMap().put(toKey, subSortedValues.get(0)); getMap().put(toKey, subSortedValues.get(0));
@ -291,7 +293,9 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
return ((SortedMap<K, V>) main.makeFullMap()).tailMap(fromKey); return ((SortedMap<K, V>) main.makeFullMap()).tailMap(fromKey);
} }
public void testTailMapOutOfRange() { public void testTailMapOutOfRange() {
if (isPutAddSupported() == false) return; if (isPutAddSupported() == false) {
return;
}
resetEmpty(); resetEmpty();
try { try {
getMap().put(invalidKey, subSortedValues.get(0)); getMap().put(invalidKey, subSortedValues.get(0));
@ -351,7 +355,9 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
return ((SortedMap<K, V>) main.makeFullMap()).subMap(fromKey, toKey); return ((SortedMap<K, V>) main.makeFullMap()).subMap(fromKey, toKey);
} }
public void testSubMapOutOfRange() { public void testSubMapOutOfRange() {
if (isPutAddSupported() == false) return; if (isPutAddSupported() == false) {
return;
}
resetEmpty(); resetEmpty();
try { try {
getMap().put(toKey, subSortedValues.get(0)); getMap().put(toKey, subSortedValues.get(0));

View File

@ -70,7 +70,9 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testLRU() { public void testLRU() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return; if (isPutAddSupported() == false || isPutChangeSupported() == false) {
return;
}
K[] keys = getSampleKeys(); K[] keys = getSampleKeys();
V[] values = getSampleValues(); V[] values = getSampleValues();
Iterator<K> kit; Iterator<K> kit;
@ -150,7 +152,9 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testAccessOrder() { public void testAccessOrder() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return; if (isPutAddSupported() == false || isPutChangeSupported() == false) {
return;
}
K[] keys = getSampleKeys(); K[] keys = getSampleKeys();
V[] values = getSampleValues(); V[] values = getSampleValues();
Iterator<K> kit = null; Iterator<K> kit = null;
@ -364,7 +368,9 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testInternalState_Buckets() { public void testInternalState_Buckets() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return; if (isPutAddSupported() == false || isPutChangeSupported() == false) {
return;
}
SingleHashCode one = new SingleHashCode("1"); SingleHashCode one = new SingleHashCode("1");
SingleHashCode two = new SingleHashCode("2"); SingleHashCode two = new SingleHashCode("2");
SingleHashCode three = new SingleHashCode("3"); SingleHashCode three = new SingleHashCode("3");
@ -452,7 +458,9 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testInternalState_getEntry_int() { public void testInternalState_getEntry_int() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return; if (isPutAddSupported() == false || isPutChangeSupported() == false) {
return;
}
SingleHashCode one = new SingleHashCode("1"); SingleHashCode one = new SingleHashCode("1");
SingleHashCode two = new SingleHashCode("2"); SingleHashCode two = new SingleHashCode("2");
SingleHashCode three = new SingleHashCode("3"); SingleHashCode three = new SingleHashCode("3");

View File

@ -82,7 +82,9 @@ public class LinkedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testInsertionOrder() { public void testInsertionOrder() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return; if (isPutAddSupported() == false || isPutChangeSupported() == false) {
return;
}
K[] keys = getSampleKeys(); K[] keys = getSampleKeys();
V[] values = getSampleValues(); V[] values = getSampleValues();
Iterator<K> keyIter; Iterator<K> keyIter;