Skip to content
Permalink
Browse files
Clean up tests.
- Simple syntax for array creation.
- Use better Collection APIs.
- Make test fixture a static class.
- Use number cache when possible.
  • Loading branch information
garydgregory committed Mar 4, 2022
1 parent 505722c commit 5588a9bdeebd5a8a3f4010eaab8a6a4484d6b71f
Showing 34 changed files with 77 additions and 77 deletions.
@@ -413,7 +413,7 @@ public void testTransformerClosure() {
*/
@Test
public void testSingletonPatternInSerialization() {
final Object[] singletons = new Object[] {
final Object[] singletons = {
ExceptionClosure.INSTANCE,
NOPClosure.INSTANCE,
};
@@ -2022,7 +2022,7 @@ public void testReverseArrayNull() {

@Test
public void testSize_Array() {
final Object[] objectArray = new Object[0];
final Object[] objectArray = {};
assertEquals(0, CollectionUtils.size(objectArray));

final String[] stringArray = new String[3];
@@ -2083,7 +2083,7 @@ public void testSize_Other() {

@Test
public void testSize_PrimitiveArray() {
final int[] intArray = new int[0];
final int[] intArray = {};
assertEquals(0, CollectionUtils.size(intArray));

final double[] doubleArray = new double[3];
@@ -2096,7 +2096,7 @@ public void testSize_PrimitiveArray() {

@Test
public void testSizeIsEmpty_Array() {
final Object[] objectArray = new Object[0];
final Object[] objectArray = {};
assertTrue(CollectionUtils.sizeIsEmpty(objectArray));

final String[] stringArray = new String[3];
@@ -2162,7 +2162,7 @@ public void testSizeIsEmpty_Other() {

@Test
public void testSizeIsEmpty_PrimitiveArray() {
final int[] intArray = new int[0];
final int[] intArray = {};
assertTrue(CollectionUtils.sizeIsEmpty(intArray));

final double[] doubleArray = new double[3];
@@ -240,7 +240,7 @@ public void instantiateFactoryComplex() {
*/
@Test
public void testSingletonPatternInSerialization() {
final Object[] singletons = new Object[] {
final Object[] singletons = {
ExceptionFactory.INSTANCE,
};

@@ -672,7 +672,7 @@ public void testTransformedPredicate() {
*/
@Test
public void testSingletonPatternInSerialization() {
final Object[] singletons = new Object[] {
final Object[] singletons = {
ExceptionPredicate.INSTANCE,
FalsePredicate.INSTANCE,
NotNullPredicate.INSTANCE,
@@ -419,7 +419,7 @@ public void testInstantiateTransformerNull() {
*/
@Test
public void testSingletonPatternInSerialization() {
final Object[] singletons = new Object[] {
final Object[] singletons = {
ExceptionTransformer.INSTANCE,
NOPTransformer.INSTANCE,
StringValueTransformer.stringValueTransformer(),
@@ -53,7 +53,7 @@ public void testTransformedBag() {
final Bag<T> bag = TransformedBag.transformingBag(new HashBag<T>(),
(Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertTrue(bag.isEmpty());
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
final Object[] els = {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
bag.add((T) els[i]);
assertEquals(i + 1, bag.size());
@@ -68,7 +68,7 @@ public void testTransformedBag() {
@SuppressWarnings("unchecked")
public void testTransformedBag_decorateTransform() {
final Bag<T> originalBag = new HashBag<>();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
final Object[] els = {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
originalBag.add((T) el);
}
@@ -50,7 +50,7 @@ public SortedBag<T> makeObject() {
public void testTransformedBag() {
final SortedBag<T> bag = TransformedSortedBag.transformingSortedBag(new TreeBag<T>(), (Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, bag.size());
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
final Object[] els = {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
bag.add((T) els[i]);
assertEquals(i + 1, bag.size());
@@ -63,7 +63,7 @@ public void testTransformedBag() {

public void testTransformedBag_decorateTransform() {
final TreeBag<T> originalBag = new TreeBag<>();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
final Object[] els = {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
originalBag.add((T) el);
}
@@ -278,7 +278,7 @@ public void testBidiRemoveByKeySet() {
}

private void removeByKeySet(final BidiMap<?, ?> map, final Object key, final Object value) {
map.keySet().remove(key);
map.remove(key);

assertFalse("Key was not removed.", map.containsKey(key));
assertFalse("Value was not removed.", map.containsValue(value));
@@ -1093,7 +1093,7 @@ public void testCollectionToArray() {
*/
public void testCollectionToArray2() {
resetEmpty();
Object[] a = new Object[] { new Object(), null, null };
Object[] a = { new Object(), null, null };
Object[] array = getCollection().toArray(a);
assertEquals("Given array shouldn't shrink", array, a);
assertNull("Last element should be set to null", a[0]);
@@ -34,7 +34,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
/**
* Top cities of the world, by population including metro areas.
*/
private static final String topCities[] = new String[] {
private static final String topCities[] = {
"Tokyo",
"Mexico City",
"Mumbai",
@@ -25,7 +25,7 @@


public class ComparatorPredicateTest extends AbstractPredicateTest {
private class TestComparator<T extends Comparable<T>> implements Comparator<T> {
private static class TestComparator<T extends Comparable<T>> implements Comparator<T> {
@Override
public int compare(final T first, final T second) {
return first.compareTo(second);
@@ -87,9 +87,9 @@ public void testListIterator() {
*/
@SuppressWarnings("unchecked")
public void testListIteratorSet() {
final String[] testData = new String[] { "a", "b", "c" };
final String[] testData = { "a", "b", "c" };

final String[] result = new String[] { "0", "1", "2" };
final String[] result = { "0", "1", "2" };

ListIterator<E> iter = makeArrayListIterator(testData);
int x = 0;
@@ -84,9 +84,9 @@ public void testListIterator() {
*/
@SuppressWarnings("unchecked")
public void testListIteratorSet() {
final String[] testData = new String[] { "a", "b", "c" };
final String[] testData = { "a", "b", "c" };

final String[] result = new String[] { "0", "1", "2" };
final String[] result = { "0", "1", "2" };

ListIterator<E> iter = makeArrayListIterator((E[]) testData);
int x = 0;
@@ -120,7 +120,7 @@ public void testConstructors() throws Exception {
@Test
public void testConstructorsByArray() throws Exception {
MultiKey<Integer> mk;
Integer[] keys = new Integer[] { THREE, FOUR, ONE, TWO };
Integer[] keys = { THREE, FOUR, ONE, TWO };
mk = new MultiKey<>(keys);
assertArrayEquals(new Object[]{THREE, FOUR, ONE, TWO}, mk.getKeys());
keys[3] = FIVE; // no effect
@@ -246,7 +246,7 @@ public Collection<DynamicTest> testGetIndexed() {

@Test
public void testGetKeysArrayConstructorCloned() {
final Integer[] keys = new Integer[] { ONE, TWO };
final Integer[] keys = { ONE, TWO };
final MultiKey<Integer> mk = new MultiKey<>(keys, true);
final Object[] array = mk.getKeys();
assertNotSame(array, keys);
@@ -258,7 +258,7 @@ public void testGetKeysArrayConstructorCloned() {

@Test
public void testGetKeysArrayConstructorNonCloned() {
final Integer[] keys = new Integer[] { ONE, TWO };
final Integer[] keys = { ONE, TWO };
final MultiKey<Integer> mk = new MultiKey<>(keys, false);
final Object[] array = mk.getKeys();
assertNotSame(array, keys); // still not equal
@@ -1496,7 +1496,7 @@ public String[] ignoredTests() {
final ArrayList<String> list = new ArrayList<>();
final String prefix = "CursorableLinkedListTest";
final String bulk = ".bulkTestSubList";
final String[] ignored = new String[] {
final String[] ignored = {
".testEmptyListSerialization",
".testFullListSerialization",
".testEmptyListCompatibility",
@@ -61,18 +61,18 @@ public E[] getFullNonNullElements() {
Integer.valueOf(2),
"Three",
Integer.valueOf(4),
new Double(5),
new Float(6),
Double.valueOf(5),
Float.valueOf(6),
"Seven",
"Eight",
"Nine",
Integer.valueOf(10),
new Short((short) 11),
new Long(12),
Short.valueOf((short) 11),
Long.valueOf(12),
"Thirteen",
"14",
"15",
new Byte((byte) 16)
Byte.valueOf((byte) 16)
};
}

@@ -234,7 +234,7 @@ public void testCollections701() {
}

public void testFactory() {
final Integer[] array = new Integer[] { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(1) };
final Integer[] array = { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(1) };
final ArrayList<Integer> list = new ArrayList<>(Arrays.asList(array));
final SetUniqueList<Integer> lset = SetUniqueList.setUniqueList(list);

@@ -337,12 +337,12 @@ public void testListSetByIndex() {
// override for set behavior
resetFull();
final int size = getCollection().size();
getCollection().set(0, (E) new Long(1000));
getCollection().set(0, (E) Long.valueOf(1000));
assertEquals(size, getCollection().size());

getCollection().set(2, (E) new Long(1000));
getCollection().set(2, (E) Long.valueOf(1000));
assertEquals(size - 1, getCollection().size());
assertEquals(new Long(1000), getCollection().get(1)); // set into 2, but shifted down to 1
assertEquals(Long.valueOf(1000), getCollection().get(1)); // set into 2, but shifted down to 1
}

@SuppressWarnings("unchecked")
@@ -596,12 +596,12 @@ public void verify() {

if (extraVerify) {
final int size = getCollection().size();
getCollection().add((E) new Long(1000));
getCollection().add((E) Long.valueOf(1000));
assertEquals(size + 1, getCollection().size());

getCollection().add((E) new Long(1000));
getCollection().add((E) Long.valueOf(1000));
assertEquals(size + 1, getCollection().size());
assertEquals(new Long(1000), getCollection().get(size));
assertEquals(Long.valueOf(1000), getCollection().get(size));

getCollection().remove(size);
}
@@ -109,7 +109,7 @@ public void testTransformedList() {

public void testTransformedList_decorateTransform() {
final List<Object> originalList = new ArrayList<>();
final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
final Object[] els = {"1", "3", "5", "7", "2", "4", "6"};
for (final Object el : els) {
originalList.add(el);
}
@@ -299,7 +299,7 @@ public boolean areEqualElementsDistinguishable() {
*/
@SuppressWarnings("unchecked")
public K[] getSampleKeys() {
final Object[] result = new Object[] {
final Object[] result = {
"blah", "foo", "bar", "baz", "tmp", "gosh", "golly", "gee",
"hello", "goodbye", "we'll", "see", "you", "all", "again",
"key",
@@ -354,7 +354,7 @@ public Object[] getOtherNonNullStringElements() {
*/
@SuppressWarnings("unchecked")
public V[] getSampleValues() {
final Object[] result = new Object[] {
final Object[] result = {
"blahv", "foov", "barv", "bazv", "tmpv", "goshv", "gollyv", "geev",
"hellov", "goodbyev", "we'llv", "seev", "youv", "allv", "againv",
isAllowNullValue() && !JDK12 ? null : "nonnullvalue",
@@ -377,7 +377,7 @@ public V[] getSampleValues() {
*/
@SuppressWarnings("unchecked")
public V[] getNewSampleValues() {
final Object[] result = new Object[] {
final Object[] result = {
isAllowNullValue() && !JDK12 && isAllowDuplicateValues() ? null : "newnonnullvalue",
"newvalue",
isAllowDuplicateValues() ? "newvalue" : "newvalue2",
@@ -39,7 +39,7 @@
@SuppressWarnings("boxing")
public class LazySortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {

private class ReverseStringComparator implements Comparator<String> {
private static class ReverseStringComparator implements Comparator<String> {
@Override
public int compare(final String arg0, final String arg1) {
return arg1.compareTo(arg0);
@@ -121,8 +121,8 @@ public void testNullHandling() {
assertFalse(map.containsValue(null));
assertNull(map.remove(null));
assertFalse(map.entrySet().contains(null));
assertFalse(map.keySet().contains(null));
assertFalse(map.values().contains(null));
assertFalse(map.containsKey(null));
assertFalse(map.containsValue(null));
try {
map.put(null, null);
fail();
@@ -214,7 +214,7 @@ public void testIsEmpty() {

public void testKeySet() {
final Map<Integer, String> m = makeTestMap();
assertEquals(3, m.keySet().size());
assertEquals(3, m.size());
}

public void testPut() {
@@ -234,7 +234,7 @@ public void testSize() {

public void testValues() {
final Map<Integer, String> m = makeTestMap();
assertEquals(3, m.values().size());
assertEquals(3, m.size());
}

public void testZeroTimeToLive() {
@@ -88,8 +88,8 @@ public void testNullHandling() {
assertFalse(map.containsValue(null));
assertNull(map.remove(null));
assertFalse(map.entrySet().contains(null));
assertFalse(map.keySet().contains(null));
assertFalse(map.values().contains(null));
assertFalse(map.containsKey(null));
assertFalse(map.containsValue(null));
try {
map.put(null, null);
fail();
@@ -45,7 +45,7 @@ public IterableMap<K, V> makeObject() {

@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTransformedMap() {
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
final Object[] els = { "1", "3", "5", "7", "2", "4", "6" };

Map<K, V> map = TransformedMap
.transformingMap(
@@ -65,7 +65,7 @@ public boolean isSubMapViewsSerializable() {

@SuppressWarnings("unchecked")
public void testTransformedMap() {
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
final Object[] els = { "1", "3", "5", "7", "2", "4", "6" };

SortedMap<K, V> map = TransformedSortedMap
.transformingSortedMap(
@@ -129,7 +129,7 @@ public boolean isTestSerialization() {
*/
@SuppressWarnings("unchecked")
public K[] getSampleKeys() {
final Object[] result = new Object[] {
final Object[] result = {
"one", "one", "two", "two",
"three", "three"
};
@@ -144,7 +144,7 @@ public K[] getSampleKeys() {
*/
@SuppressWarnings("unchecked")
public V[] getSampleValues() {
final Object[] result = new Object[] {
final Object[] result = {
"uno", "un", "dos", "deux",
"tres", "trois"
};

0 comments on commit 5588a9b

Please sign in to comment.