Author: bayard Date: Thu May 3 12:54:44 2007 New Revision: 534976 URL: http://svn.apache.org/viewvc?view=rev&rev=534976 Log: Applying Mark Hindess' patch from COLLECTIONS-232 that cleans up the ordering of various assertEquals to be expected,actual and not actual,expected and also fixes various assertEquals to assertNulls where applicable
Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayList.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayStack.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestMapUtils.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestTreeMap.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/AbstractTestList.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazySortedMap.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayList.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayList.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayList.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayList.java Thu May 3 12:54:44 2007 @@ -54,7 +54,7 @@ //----------------------------------------------------------------------- public void testNewArrayList() { assertTrue("New list is empty", list.isEmpty()); - assertEquals("New list has size zero", list.size(), 0); + assertEquals("New list has size zero", 0, list.size()); try { list.get(1); @@ -67,8 +67,8 @@ public void testSearch() { list.add("First Item"); list.add("Last Item"); - assertEquals("First item is 'First Item'", list.get(0), "First Item"); - assertEquals("Last Item is 'Last Item'", list.get(1), "Last Item"); + assertEquals("First item is 'First Item'", "First Item", list.get(0)); + assertEquals("Last Item is 'Last Item'", "Last Item", list.get(1)); } } Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayStack.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayStack.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayStack.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestArrayStack.java Thu May 3 12:54:44 2007 @@ -58,7 +58,7 @@ public void testNewStack() { assertTrue("New stack is empty", stack.empty()); - assertEquals("New stack has size zero", stack.size(), 0); + assertEquals("New stack has size zero", 0, stack.size()); try { stack.peek(); @@ -80,26 +80,26 @@ stack.push("First Item"); assertTrue("Stack is not empty", !stack.empty()); - assertEquals("Stack size is one", stack.size(), 1); + assertEquals("Stack size is one", 1, stack.size()); assertEquals("Top item is 'First Item'", - (String) stack.peek(), "First Item"); - assertEquals("Stack size is one", stack.size(), 1); + "First Item", (String) stack.peek()); + assertEquals("Stack size is one", 1, stack.size()); stack.push("Second Item"); - assertEquals("Stack size is two", stack.size(), 2); + assertEquals("Stack size is two", 2, stack.size()); assertEquals("Top item is 'Second Item'", - (String) stack.peek(), "Second Item"); - assertEquals("Stack size is two", stack.size(), 2); + "Second Item", (String) stack.peek()); + assertEquals("Stack size is two", 2, stack.size()); assertEquals("Popped item is 'Second Item'", - (String) stack.pop(), "Second Item"); + "Second Item", (String) stack.pop()); assertEquals("Top item is 'First Item'", - (String) stack.peek(), "First Item"); - assertEquals("Stack size is one", stack.size(), 1); + "First Item", (String) stack.peek()); + assertEquals("Stack size is one", 1, stack.size()); assertEquals("Popped item is 'First Item'", - (String) stack.pop(), "First Item"); - assertEquals("Stack size is zero", stack.size(), 0); + "First Item", (String) stack.pop()); + assertEquals("Stack size is zero", 0, stack.size()); } @@ -108,11 +108,11 @@ stack.push("First Item"); stack.push("Second Item"); assertEquals("Top item is 'Second Item'", - stack.search("Second Item"), 1); + 1, stack.search("Second Item")); assertEquals("Next Item is 'First Item'", - stack.search("First Item"), 2); + 2, stack.search("First Item")); assertEquals("Cannot find 'Missing Item'", - stack.search("Missing Item"), -1); + -1, stack.search("Missing Item")); } Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java Thu May 3 12:54:44 2007 @@ -438,8 +438,8 @@ testPredicate = PredicateUtils.equalPredicate("de"); test = CollectionUtils.find(collectionA, testPredicate); assertTrue(test == null); - assertEquals(CollectionUtils.find(null,testPredicate), null); - assertEquals(CollectionUtils.find(collectionA, null), null); + assertNull(CollectionUtils.find(null,testPredicate)); + assertNull(CollectionUtils.find(collectionA, null)); } public void testForAllDo() { Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java Thu May 3 12:54:44 2007 @@ -57,14 +57,14 @@ /* * should be empty and return null */ - assertEquals("This returns null", eprop.getProperty("foo"), null); + assertNull("This returns null", eprop.getProperty("foo")); /* * add a real value, and get it two different ways */ eprop.setProperty("number", "1"); - assertEquals("This returns '1'", eprop.getProperty("number"), "1"); - assertEquals("This returns '1'", eprop.getString("number"), "1"); + assertEquals("This returns '1'", "1", eprop.getProperty("number")); + assertEquals("This returns '1'", "1", eprop.getString("number")); /* * now add another and get a Vector/list Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestMapUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestMapUtils.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestMapUtils.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestMapUtils.java Thu May 3 12:54:44 2007 @@ -159,7 +159,7 @@ Transformer transformer = TransformerUtils.asTransformer(factory); map = MapUtils.lazyMap(new HashMap(), transformer); assertTrue(map instanceof LazyMap); - try { + try { map = MapUtils.lazyMap(new HashMap(), (Transformer) null); fail("Expecting IllegalArgumentException for null transformer"); } catch (IllegalArgumentException e) { @@ -212,11 +212,11 @@ assertTrue( inKeySet.equals( outValSet )); assertTrue( inValSet.equals( outKeySet )); - assertEquals( out.get("A"), "1" ); - assertEquals( out.get("B"), "2" ); - assertEquals( out.get("C"), "3" ); - assertEquals( out.get("D"), "4" ); - assertEquals( out.get("E"), "5" ); + assertEquals( "1", out.get("A")); + assertEquals( "2", out.get("B")); + assertEquals( "3", out.get("C")); + assertEquals( "4", out.get("D")); + assertEquals( "5", out.get("E")); } public void testPutAll_Map_array() { Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestTreeMap.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestTreeMap.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestTreeMap.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestTreeMap.java Thu May 3 12:54:44 2007 @@ -50,13 +50,15 @@ public void testNewMap() { assertTrue("New map is empty", map.isEmpty()); - assertEquals("New map has size zero", map.size(), 0); + assertEquals("New map has size zero", 0, map.size()); } public void testSearch() { map.put("first", "First Item"); map.put("second", "Second Item"); - assertEquals("Top item is 'Second Item'", map.get("first"), "First Item"); - assertEquals("Next Item is 'First Item'", map.get("second"), "Second Item"); + assertEquals("Top item is 'Second Item'", + "First Item", map.get("first")); + assertEquals("Next Item is 'First Item'", + "Second Item", map.get("second")); } } Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestPredicatedBuffer.java Thu May 3 12:54:44 2007 @@ -88,13 +88,13 @@ buffer.add("one"); buffer.add("two"); buffer.add("three"); - assertEquals("Buffer get", buffer.get(), "three"); + assertEquals("Buffer get", "three", buffer.get()); } public void testRemove() { Buffer buffer = makeTestBuffer(); buffer.add("one"); - assertEquals("Buffer get", buffer.remove(), "one"); + assertEquals("Buffer get", "one", buffer.remove()); try { buffer.remove(); fail("Expecting BufferUnderflowException"); Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java Thu May 3 12:54:44 2007 @@ -1103,7 +1103,7 @@ Object[] a = new Object[] { new Object(), null, null }; Object[] array = collection.toArray(a); assertEquals("Given array shouldn't shrink", array, a); - assertEquals("Last element should be set to null", a[0], null); + assertNull("Last element should be set to null", a[0]); verify(); resetFull(); Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java Thu May 3 12:54:44 2007 @@ -353,6 +353,6 @@ c.addComposited(one, two); c.removeComposited(one); assertTrue(c.contains("1")); - assertEquals(c.size(), 2); + assertEquals(2, c.size()); } } Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/AbstractTestList.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/AbstractTestList.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/AbstractTestList.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/AbstractTestList.java Thu May 3 12:54:44 2007 @@ -498,7 +498,7 @@ Object[] other = getOtherElements(); for (int i = 0; i < other.length; i++) { assertEquals("indexOf should return -1 for nonexistent element", - list1.indexOf(other[i]), -1); + -1, list1.indexOf(other[i])); verify(); } } @@ -522,7 +522,7 @@ Object[] other = getOtherElements(); for (int i = 0; i < other.length; i++) { assertEquals("lastIndexOf should return -1 for nonexistent " + - "element", list1.lastIndexOf(other[i]), -1); + "element", -1, list1.lastIndexOf(other[i])); verify(); } } @@ -917,18 +917,18 @@ while (i < max) { assertTrue("Iterator should have next", iter.hasNext()); assertEquals("Iterator.nextIndex should work", - iter.nextIndex(), i); + i, iter.nextIndex()); assertEquals("Iterator.previousIndex should work", - iter.previousIndex(), i - 1); + i - 1, iter.previousIndex()); Object o = iter.next(); assertEquals("Iterator returned correct element", list.get(i), o); i++; } assertTrue("Iterator shouldn't have next", !iter.hasNext()); - assertEquals("nextIndex should be size", iter.nextIndex(), max); + assertEquals("nextIndex should be size", max, iter.nextIndex()); assertEquals("previousIndex should be size - 1", - iter.previousIndex(), max - 1); + max - 1, iter.previousIndex()); try { iter.next(); @@ -949,19 +949,23 @@ List list = getList(); while (i > 0) { - assertTrue("Iterator should have previous, i:" + i, iter.hasPrevious()); - assertEquals("Iterator.nextIndex should work, i:" + i, iter.nextIndex(), i); - assertEquals("Iterator.previousIndex should work, i:" + i, iter.previousIndex(), i - 1); + assertTrue("Iterator should have previous, i:" + i, + iter.hasPrevious()); + assertEquals("Iterator.nextIndex should work, i:" + i, + i, iter.nextIndex()); + assertEquals("Iterator.previousIndex should work, i:" + i, + i - 1, iter.previousIndex()); Object o = iter.previous(); - assertEquals("Iterator returned correct element", list.get(i - 1), o); + assertEquals("Iterator returned correct element", + list.get(i - 1), o); i--; } assertTrue("Iterator shouldn't have previous", !iter.hasPrevious()); int nextIndex = iter.nextIndex(); - assertEquals("nextIndex should be 0, actual value: " + nextIndex, nextIndex, 0); + assertEquals("nextIndex should be 0", 0, nextIndex); int prevIndex = iter.previousIndex(); - assertEquals("previousIndex should be -1, actual value: " + prevIndex, prevIndex, -1); + assertEquals("previousIndex should be -1", -1, prevIndex); try { iter.previous(); @@ -1037,8 +1041,8 @@ byte[] objekt = writeExternalFormToBytes((Serializable) list); List list2 = (List) readExternalFormFromBytes(objekt); - assertTrue("Both lists are empty",list.size() == 0); - assertTrue("Both lists are empty",list2.size() == 0); + assertEquals("Both lists are empty", 0, list.size()); + assertEquals("Both lists are empty", 0, list2.size()); } public void testFullListSerialization() @@ -1050,8 +1054,8 @@ byte[] objekt = writeExternalFormToBytes((Serializable) list); List list2 = (List) readExternalFormFromBytes(objekt); - assertEquals("Both lists are same size",list.size(), size); - assertEquals("Both lists are same size",list2.size(), size); + assertEquals("Both lists are same size", size, list.size()); + assertEquals("Both lists are same size", size, list2.size()); } /** @@ -1071,7 +1075,7 @@ List list = makeEmptyList(); if(list instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) { List list2 = (List) readExternalFormFromDisk(getCanonicalEmptyCollectionName(list)); - assertTrue("List is empty",list2.size() == 0); + assertEquals("List is empty", 0, list2.size()); assertEquals(list, list2); } } Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java Thu May 3 12:54:44 2007 @@ -993,8 +993,7 @@ int size = map.size(); for (int i = 0; i < other.length; i++) { Object o = map.remove(other[i]); - assertEquals("map.remove for nonexistent key should return null", - o, null); + assertNull("map.remove for nonexistent key should return null", o); assertEquals("map.remove for nonexistent key should not " + "shrink map", size, map.size()); } Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java Thu May 3 12:54:44 2007 @@ -78,7 +78,7 @@ assertTrue(keys.contains("one")); assertTrue(keys.contains("two")); assertTrue(keys.contains(null)); - assertTrue(keys.size() == 3); + assertEquals(3, keys.size()); } public void testPutAll() { @@ -89,16 +89,16 @@ map.put(null, "Four"); map.put(new Integer(20), "Five"); Map caseInsensitiveMap = new CaseInsensitiveMap(map); - assertTrue(caseInsensitiveMap.size() == 4); // ones collapsed + assertEquals(4, caseInsensitiveMap.size()); // ones collapsed Set keys = caseInsensitiveMap.keySet(); assertTrue(keys.contains("one")); assertTrue(keys.contains("two")); assertTrue(keys.contains(null)); assertTrue(keys.contains(Integer.toString(20))); - assertTrue(keys.size() == 4); + assertEquals(4, keys.size()); assertTrue(!caseInsensitiveMap.containsValue("One") || !caseInsensitiveMap.containsValue("Three")); // ones collaped - assertEquals(caseInsensitiveMap.get(null), "Four"); + assertEquals("Four", caseInsensitiveMap.get(null)); } public void testClone() { Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazySortedMap.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazySortedMap.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazySortedMap.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLazySortedMap.java Thu May 3 12:54:44 2007 @@ -104,14 +104,14 @@ map.put("A", "a"); map.get("B"); // Entry with value "One" created map.put("C", "c"); - assertEquals("First key should be A", map.firstKey(), "A"); - assertEquals("Last key should be C", map.lastKey(), "C"); + assertEquals("First key should be A", "A", map.firstKey()); + assertEquals("Last key should be C", "C", map.lastKey()); assertEquals("First key in tail map should be B", - map.tailMap("B").firstKey(), "B"); + "B", map.tailMap("B").firstKey()); assertEquals("Last key in head map should be B", - map.headMap("C").lastKey(), "B"); + "B", map.headMap("C").lastKey()); assertEquals("Last key in submap should be B", - map.subMap("A","C").lastKey(), "B"); + "B", map.subMap("A","C").lastKey()); Comparator c = map.comparator(); assertTrue("natural order, so comparator should be null", Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java?view=diff&rev=534976&r1=534975&r2=534976 ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java Thu May 3 12:54:44 2007 @@ -167,14 +167,14 @@ } catch (IllegalArgumentException e) { // expected } - assertEquals("First key should be A", map.firstKey(), "A"); - assertEquals("Last key should be C", map.lastKey(), "C"); + assertEquals("First key should be A", "A", map.firstKey()); + assertEquals("Last key should be C", "C", map.lastKey()); assertEquals("First key in tail map should be B", - map.tailMap("B").firstKey(), "B"); + "B", map.tailMap("B").firstKey()); assertEquals("Last key in head map should be B", - map.headMap("C").lastKey(), "B"); + "B", map.headMap("C").lastKey()); assertEquals("Last key in submap should be B", - map.subMap("A","C").lastKey(), "B"); + "B", map.subMap("A","C").lastKey()); Comparator c = map.comparator(); assertTrue("natural order, so comparator should be null", --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]