Code simplification

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1540860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Bourg 2013-11-11 21:58:27 +00:00
parent 90559c49ba
commit 0f5b35aa8d
37 changed files with 184 additions and 200 deletions

View File

@ -426,7 +426,7 @@ class BulkTestSuiteMaker {
private static <T extends BulkTest> BulkTest makeTestCase(final Class<T> c, final Method m) {
final Constructor<T> con = getTestCaseConstructor(c);
try {
return con.newInstance(new Object[] { m.getName() });
return con.newInstance(m.getName());
} catch (final InvocationTargetException e) {
e.printStackTrace();
throw new RuntimeException(); // FIXME;

View File

@ -673,7 +673,7 @@ public class CollectionUtilsTest extends MockTestCase {
lastElement = CollectionUtils.forAllButLastDo(col, testClosure);
assertNull(lastElement);
Collection<String> strings = Arrays.asList(new String[]{"a", "b", "c"});
Collection<String> strings = Arrays.asList("a", "b", "c");
final StringBuffer result = new StringBuffer();
result.append(CollectionUtils.forAllButLastDo(strings, new Closure<String>() {
public void execute(String input) {
@ -682,7 +682,7 @@ public class CollectionUtilsTest extends MockTestCase {
}));
assertEquals("a;b;c", result.toString());
Collection<String> oneString = Arrays.asList(new String[]{"a"});
Collection<String> oneString = Arrays.asList("a");
final StringBuffer resultOne = new StringBuffer();
resultOne.append(CollectionUtils.forAllButLastDo(oneString, new Closure<String>() {
public void execute(String input) {
@ -690,8 +690,8 @@ public class CollectionUtilsTest extends MockTestCase {
}
}));
assertEquals("a", resultOne.toString());
assertNull(CollectionUtils.forAllButLastDo(strings, (Closure<String>) null));
assertNull(CollectionUtils.forAllButLastDo((Collection<String>) null, (Closure<String>) null));
assertNull(CollectionUtils.forAllButLastDo(strings, null));
assertNull(CollectionUtils.forAllButLastDo((Collection<String>) null, null));
}
@Test
@ -705,7 +705,7 @@ public class CollectionUtilsTest extends MockTestCase {
assertTrue(collectionA.isEmpty() && !collectionB.isEmpty());
assertNull(CollectionUtils.forAllButLastDo(col.iterator(), (Closure<List<? extends Number>>) null));
assertNull(CollectionUtils.forAllButLastDo((Iterator<String>) null, (Closure<String>) null));
assertNull(CollectionUtils.forAllButLastDo((Iterator<String>) null, null));
}
@Test

View File

@ -179,7 +179,7 @@ public class ListUtilsTest extends BulkTest {
}
public void testEquals() {
final Collection<String> data = Arrays.asList( new String[] { "a", "b", "c" });
final Collection<String> data = Arrays.asList("a", "b", "c");
final List<String> a = new ArrayList<String>( data );
final List<String> b = new ArrayList<String>( data );
@ -194,7 +194,7 @@ public class ListUtilsTest extends BulkTest {
}
public void testHashCode() {
final Collection<String> data = Arrays.asList( new String[] { "a", "b", "c" });
final Collection<String> data = Arrays.asList("a", "b", "c");
final List<String> a = new ArrayList<String>(data);
final List<String> b = new ArrayList<String>(data);

View File

@ -73,7 +73,7 @@ public class SetUtilsTest extends BulkTest {
}
public void testEquals() {
final Collection<String> data = Arrays.asList( new String[] { "a", "b", "c" });
final Collection<String> data = Arrays.asList("a", "b", "c");
final Set<String> a = new HashSet<String>(data);
final Set<String> b = new HashSet<String>(data);
@ -88,7 +88,7 @@ public class SetUtilsTest extends BulkTest {
}
public void testHashCode() {
final Collection<String> data = Arrays.asList( new String[] { "a", "b", "c" });
final Collection<String> data = Arrays.asList("a", "b", "c");
final Set<String> a = new HashSet<String>(data);
final Set<String> b = new HashSet<String>(data);

View File

@ -357,7 +357,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
final String element = (String) i.next();
// ignore the first A, remove the second via Iterator.remove()
if (element.equals("A")) {
if (foundA == false) {
if (!foundA) {
foundA = true;
} else {
i.remove();

View File

@ -80,7 +80,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//-----------------------------------------------------------------------
@SuppressWarnings("unchecked")
public void testBidiPut() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) {
if (!isPutAddSupported() || !isPutChangeSupported()) {
return;
}
@ -152,7 +152,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
getSampleKeys()[0]);
}
private final void doTestGetKey(final BidiMap<?, ?> map, final Object key, final Object value) {
private void doTestGetKey(final BidiMap<?, ?> map, final Object key, final Object value) {
assertEquals("Value not found for key.", value, map.get(key));
assertEquals("Key not found for value.", key, map.getKey(value));
}
@ -181,7 +181,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//-----------------------------------------------------------------------
public void testBidiModifyEntrySet() {
if (isSetValueSupported() == false) {
if (!isSetValueSupported()) {
return;
}
@ -190,7 +190,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
}
@SuppressWarnings("unchecked")
private final <T> void modifyEntrySet(final BidiMap<?, T> map) {
private <T> void modifyEntrySet(final BidiMap<?, T> map) {
// Gets first entry
final Map.Entry<?, T> entry = map.entrySet().iterator().next();
@ -214,7 +214,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//-----------------------------------------------------------------------
public void testBidiClear() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
try {
makeFullMap().clear();
fail();
@ -237,7 +237,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//-----------------------------------------------------------------------
public void testBidiRemove() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
try {
makeFullMap().remove(getSampleKeys()[0]);
fail();
@ -258,13 +258,13 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
assertEquals(null, makeFullMap().removeValue("NotPresent"));
}
private final void remove(final BidiMap<?, ?> map, final Object key) {
private void remove(final BidiMap<?, ?> map, final Object key) {
final Object value = map.remove(key);
assertTrue("Key was not removed.", !map.containsKey(key));
assertNull("Value was not removed.", map.getKey(value));
}
private final void removeValue(final BidiMap<?, ?> map, final Object value) {
private void removeValue(final BidiMap<?, ?> map, final Object value) {
final Object key = map.removeValue(value);
assertTrue("Key was not removed.", !map.containsKey(key));
assertNull("Value was not removed.", map.getKey(value));
@ -286,7 +286,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//-----------------------------------------------------------------------
public void testBidiRemoveByKeySet() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -294,7 +294,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
removeByKeySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]);
}
private final void removeByKeySet(final BidiMap<?, ?> map, final Object key, final Object value) {
private void removeByKeySet(final BidiMap<?, ?> map, final Object key, final Object value) {
map.keySet().remove(key);
assertTrue("Key was not removed.", !map.containsKey(key));
@ -310,7 +310,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
//-----------------------------------------------------------------------
public void testBidiRemoveByEntrySet() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -318,7 +318,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
removeByEntrySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]);
}
private final void removeByEntrySet(final BidiMap<?, ?> map, final Object key, final Object value) {
private void removeByEntrySet(final BidiMap<?, ?> map, final Object key, final Object value) {
final Map<Object, Object> temp = new HashMap<Object, Object>();
temp.put(key, value);
map.entrySet().remove(temp.entrySet().iterator().next());
@ -371,7 +371,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
final Map.Entry<K, V> entryConfirmed2 = getEntry(itConfirmed, key2);
TestBidiMapEntrySet.this.verify();
if (isSetValueSupported() == false) {
if (!isSetValueSupported()) {
try {
entry1.setValue(newValue1);
} catch (final UnsupportedOperationException ex) {
@ -545,7 +545,7 @@ public abstract class AbstractBidiMapTest<K, V> extends AbstractIterableMapTest<
assertEquals(true, it.hasNext());
final K key1 = it.next();
if (isSetValueSupported() == false) {
if (!isSetValueSupported()) {
try {
it.setValue(newValue1);
fail();

View File

@ -80,7 +80,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
resetEmpty();
OrderedBidiMap<K, V> bidi = (OrderedBidiMap<K, V>) map;
assertEquals(null, bidi.nextKey(getOtherKeys()[0]));
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
try {
assertEquals(null, bidi.nextKey(null)); // this is allowed too
} catch (final NullPointerException ex) {}
@ -99,7 +99,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
}
assertEquals(null, bidi.nextKey(confirmedLast));
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
try {
bidi.nextKey(null);
fail();
@ -113,7 +113,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
resetEmpty();
OrderedBidiMap<K, V> bidi = getMap();
assertEquals(null, bidi.previousKey(getOtherKeys()[0]));
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
try {
assertEquals(null, bidi.previousKey(null)); // this is allowed too
} catch (final NullPointerException ex) {}
@ -134,7 +134,7 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
}
assertEquals(null, bidi.previousKey(confirmedLast));
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
try {
bidi.previousKey(null);
fail();

View File

@ -129,7 +129,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiClearByHeadMap() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -176,7 +176,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiRemoveByHeadMap() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -220,7 +220,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiRemoveByHeadMapEntrySet() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -303,7 +303,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiClearByTailMap() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -352,7 +352,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiRemoveByTailMap() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -397,7 +397,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiRemoveByTailMapEntrySet() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -487,7 +487,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiClearBySubMap() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -544,7 +544,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiRemoveBySubMap() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
@ -590,7 +590,7 @@ public abstract class AbstractSortedBidiMapTest<K extends Comparable<K>, V exten
//-----------------------------------------------------------------------
public void testBidiRemoveBySubMapEntrySet() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}

View File

@ -672,9 +672,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
resetFull();
elements = getOtherElements();
for (int i = 0; i < elements.length; i++) {
for (Object element : elements) {
assertTrue("Full collection shouldn't contain element",
!getCollection().contains(elements[i]));
!getCollection().contains(element));
}
}
@ -862,16 +862,16 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
resetEmpty();
final E[] elements = getFullElements();
for (int i = 0; i < elements.length; i++) {
assertTrue("Shouldn't remove nonexistent element", !getCollection().remove(elements[i]));
for (E element : elements) {
assertTrue("Shouldn't remove nonexistent element", !getCollection().remove(element));
verify();
}
final E[] other = getOtherElements();
resetFull();
for (int i = 0; i < other.length; i++) {
assertTrue("Shouldn't remove nonexistent other element", !getCollection().remove(other[i]));
for (E element : other) {
assertTrue("Shouldn't remove nonexistent other element", !getCollection().remove(element));
verify();
}
@ -940,10 +940,8 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
verify();
assertTrue("Collection should shrink after removeAll", getCollection().size() < size);
final Iterator<E> iter = all.iterator();
while (iter.hasNext()) {
assertTrue("Collection shouldn't contain removed element",
!getCollection().contains(iter.next()));
for (E element : all) {
assertTrue("Collection shouldn't contain removed element", !getCollection().contains(element));
}
}
@ -994,10 +992,8 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
getConfirmed().retainAll(elements.subList(min, max));
verify();
final Iterator<E> iter = getCollection().iterator();
while (iter.hasNext()) {
assertTrue("Collection only contains retained element",
elements.subList(min, max).contains(iter.next()));
for (E element : getCollection()) {
assertTrue("Collection only contains retained element", elements.subList(min, max).contains(element));
}
}

View File

@ -19,6 +19,7 @@ package org.apache.commons.collections4.collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.commons.collections4.Transformer;
@ -86,32 +87,30 @@ public class TransformedCollectionTest extends AbstractCollectionTest<Object> {
public void testTransformedCollection() {
final Collection<Object> coll = TransformedCollection.transformingCollection(new ArrayList<Object>(), STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, coll.size());
final Object[] els = getFullElements();
for (int i = 0; i < els.length; i++) {
coll.add(els[i]);
final Object[] elements = getFullElements();
for (int i = 0; i < elements.length; i++) {
coll.add(elements[i]);
assertEquals(i + 1, coll.size());
assertEquals(true, coll.contains(Integer.valueOf((String) els[i])));
assertEquals(false, coll.contains(els[i]));
assertEquals(true, coll.contains(Integer.valueOf((String) elements[i])));
assertEquals(false, coll.contains(elements[i]));
}
assertEquals(true, coll.remove(Integer.valueOf((String) els[0])));
assertEquals(true, coll.remove(Integer.valueOf((String) elements[0])));
}
public void testTransformedCollection_decorateTransform() {
final Collection<Object> originalCollection = new ArrayList<Object>();
final Object[] els = getFullElements();
for (final Object el : els) {
originalCollection.add(el);
}
final Object[] elements = getFullElements();
Collections.addAll(originalCollection, elements);
final Collection<Object> collection = TransformedCollection.transformedCollection(originalCollection, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, collection.size());
for (final Object el : els) {
assertEquals(true, collection.contains(Integer.valueOf((String) el)));
assertEquals(false, collection.contains(el));
assertEquals(elements.length, collection.size());
for (final Object element : elements) {
assertEquals(true, collection.contains(Integer.valueOf((String) element)));
assertEquals(false, collection.contains(element));
}
assertEquals(false, collection.remove(els[0]));
assertEquals(true, collection.remove(Integer.valueOf((String) els[0])));
assertEquals(false, collection.remove(elements[0]));
assertEquals(true, collection.remove(Integer.valueOf((String) elements[0])));
}
@Override

View File

@ -216,7 +216,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
boolean isInNewOrder = false;
final Random rand = new Random();
while (keys.length > 1 && isInNewOrder == false) {
while (keys.length > 1 && !isInNewOrder) {
// shuffle:
for (int i = keys.length-1; i > 0; i--) {
final String swap = keys[i];

View File

@ -101,7 +101,7 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
* Test the empty iterator.
*/
public void testEmptyIterator() {
if (supportsEmptyIterator() == false) {
if (!supportsEmptyIterator()) {
return;
}
@ -125,7 +125,7 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
* Test normal iteration behaviour.
*/
public void testFullIterator() {
if (supportsFullIterator() == false) {
if (!supportsFullIterator()) {
return;
}
@ -163,7 +163,7 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
public void testRemove() {
final Iterator<E> it = makeObject();
if (supportsRemove() == false) {
if (!supportsRemove()) {
// check for UnsupportedOperationException if not supported
try {
it.remove();

View File

@ -92,7 +92,7 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
* Test that the empty list iterator contract is correct.
*/
public void testEmptyListIteratorIsIndeedEmpty() {
if (supportsEmptyIterator() == false) {
if (!supportsEmptyIterator()) {
return;
}
@ -163,7 +163,7 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
ListIterator<E> it = makeObject();
final E addValue = addSetValue();
if (supportsAdd() == false) {
if (!supportsAdd()) {
// check for UnsupportedOperationException if not supported
try {
it.add(addValue);
@ -198,7 +198,7 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
public void testSet() {
final ListIterator<E> it = makeObject();
if (supportsSet() == false) {
if (!supportsSet()) {
// check for UnsupportedOperationException if not supported
try {
it.set(addSetValue());

View File

@ -112,7 +112,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
* Test that the empty list iterator contract is correct.
*/
public void testEmptyMapIterator() {
if (supportsEmptyIterator() == false) {
if (!supportsEmptyIterator()) {
return;
}
@ -137,7 +137,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
fail();
} catch (final IllegalStateException ex) {}
if (supportsSetValue() == false) {
if (!supportsSetValue()) {
// setValue() should throw an UnsupportedOperationException/IllegalStateException
try {
it.setValue(addSetValues()[0]);
@ -158,7 +158,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
* Test that the full list iterator contract is correct.
*/
public void testFullMapIterator() {
if (supportsFullIterator() == false) {
if (!supportsFullIterator()) {
return;
}
@ -177,7 +177,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
// getValue
final V value = it.getValue();
if (isGetStructuralModify() == false) {
if (!isGetStructuralModify()) {
assertSame("Value must be mapped to key", map.get(key), value);
}
assertTrue("Value must be in map", map.containsValue(value));
@ -188,7 +188,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
//-----------------------------------------------------------------------
public void testMapIteratorSet() {
if (supportsFullIterator() == false) {
if (!supportsFullIterator()) {
return;
}
@ -201,7 +201,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
final K key = it.next();
final V value = it.getValue();
if (supportsSetValue() == false) {
if (!supportsSetValue()) {
try {
it.setValue(newValue);
fail();
@ -242,7 +242,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
assertEquals(true, it.hasNext());
final K key = it.next();
if (supportsRemove() == false) {
if (!supportsRemove()) {
try {
it.remove();
fail();
@ -265,7 +265,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
//-----------------------------------------------------------------------
public void testMapIteratorSetRemoveSet() {
if (supportsSetValue() == false || supportsRemove() == false) {
if (!supportsSetValue() || !supportsRemove()) {
return;
}
final V newValue = addSetValues()[0];
@ -289,7 +289,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
//-----------------------------------------------------------------------
public void testMapIteratorRemoveGetKey() {
if (supportsRemove() == false) {
if (!supportsRemove()) {
return;
}
final MapIterator<K, V> it = makeObject();
@ -311,7 +311,7 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest
//-----------------------------------------------------------------------
public void testMapIteratorRemoveGetValue() {
if (supportsRemove() == false) {
if (!supportsRemove()) {
return;
}
final MapIterator<K, V> it = makeObject();

View File

@ -61,7 +61,7 @@ public abstract class AbstractOrderedMapIteratorTest<K, V> extends AbstractMapIt
*/
@Override
public void testEmptyMapIterator() {
if (supportsEmptyIterator() == false) {
if (!supportsEmptyIterator()) {
return;
}
@ -81,7 +81,7 @@ public abstract class AbstractOrderedMapIteratorTest<K, V> extends AbstractMapIt
*/
@Override
public void testFullMapIterator() {
if (supportsFullIterator() == false) {
if (!supportsFullIterator()) {
return;
}
@ -102,7 +102,7 @@ public abstract class AbstractOrderedMapIteratorTest<K, V> extends AbstractMapIt
// getValue
final V value = it.getValue();
if (isGetStructuralModify() == false) {
if (!isGetStructuralModify()) {
assertSame("Value must be mapped to key", map.get(key), value);
}
assertTrue("Value must be in map", map.containsValue(value));
@ -120,7 +120,7 @@ public abstract class AbstractOrderedMapIteratorTest<K, V> extends AbstractMapIt
// getValue
final Object value = it.getValue();
if (isGetStructuralModify() == false) {
if (!isGetStructuralModify()) {
assertSame("Value must be mapped to key", map.get(key), value);
}
assertTrue("Value must be in map", map.containsValue(value));
@ -136,7 +136,7 @@ public abstract class AbstractOrderedMapIteratorTest<K, V> extends AbstractMapIt
* Test that the iterator order matches the keySet order.
*/
public void testMapIteratorOrder() {
if (supportsFullIterator() == false) {
if (!supportsFullIterator()) {
return;
}

View File

@ -48,7 +48,7 @@ public class LoopingIteratorTest extends TestCase {
public void testLooping0() throws Exception {
final List<Object> list = new ArrayList<Object>();
final LoopingIterator<Object> loop = new LoopingIterator<Object>(list);
assertTrue("hasNext should return false", loop.hasNext() == false);
assertTrue("hasNext should return false", !loop.hasNext());
try {
loop.next();
@ -62,7 +62,7 @@ public class LoopingIteratorTest extends TestCase {
* @throws Exception If something unexpected occurs.
*/
public void testLooping1() throws Exception {
final List<String> list = Arrays.asList(new String[] { "a" });
final List<String> list = Arrays.asList("a");
final LoopingIterator<String> loop = new LoopingIterator<String>(list);
assertTrue("1st hasNext should return true", loop.hasNext());
@ -81,7 +81,7 @@ public class LoopingIteratorTest extends TestCase {
* @throws Exception If something unexpected occurs.
*/
public void testLooping2() throws Exception {
final List<String> list = Arrays.asList(new String[] { "a", "b" });
final List<String> list = Arrays.asList("a", "b");
final LoopingIterator<String> loop = new LoopingIterator<String>(list);
assertTrue("1st hasNext should return true", loop.hasNext());
@ -100,7 +100,7 @@ public class LoopingIteratorTest extends TestCase {
* @throws Exception If something unexpected occurs.
*/
public void testLooping3() throws Exception {
final List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
final List<String> list = Arrays.asList("a", "b", "c");
final LoopingIterator<String> loop = new LoopingIterator<String>(list);
assertTrue("1st hasNext should return true", loop.hasNext());
@ -122,7 +122,7 @@ public class LoopingIteratorTest extends TestCase {
* @throws Exception If something unexpected occurs.
*/
public void testRemoving1() throws Exception {
final List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
final List<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c"));
final LoopingIterator<String> loop = new LoopingIterator<String>(list);
assertEquals("list should have 3 elements.", 3, list.size());
@ -141,7 +141,7 @@ public class LoopingIteratorTest extends TestCase {
loop.remove(); // removes c
assertEquals("list should have 0 elements.", 0, list.size());
assertTrue("4th hasNext should return false", loop.hasNext() == false);
assertFalse("4th hasNext should return false", loop.hasNext());
try {
loop.next();
fail("Expected NoSuchElementException to be thrown.");
@ -154,7 +154,7 @@ public class LoopingIteratorTest extends TestCase {
* @throws Exception If something unexpected occurs.
*/
public void testReset() throws Exception {
final List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
final List<String> list = Arrays.asList("a", "b", "c");
final LoopingIterator<String> loop = new LoopingIterator<String>(list);
assertEquals("a", loop.next());
@ -176,7 +176,7 @@ public class LoopingIteratorTest extends TestCase {
* @throws Exception If something unexpected occurs.
*/
public void testSize() throws Exception {
final List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
final List<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c"));
final LoopingIterator<String> loop = new LoopingIterator<String>(list);
assertEquals(3, loop.size());

View File

@ -68,7 +68,7 @@ public class LoopingListIteratorTest extends TestCase {
* one element.
*/
public void testLooping1() throws Exception {
final List<String> list = Arrays.asList(new String[] { "a" });
final List<String> list = Arrays.asList("a");
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a>
assertTrue(loop.hasNext());
@ -95,7 +95,7 @@ public class LoopingListIteratorTest extends TestCase {
* elements.
*/
public void testLooping2() throws Exception {
final List<String> list = Arrays.asList(new String[] { "a", "b" });
final List<String> list = Arrays.asList("a", "b");
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b
assertTrue(loop.hasNext());
@ -125,7 +125,7 @@ public class LoopingListIteratorTest extends TestCase {
* the begin/end boundary of the list.
*/
public void testJoggingNotOverBoundary() {
final List<String> list = Arrays.asList(new String[] { "a", "b" });
final List<String> list = Arrays.asList("a", "b");
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b
// Try jogging back and forth between the elements, but not
@ -145,7 +145,7 @@ public class LoopingListIteratorTest extends TestCase {
* begin/end boundary of the list.
*/
public void testJoggingOverBoundary() {
final List<String> list = Arrays.asList(new String[] { "a", "b" });
final List<String> list = Arrays.asList("a", "b");
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b
// Try jogging back and forth between the elements, but not
@ -163,7 +163,7 @@ public class LoopingListIteratorTest extends TestCase {
* Tests removing an element from a wrapped ArrayList.
*/
public void testRemovingElementsAndIteratingForward() {
final List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
final List<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c"));
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
assertTrue(loop.hasNext());
@ -193,7 +193,7 @@ public class LoopingListIteratorTest extends TestCase {
* Tests removing an element from a wrapped ArrayList.
*/
public void testRemovingElementsAndIteratingBackwards() {
final List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
final List<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c"));
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
assertTrue(loop.hasPrevious());
@ -223,7 +223,7 @@ public class LoopingListIteratorTest extends TestCase {
* Tests the reset method.
*/
public void testReset() {
final List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
final List<String> list = Arrays.asList("a", "b", "c");
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
assertEquals("a", loop.next()); // a <b> c
@ -250,7 +250,7 @@ public class LoopingListIteratorTest extends TestCase {
* Tests the add method.
*/
public void testAdd() {
List<String> list = new ArrayList<String>(Arrays.asList(new String[] { "b", "e", "f" }));
List<String> list = new ArrayList<String>(Arrays.asList("b", "e", "f"));
LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <b> e f
loop.add("a"); // <a> b e f
@ -275,7 +275,7 @@ public class LoopingListIteratorTest extends TestCase {
assertEquals("f", loop.next()); // <a> b c d e f
assertEquals("a", loop.next()); // a <b> c d e f
list = new ArrayList<String>(Arrays.asList(new String[] { "b", "e", "f" }));
list = new ArrayList<String>(Arrays.asList("b", "e", "f"));
loop = new LoopingListIterator<String>(list); // <b> e f
loop.add("a"); // a <b> e f
@ -304,7 +304,7 @@ public class LoopingListIteratorTest extends TestCase {
* Tests nextIndex and previousIndex.
*/
public void testNextAndPreviousIndex() {
final List<String> list = Arrays.asList(new String[] { "a", "b", "c" });
final List<String> list = Arrays.asList("a", "b", "c");
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <a> b c
assertEquals(0, loop.nextIndex());
@ -335,7 +335,7 @@ public class LoopingListIteratorTest extends TestCase {
* Tests using the set method to change elements.
*/
public void testSet() {
final List<String> list = Arrays.asList(new String[] { "q", "r", "z" });
final List<String> list = Arrays.asList("q", "r", "z");
final LoopingListIterator<String> loop = new LoopingListIterator<String>(list); // <q> r z
assertEquals("z", loop.previous()); // q r <z>

View File

@ -53,7 +53,7 @@ public class MultiKeyTest extends TestCase {
//-----------------------------------------------------------------------
public void testConstructors() throws Exception {
MultiKey<Integer> mk = null;
MultiKey<Integer> mk;
mk = new MultiKey<Integer>(ONE, TWO);
assertTrue(Arrays.equals(new Object[] { ONE, TWO }, mk.getKeys()));
@ -71,7 +71,7 @@ public class MultiKeyTest extends TestCase {
}
public void testConstructorsByArray() throws Exception {
MultiKey<Integer> mk = null;
MultiKey<Integer> mk;
Integer[] keys = new Integer[] { THREE, FOUR, ONE, TWO };
mk = new MultiKey<Integer>(keys);
assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys()));
@ -193,9 +193,9 @@ public class MultiKeyTest extends TestCase {
assertEquals(mk1, mk1);
assertEquals(mk1, mk2);
assertTrue(mk1.equals(mk3) == false);
assertTrue(mk1.equals("") == false);
assertTrue(mk1.equals(null) == false);
assertFalse(mk1.equals(mk3));
assertFalse(mk1.equals(""));
assertFalse(mk1.equals(null));
}
static class SystemHashCodeSimulatingKey implements Serializable {

View File

@ -34,7 +34,7 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
public void testRemoveFirst() {
resetEmpty();
final AbstractLinkedList<E> list = getCollection();
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
try {
list.removeFirst();
} catch (final UnsupportedOperationException ex) {}
@ -58,7 +58,7 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
public void testRemoveLast() {
resetEmpty();
final AbstractLinkedList<E> list = getCollection();
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
try {
list.removeLast();
} catch (final UnsupportedOperationException ex) {}
@ -79,7 +79,7 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
public void testAddNodeAfter() {
resetEmpty();
final AbstractLinkedList<E> list = getCollection();
if (isAddSupported() == false) {
if (!isAddSupported()) {
try {
list.addFirst(null);
} catch (final UnsupportedOperationException ex) {}
@ -111,7 +111,7 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
@SuppressWarnings("unchecked")
public void testRemoveNode() {
resetEmpty();
if (isAddSupported() == false || isRemoveSupported() == false) {
if (!isAddSupported() || !isRemoveSupported()) {
return;
}
final AbstractLinkedList<E> list = getCollection();

View File

@ -473,11 +473,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
final List<E> list1 = getCollection();
final List<E> list2 = getConfirmed();
final Iterator<E> iterator = list2.iterator();
while (iterator.hasNext()) {
final Object element = iterator.next();
for (E element : list2) {
assertEquals("indexOf should return correct result",
list1.indexOf(element), list2.indexOf(element));
list1.indexOf(element), list2.indexOf(element));
verify();
}
@ -793,7 +791,7 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct.
*/
public void testListListIteratorPreviousRemoveNext() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
resetFull();
@ -825,7 +823,7 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct.
*/
public void testListListIteratorPreviousRemovePrevious() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
resetFull();
@ -857,7 +855,7 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct.
*/
public void testListListIteratorNextRemoveNext() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
resetFull();
@ -886,7 +884,7 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
* Tests remove on list iterator is correct.
*/
public void testListListIteratorNextRemovePrevious() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
resetFull();

View File

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

View File

@ -148,7 +148,7 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
// add two new unique elements at index 0
final Integer firstNewElement = Integer.valueOf(2);
final Integer secondNewElement = Integer.valueOf(3);
Collection<Integer> collection = Arrays.asList(new Integer[] {firstNewElement, secondNewElement});
Collection<Integer> collection = Arrays.asList(firstNewElement, secondNewElement);
list.addAll(0, collection);
assertEquals("Unique elements should be added.", 3, list.size());
assertEquals("First new element should be at index 0", firstNewElement, list.get(0));
@ -157,7 +157,7 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
// add a duplicate element and a unique element at index 0
final Integer thirdNewElement = Integer.valueOf(4);
collection = Arrays.asList(new Integer[] {existingElement, thirdNewElement});
collection = Arrays.asList(existingElement, thirdNewElement);
list.addAll(0, collection);
assertEquals("Duplicate element should not be added, unique element should be added.",
4, list.size());

View File

@ -57,10 +57,10 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
//-----------------------------------------------------------------------
public void testFailFastEntrySet() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
if (isFailFastExpected() == false) {
if (!isFailFastExpected()) {
return;
}
resetFull();
@ -83,10 +83,10 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
}
public void testFailFastKeySet() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
if (isFailFastExpected() == false) {
if (!isFailFastExpected()) {
return;
}
resetFull();
@ -109,10 +109,10 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
}
public void testFailFastValues() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
if (isFailFastExpected() == false) {
if (!isFailFastExpected()) {
return;
}
resetFull();

View File

@ -621,14 +621,14 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
final Object[] keys = getSampleKeys();
resetEmpty();
for(int i = 0; i < keys.length; i++) {
for (Object key : keys) {
assertTrue("Map must not contain key when map is empty",
!getMap().containsKey(keys[i]));
!getMap().containsKey(key));
}
verify();
resetFull();
for (final Object key : keys) {
for (Object key : keys) {
assertTrue("Map must contain key for a mapping in the map. " +
"Missing: " + key, getMap().containsKey(key));
}
@ -1614,7 +1614,7 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
final Map.Entry<K, V> entry = it.next();
assertEquals(true, AbstractMapTest.this.getMap().containsKey(entry.getKey()));
assertEquals(true, AbstractMapTest.this.getMap().containsValue(entry.getValue()));
if (isGetStructuralModify() == false) {
if (!isGetStructuralModify()) {
assertEquals(AbstractMapTest.this.getMap().get(entry.getKey()), entry.getValue());
}
count++;
@ -1641,7 +1641,7 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
final Map.Entry<K, V> entryConfirmed2 = getEntry(itConfirmed, key2);
verify();
if (isSetValueSupported() == false) {
if (!isSetValueSupported()) {
try {
entry1.setValue(newValue1);
} catch (final UnsupportedOperationException ex) {
@ -1693,7 +1693,7 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
}
public void testMapEntrySetRemoveNonMapEntry() {
if (isRemoveSupported() == false) {
if (!isRemoveSupported()) {
return;
}
resetFull();

View File

@ -140,7 +140,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
}
assertEquals(null, ordered.nextKey(confirmedLast));
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
try {
ordered.nextKey(null);
fail();
@ -154,7 +154,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
resetEmpty();
OrderedMap<K, V> ordered = getMap();
assertEquals(null, ordered.previousKey(getOtherKeys()[0]));
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
try {
assertEquals(null, ordered.previousKey(null)); // this is allowed too
} catch (final NullPointerException ex) {}
@ -175,13 +175,13 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
}
assertEquals(null, ordered.previousKey(confirmedLast));
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
try {
ordered.previousKey(null);
fail();
} catch (final NullPointerException ex) {}
} else {
if (isAllowNullKey() == false) {
if (!isAllowNullKey()) {
assertEquals(null, ordered.previousKey(null));
}
}

View File

@ -18,7 +18,6 @@ package org.apache.commons.collections4.map;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -92,8 +91,8 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
public void testLastKey() {
final SortedMap<K, V> sm = makeFullMap();
K obj = null;
for (final Iterator<K> it = sm.keySet().iterator(); it.hasNext();) {
obj = it.next();
for (K k : sm.keySet()) {
obj = k;
}
assertSame(obj, sm.lastKey());
}
@ -236,7 +235,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
return ((SortedMap<K, V>) main.makeFullMap()).headMap(toKey);
}
public void testHeadMapOutOfRange() {
if (isPutAddSupported() == false) {
if (!isPutAddSupported()) {
return;
}
resetEmpty();
@ -291,7 +290,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
return ((SortedMap<K, V>) main.makeFullMap()).tailMap(fromKey);
}
public void testTailMapOutOfRange() {
if (isPutAddSupported() == false) {
if (!isPutAddSupported()) {
return;
}
resetEmpty();
@ -353,7 +352,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
return ((SortedMap<K, V>) main.makeFullMap()).subMap(fromKey, toKey);
}
public void testSubMapOutOfRange() {
if (isPutAddSupported() == false) {
if (!isPutAddSupported()) {
return;
}
resetEmpty();

View File

@ -159,7 +159,7 @@ public class IdentityMap<K, V>
if (obj == this) {
return true;
}
if (obj instanceof Map.Entry == false) {
if (!(obj instanceof Entry)) {
return false;
}
final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;

View File

@ -69,7 +69,7 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
//-----------------------------------------------------------------------
public void testLRU() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) {
if (!isPutAddSupported() || !isPutChangeSupported()) {
return;
}
final K[] keys = getSampleKeys();
@ -151,7 +151,7 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
//-----------------------------------------------------------------------
public void testAccessOrder() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) {
if (!isPutAddSupported() || !isPutChangeSupported()) {
return;
}
final K[] keys = getSampleKeys();
@ -378,7 +378,7 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
@SuppressWarnings("unchecked")
public void testInternalState_Buckets() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) {
if (!isPutAddSupported() || !isPutChangeSupported()) {
return;
}
final SingleHashCode one = new SingleHashCode("1");
@ -468,7 +468,7 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
@SuppressWarnings("unchecked")
public void testInternalState_getEntry_int() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) {
if (!isPutAddSupported() || !isPutChangeSupported()) {
return;
}
final SingleHashCode one = new SingleHashCode("1");

View File

@ -81,7 +81,7 @@ public class LinkedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
//-----------------------------------------------------------------------
public void testInsertionOrder() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) {
if (!isPutAddSupported() || !isPutChangeSupported()) {
return;
}
final K[] keys = getSampleKeys();

View File

@ -121,7 +121,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
public void testKeyedIterator() {
final MultiValueMap<K, V> map = createTestMap();
final ArrayList<Object> actual = new ArrayList<Object>(IteratorUtils.toList(map.iterator("one")));
final ArrayList<Object> expected = new ArrayList<Object>(Arrays.asList(new String[]{ "uno", "un" }));
final ArrayList<Object> expected = new ArrayList<Object>(Arrays.asList("uno", "un"));
assertEquals(expected, actual);
}
@ -342,7 +342,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
@SuppressWarnings("unchecked")
public void testPutAll_KeyCollection() {
final MultiValueMap<K, V> map = new MultiValueMap<K, V>();
Collection<V> coll = (Collection<V>) Arrays.asList(new Object[] { "X", "Y", "Z" });
Collection<V> coll = (Collection<V>) Arrays.asList("X", "Y", "Z");
assertEquals(true, map.putAll((K) "A", coll));
assertEquals(3, map.size("A"));
@ -362,7 +362,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
assertEquals(true, map.containsValue("A", "Y"));
assertEquals(true, map.containsValue("A", "Z"));
coll = (Collection<V>) Arrays.asList(new Object[] { "M" });
coll = (Collection<V>) Arrays.asList("M");
assertEquals(true, map.putAll((K) "A", coll));
assertEquals(4, map.size("A"));
assertEquals(true, map.containsValue("A", "X"));

View File

@ -73,11 +73,10 @@ public abstract class AbstractQueueTest<E> extends AbstractCollectionTest<E> {
public void verify() {
super.verify();
final Iterator<E> iterator1 = getCollection().iterator();
final Iterator<E> iterator2 = getConfirmed().iterator();
while (iterator2.hasNext()) {
for (E e : getConfirmed()) {
assertTrue(iterator1.hasNext());
final Object o1 = iterator1.next();
final Object o2 = iterator2.next();
final Object o2 = e;
assertEquals(o1, o2);
}
}

View File

@ -49,11 +49,10 @@ public class CircularFifoQueueTest<E> extends AbstractQueueTest<E> {
public void verify() {
super.verify();
final Iterator<E> iterator1 = getCollection().iterator();
final Iterator<E> iterator2 = getConfirmed().iterator();
while (iterator2.hasNext()) {
for (E e : getConfirmed()) {
assertTrue(iterator1.hasNext());
final Object o1 = iterator1.next();
final Object o2 = iterator2.next();
final Object o2 = e;
assertEquals(o1, o2);
}
}

View File

@ -17,6 +17,7 @@
package org.apache.commons.collections4.queue;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;
@ -70,36 +71,34 @@ public class TransformedQueueTest<E> extends AbstractQueueTest<E> {
final Queue<Object> queue = TransformedQueue.transformingQueue(new LinkedList<Object>(),
TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, queue.size());
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
for (int i = 0; i < els.length; i++) {
queue.add(els[i]);
final Object[] elements = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
for (int i = 0; i < elements.length; i++) {
queue.add(elements[i]);
assertEquals(i + 1, queue.size());
assertEquals(true, queue.contains(Integer.valueOf((String) els[i])));
assertEquals(false, queue.contains(els[i]));
assertEquals(true, queue.contains(Integer.valueOf((String) elements[i])));
assertEquals(false, queue.contains(elements[i]));
}
assertEquals(false, queue.remove(els[0]));
assertEquals(true, queue.remove(Integer.valueOf((String) els[0])));
assertEquals(false, queue.remove(elements[0]));
assertEquals(true, queue.remove(Integer.valueOf((String) elements[0])));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testTransformedQueue_decorateTransform() {
final Queue originalQueue = new LinkedList();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
originalQueue.add(el);
}
final Object[] elements = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
Collections.addAll(originalQueue, elements);
final Queue<?> queue = TransformedQueue.transformedQueue(originalQueue,
TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, queue.size());
for (final Object el : els) {
assertEquals(elements.length, queue.size());
for (final Object el : elements) {
assertEquals(true, queue.contains(Integer.valueOf((String) el)));
assertEquals(false, queue.contains(el));
}
assertEquals(false, queue.remove(els[0]));
assertEquals(true, queue.remove(Integer.valueOf((String) els[0])));
assertEquals(false, queue.remove(elements[0]));
assertEquals(true, queue.remove(Integer.valueOf((String) elements[0])));
}
@Override

View File

@ -130,13 +130,13 @@ public class SequencesComparatorTest {
final ExecutionVisitor<String> ev = new ExecutionVisitor<String>();
for (int i = 0; i < shadokSentences.size(); ++i) {
for (int j = 0; j < shadokSentences.size(); ++j) {
for (List<String> shadokSentence : shadokSentences) {
ev.setList(shadokSentences.get(i));
new SequencesComparator<String>(shadokSentences.get(i),
shadokSentences.get(j)).getScript().visit(ev);
shadokSentence).getScript().visit(ev);
final StringBuilder concat = new StringBuilder();
for (final String s : shadokSentences.get(j)) {
for (final String s : shadokSentence) {
concat.append(s);
}
Assert.assertEquals(concat.toString(), ev.getString());
@ -175,7 +175,7 @@ public class SequencesComparatorTest {
}
public String getString() {
final StringBuffer buffer = new StringBuffer();
final StringBuilder buffer = new StringBuilder();
for (final T c : v) {
buffer.append(c);
}
@ -187,7 +187,7 @@ public class SequencesComparatorTest {
@Before
public void setUp() {
before = Arrays.asList(new String[] {
before = Arrays.asList(
"bottle",
"nematode knowledge",
"",
@ -196,10 +196,9 @@ public class SequencesComparatorTest {
"ABCABBA",
"glop glop",
"coq",
"spider-man"
});
"spider-man");
after = Arrays.asList(new String[] {
after = Arrays.asList(
"noodle",
"empty bottle",
"",
@ -208,8 +207,7 @@ public class SequencesComparatorTest {
"CBABAC",
"pas glop pas glop",
"ane",
"klingon"
});
"klingon");
length = new int[] {
6,

View File

@ -64,9 +64,8 @@ public abstract class AbstractSetTest<E> extends AbstractCollectionTest<E> {
assertEquals("Sets should have equal hashCodes",
getConfirmed().hashCode(), getCollection().hashCode());
final Collection<E> set = makeConfirmedCollection();
final Iterator<E> iterator = getCollection().iterator();
while (iterator.hasNext()) {
assertTrue("Set.iterator should only return unique elements", set.add(iterator.next()));
for (E element : getCollection()) {
assertTrue("Set.iterator should only return unique elements", set.add(element));
}
}

View File

@ -17,6 +17,7 @@
package org.apache.commons.collections4.set;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@ -85,9 +86,7 @@ public class TransformedSetTest<E> extends AbstractSetTest<E> {
public void testTransformedSet_decorateTransform() {
final Set<Object> originalSet = new HashSet<Object>();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
originalSet.add(el);
}
Collections.addAll(originalSet, els);
final Set<?> set = TransformedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, set.size());
for (final Object el : els) {

View File

@ -17,6 +17,7 @@
package org.apache.commons.collections4.set;
import java.util.Arrays;
import java.util.Collections;
import java.util.TreeSet;
import java.util.Set;
import java.util.SortedSet;
@ -78,9 +79,7 @@ public class TransformedSortedSetTest<E> extends AbstractSortedSetTest<E> {
public void testTransformedSet_decorateTransform() {
final Set<Object> originalSet = new TreeSet<Object>();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
originalSet.add(el);
}
Collections.addAll(originalSet, els);
final Set<?> set = TransformedSortedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, set.size());
for (final Object el : els) {