Index: /Users/edwin/workspace/groovy/src/test/AllGroovyJavaTestsSuite.java =================================================================== --- /Users/edwin/workspace/groovy/src/test/AllGroovyJavaTestsSuite.java (revision 4080) +++ /Users/edwin/workspace/groovy/src/test/AllGroovyJavaTestsSuite.java (working copy) @@ -1,5 +1,6 @@ import groovy.inspect.InspectorTest; import groovy.lang.*; +import groovy.lang.RangeTest; import groovy.security.SecurityTest; import groovy.security.SignedJarTest; import groovy.servlet.GroovyServletTest; @@ -23,9 +24,8 @@ suite.addTestSuite(InspectorTest.class); suite.addTestSuite(GroovyShellTest.class); suite.addTestSuite(GStringTest.class); - suite.addTestSuite(IntRangeTest.class); suite.addTestSuite(MetaClassTest.class); - suite.addTestSuite(RangeTest.class); + // suite.addTestSuite(RangeTest.class); suite.addTestSuite(ScriptIntegerDivideTest.class); suite.addTestSuite(ScriptPrintTest.class); suite.addTestSuite(ScriptTest.class); @@ -41,6 +41,8 @@ suite.addTestSuite(MBeanTest.class); suite.addTestSuite(XmlTest.class); + suite.addTest(new RangeTestSuite()); + return suite; } } Index: /Users/edwin/workspace/groovy/src/main/groovy/lang/EmptyRange.java =================================================================== --- /Users/edwin/workspace/groovy/src/main/groovy/lang/EmptyRange.java (revision 4080) +++ /Users/edwin/workspace/groovy/src/main/groovy/lang/EmptyRange.java (working copy) @@ -8,88 +8,86 @@ * Constructing Ranges like 0..<0 * @author Dierk Koenig */ -public class EmptyRange implements Range { +public class EmptyRange extends AbstractList implements Range { + + /** + * The value at which the range originates (may be null). + */ protected Comparable at = null; - protected final List EMPTY_LIST = new ArrayList(); + /** + * Creates a new {@link EmptyRange}. + * + * @param at the value at which the range starts (may be null). + */ public EmptyRange(Comparable at) { this.at = at; } + /** + * {@inheritDoc} + */ public Comparable getFrom() { return at; } + /** + * {@inheritDoc} + */ public Comparable getTo() { return at; } + /** + * Returns false + * + * @return false + */ public boolean isReverse() { return false; } + /** + * {@inheritDoc} + */ public String inspect() { - return InvokerHelper.inspect(at)+"..<"+InvokerHelper.inspect(at); + return InvokerHelper.inspect(at) + "..<" + InvokerHelper.inspect(at); } + /** + * {@inheritDoc} + */ public String toString() { - if (null == at) return "null..IndexOutOfBoundsException. + * + * @throws IndexOutOfBoundsException always */ - public void add(int index, Object element) { - throw new UnsupportedOperationException("cannot add to Empty Ranges"); + public Object get(int index) { + throw new IndexOutOfBoundsException("can't get values from Empty Ranges"); } - public int indexOf(Object o) { - return -1; - } - - public int lastIndexOf(Object o) { - return -1; - } - /** - * @throws UnsupportedOperationException + * @throws UnsupportedOperationException always */ public boolean add(Object o) { throw new UnsupportedOperationException("cannot add to Empty Ranges"); } - public boolean contains(Object o) { - return false; - } - - public boolean remove(Object o) { - return false; - } - /** * @throws UnsupportedOperationException */ @@ -103,35 +101,35 @@ public boolean addAll(Collection c) { throw new UnsupportedOperationException("cannot add to Empty Ranges"); } + + /** + * @throws UnsupportedOperationException + */ + public boolean remove(Object o) { + throw new UnsupportedOperationException("cannot remove from Empty Ranges"); + } - public boolean containsAll(Collection c) { - return false; + /** + * @throws UnsupportedOperationException + */ + public Object remove(int index) { + throw new UnsupportedOperationException("cannot remove from Empty Ranges"); } + /** + * @throws UnsupportedOperationException + */ public boolean removeAll(Collection c) { - return false; + throw new UnsupportedOperationException("cannot remove from Empty Ranges"); } + /** + * @throws UnsupportedOperationException + */ public boolean retainAll(Collection c) { - return false; + throw new UnsupportedOperationException("cannot retainAll in Empty Ranges"); } - public Iterator iterator() { - return EMPTY_LIST.iterator(); - } - - public List subList(int fromIndex, int toIndex) { - return EMPTY_LIST.subList(fromIndex, toIndex); - } - - public ListIterator listIterator() { - return EMPTY_LIST.listIterator(); - } - - public ListIterator listIterator(int index) { - return EMPTY_LIST.listIterator(index); - } - /** * @throws UnsupportedOperationException */ @@ -139,14 +137,16 @@ throw new UnsupportedOperationException("cannot set in Empty Ranges"); } - public Object[] toArray(Object a[]) { - return new Object[0]; - } - + /** + * {@inheritDoc} + */ public void step(int step, Closure closure) { } + /** + * {@inheritDoc} + */ public List step(int step) { - return EMPTY_LIST; + return new ArrayList(); } } Index: /Users/edwin/workspace/groovy/src/test/groovy/lang/EmptyRangeTest.java =================================================================== --- /Users/edwin/workspace/groovy/src/test/groovy/lang/EmptyRangeTest.java (revision 0) +++ /Users/edwin/workspace/groovy/src/test/groovy/lang/EmptyRangeTest.java (revision 0) @@ -0,0 +1,395 @@ +/** + * + */ +package groovy.lang; + +import groovy.util.GroovyTestCase; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; + +/** + * Provides unit tests for the {@link EmptyRange} class. + * + * @author $Author$ + * @version $Revision$ + */ +public class EmptyRangeTest extends GroovyTestCase { + + /** + * The 'from' value for the {@link Range}. + */ + private static final Integer AT = new Integer(17); + + /** + * The {@link Range} to test. + */ + private Range range = null; + + /** + * {@inheritDoc} + */ + protected void setUp() throws Exception { + super.setUp(); + + range = new EmptyRange(AT); + } + + /** + * Test method for {@link groovy.lang.EmptyRange#getFrom()}. + */ + public void testGetFrom() { + assertEquals("wrong 'from' value", AT, range.getFrom()); + } + + /** + * Test method for {@link groovy.lang.EmptyRange#getTo()}. + */ + public void testGetTo() { + assertEquals("wrong 'from' value", AT, range.getTo()); + } + + /** + * Test method for {@link groovy.lang.EmptyRange#isReverse()}. + */ + public void testIsReverse() { + assertFalse("empty range reversed", range.isReverse()); + } + + /** + * Test method for {@link groovy.lang.EmptyRange#inspect()}. + */ + public void testInspect() { + assertEquals("wrong 'inspect' value", AT + "..<" + AT, range.inspect()); + } + + /** + * Test method for {@link groovy.lang.EmptyRange#inspect()()} with a range with a null 'at' value. + */ + public void testInspectNullAt() { + final Range nullAtRange = new EmptyRange(null); + assertEquals("wrong inspect value", "null..null 'at' value. + */ + public void testToStringNullAt() { + final Range nullAtRange = new EmptyRange(null); + assertEquals("wrong string value", "null..