From: Bryan T. <tho...@us...> - 2009-09-24 14:47:04
|
Update of /cvsroot/cweb/junit-ext/src/java/junit/framework In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11369/src/java/junit/framework Modified Files: TestCase2.java Log Message: modified assertSameIteratorAnyOrder(...) to work without requiring that the objects implement Comparable. It was relying on a TreeMap, which uses Comparable. It now relies on a HashMap. Of course, if the object does not implement hashCode() and equals() correctly then this will cause unit tests for that object to break. Index: TestCase2.java =================================================================== RCS file: /cvsroot/cweb/junit-ext/src/java/junit/framework/TestCase2.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** TestCase2.java 4 Dec 2007 15:03:03 -0000 1.28 --- TestCase2.java 24 Sep 2009 14:46:56 -0000 1.29 *************** *** 913,1005 **** /** ! * Verifies that the iterator visits the specified objects in some ! * arbitrary ordering and that the iterator is exhausted once all ! * expected objects have been visited. The implementation uses a ! * selection without replacement "pattern". */ - static public void assertSameIteratorAnyOrder - ( Comparable[] expected, - Iterator actual - ) - { - - assertSameIteratorAnyOrder - ( "", - expected, - actual - ); - } /** ! * Verifies that the iterator visits the specified objects in some ! * arbitrary ordering and that the iterator is exhausted once all ! * expected objects have been visited. The implementation uses a ! * selection without replacement "pattern". ! * ! * FIXME Write test cases for this one. ! * ! * FIXME Can we we this without requiring the objects to implement ! * {@link Comparable}? */ ! static public void assertSameIteratorAnyOrder ! ( String msg, ! Comparable[] expected, ! Iterator actual ! ) ! { ! // Populate a map that we will use to realize the match and ! // selection without replacement logic. ! final int nrange = expected.length; ! ! java.util.Map range = new java.util.TreeMap(); ! ! for( int j=0; j<nrange; j++ ) { ! ! range.put ! ( expected[ j ], ! expected[ j ] ! ); ! ! } ! ! // Do selection without replacement for the objects visited by ! // iterator. ! ! for( int j=0; j<nrange; j++ ) { ! ! if( ! actual.hasNext() ) { ! ! fail( msg+": Index exhausted while expecting more object(s)"+ ! ": index="+j ! ); ! ! } ! ! Object actualObject = actual.next(); ! ! if( range.remove( actualObject ) == null ) { ! ! fail( "Object not expected"+ ! ": index="+j+ ! ", object="+actualObject ! ); ! ! } ! ! } ! if( actual.hasNext() ) { ! fail( "Iterator will deliver too many objects." ! ); ! } } //************************************************************ --- 913,1073 ---- /** ! * Verifies that the iterator visits the specified objects in some arbitrary ! * ordering and that the iterator is exhausted once all expected objects ! * have been visited. The implementation uses a selection without ! * replacement "pattern". */ + @SuppressWarnings("unchecked") + static public void assertSameIteratorAnyOrder(final Object[] expected, + final Iterator actual) { + + assertSameIteratorAnyOrder("", expected, actual); } /** ! * Verifies that the iterator visits the specified objects in some arbitrary ! * ordering and that the iterator is exhausted once all expected objects ! * have been visited. The implementation uses a selection without ! * replacement "pattern". */ + @SuppressWarnings("unchecked") + static public void assertSameIteratorAnyOrder(final String msg, + final Object[] expected, final Iterator actual) { ! // Populate a map that we will use to realize the match and ! // selection without replacement logic. ! final int nrange = expected.length; ! java.util.Map range = new java.util.HashMap(); ! for (int j = 0; j < nrange; j++) { ! range.put(expected[j], expected[j]); ! } ! ! // Do selection without replacement for the objects visited by ! // iterator. ! ! for (int j = 0; j < nrange; j++) { ! ! if (!actual.hasNext()) { ! ! fail(msg + ": Index exhausted while expecting more object(s)" ! + ": index=" + j); ! ! } ! ! Object actualObject = actual.next(); ! ! if (range.remove(actualObject) == null) { ! ! fail("Object not expected" + ": index=" + j + ", object=" ! + actualObject); ! ! } ! ! } ! ! if (actual.hasNext()) { ! ! fail("Iterator will deliver too many objects."); ! ! } } + + // /** + // * Verifies that the iterator visits the specified objects in some + // * arbitrary ordering and that the iterator is exhausted once all + // * expected objects have been visited. The implementation uses a + // * selection without replacement "pattern". + // */ + // + // static public void assertSameIteratorAnyOrder + // ( Comparable[] expected, + // Iterator actual + // ) + // { + // + // assertSameIteratorAnyOrder + // ( "", + // expected, + // actual + // ); + // + // } + // + // /** + // * Verifies that the iterator visits the specified objects in some + // * arbitrary ordering and that the iterator is exhausted once all + // * expected objects have been visited. The implementation uses a + // * selection without replacement "pattern". + // * + // * FIXME Write test cases for this one. + // * + // * FIXME Can we we this without requiring the objects to implement + // * {@link Comparable}? + // */ + // + // static public void assertSameIteratorAnyOrder + // ( String msg, + // Comparable[] expected, + // Iterator actual + // ) + // { + // + // // Populate a map that we will use to realize the match and + // // selection without replacement logic. + // + // final int nrange = expected.length; + // + // java.util.Map range = new java.util.TreeMap(); + // + // for( int j=0; j<nrange; j++ ) { + // + // range.put + // ( expected[ j ], + // expected[ j ] + // ); + // + // } + // + // // Do selection without replacement for the objects visited by + // // iterator. + // + // for( int j=0; j<nrange; j++ ) { + // + // if( ! actual.hasNext() ) { + // + // fail( msg+": Index exhausted while expecting more object(s)"+ + // ": index="+j + // ); + // + // } + // + // Object actualObject = actual.next(); + // + // if( range.remove( actualObject ) == null ) { + // + // fail( "Object not expected"+ + // ": index="+j+ + // ", object="+actualObject + // ); + // + // } + // + // } + // + // if( actual.hasNext() ) { + // + // fail( "Iterator will deliver too many objects." + // ); + // + // } + // + // } //************************************************************ |