groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [11/50] [abbrv] groovy git commit: GROOVY-7961: ObjectRange do not return null when exhausted (closes #440)
Date Thu, 10 Nov 2016 15:13:43 GMT
GROOVY-7961: ObjectRange do not return null when exhausted (closes #440)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/445869f4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/445869f4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/445869f4

Branch: refs/heads/parrot
Commit: 445869f433996ff6102e82dac751fa0092bcf1a9
Parents: 2e2e471
Author: John Tompkins <tompkins.jt@gmail.com>
Authored: Thu Oct 6 19:54:58 2016 -0400
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Thu Oct 6 20:48:09 2016 -0700

----------------------------------------------------------------------
 src/main/groovy/lang/ObjectRange.java              |  6 +++---
 .../groovy/lang/BigDecimalObjectRangeTest.java     |  1 -
 .../groovy/lang/BigIntegerObjectRangeTest.java     |  1 -
 src/test/groovy/lang/DoubleObjectRangeTest.java    |  1 -
 src/test/groovy/lang/FloatObjectRangeTest.java     |  1 -
 src/test/groovy/lang/IntegerObjectRangeTest.java   |  1 -
 src/test/groovy/lang/LongObjectRangeTest.java      |  1 -
 src/test/groovy/lang/NumberRangeTestCase.java      | 17 ++++-------------
 src/test/groovy/lang/ObjectRangeTest.java          | 13 +++++++++++++
 src/test/groovy/lang/ShortObjectRangeTest.java     |  1 -
 10 files changed, 20 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/main/groovy/lang/ObjectRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/ObjectRange.java b/src/main/groovy/lang/ObjectRange.java
index 8741c9b..1cf392e 100644
--- a/src/main/groovy/lang/ObjectRange.java
+++ b/src/main/groovy/lang/ObjectRange.java
@@ -29,6 +29,7 @@ import java.math.BigInteger;
 import java.util.AbstractList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 /**
  * Represents an inclusive list of objects from a value to a value using
@@ -446,9 +447,8 @@ public class ObjectRange extends AbstractList<Comparable> implements
Range<Compa
         @Override
         public Comparable next() {
             // not thread safe
-            if (!nextFetched) {
-                value = peek();
-                nextFetched = true;
+            if (!hasNext()) {
+                throw new NoSuchElementException();
             }
             nextFetched = false;
             index++;

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/BigDecimalObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/BigDecimalObjectRangeTest.java b/src/test/groovy/lang/BigDecimalObjectRangeTest.java
index fcaa7b2..6fcc5da 100644
--- a/src/test/groovy/lang/BigDecimalObjectRangeTest.java
+++ b/src/test/groovy/lang/BigDecimalObjectRangeTest.java
@@ -27,7 +27,6 @@ public class BigDecimalObjectRangeTest extends NumberRangeTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        expectNullFromExhausted = true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/BigIntegerObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/BigIntegerObjectRangeTest.java b/src/test/groovy/lang/BigIntegerObjectRangeTest.java
index 15fb61a..70b1b32 100644
--- a/src/test/groovy/lang/BigIntegerObjectRangeTest.java
+++ b/src/test/groovy/lang/BigIntegerObjectRangeTest.java
@@ -27,7 +27,6 @@ public class BigIntegerObjectRangeTest extends NumberRangeTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        expectNullFromExhausted = true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/DoubleObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/DoubleObjectRangeTest.java b/src/test/groovy/lang/DoubleObjectRangeTest.java
index 6d866a2..3ec9dd0 100644
--- a/src/test/groovy/lang/DoubleObjectRangeTest.java
+++ b/src/test/groovy/lang/DoubleObjectRangeTest.java
@@ -27,7 +27,6 @@ public class DoubleObjectRangeTest extends NumberRangeTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        expectNullFromExhausted = true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/FloatObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/FloatObjectRangeTest.java b/src/test/groovy/lang/FloatObjectRangeTest.java
index e46bb48..7ffa9b5 100644
--- a/src/test/groovy/lang/FloatObjectRangeTest.java
+++ b/src/test/groovy/lang/FloatObjectRangeTest.java
@@ -25,7 +25,6 @@ public class FloatObjectRangeTest extends NumberRangeTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        expectNullFromExhausted = true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/IntegerObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/IntegerObjectRangeTest.java b/src/test/groovy/lang/IntegerObjectRangeTest.java
index 29f8adc..968c6d8 100644
--- a/src/test/groovy/lang/IntegerObjectRangeTest.java
+++ b/src/test/groovy/lang/IntegerObjectRangeTest.java
@@ -25,7 +25,6 @@ public class IntegerObjectRangeTest extends NumberRangeTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        expectNullFromExhausted = true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/LongObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/LongObjectRangeTest.java b/src/test/groovy/lang/LongObjectRangeTest.java
index 5d7c8e2..da15aab 100644
--- a/src/test/groovy/lang/LongObjectRangeTest.java
+++ b/src/test/groovy/lang/LongObjectRangeTest.java
@@ -25,7 +25,6 @@ public class LongObjectRangeTest extends NumberRangeTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        expectNullFromExhausted = true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/NumberRangeTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/NumberRangeTestCase.java b/src/test/groovy/lang/NumberRangeTestCase.java
index c3ea57f..7e00612 100644
--- a/src/test/groovy/lang/NumberRangeTestCase.java
+++ b/src/test/groovy/lang/NumberRangeTestCase.java
@@ -32,11 +32,6 @@ import java.util.NoSuchElementException;
 public abstract class NumberRangeTestCase extends TestCase {
 
     /**
-     * legacy ranges in Groovy hush exceptions and return null when exhausted
-     */
-    protected boolean expectNullFromExhausted = false;
-
-    /**
      * Records the values passed to a closure.
      */
     protected static class RecordingClosure extends Closure {
@@ -429,14 +424,10 @@ public abstract class NumberRangeTestCase extends TestCase {
             assertEquals("wrong next value", createValue(next++), value);
         }
         assertEquals("wrong number of elements in iteration", 6, next);
-        if (expectNullFromExhausted) {
-            assertNull("got element after iterator finished", iter.next());
-        } else {
-            try {
-                iter.next();
-                fail("successfully got element from exhausted iterator");
-            } catch(NoSuchElementException ignore) {
-            }
+        try {
+            iter.next();
+            fail("successfully got element from exhausted iterator");
+        } catch(NoSuchElementException ignore) {
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/ObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/ObjectRangeTest.java b/src/test/groovy/lang/ObjectRangeTest.java
index fb64ab2..39f1361 100644
--- a/src/test/groovy/lang/ObjectRangeTest.java
+++ b/src/test/groovy/lang/ObjectRangeTest.java
@@ -25,6 +25,7 @@ import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 /**
  * Provides unit tests for the <code>ObjectRange</code> class.
@@ -308,6 +309,18 @@ public class ObjectRangeTest extends TestCase {
         assertFalse("a != c", a.equals(c));
     }
 
+    public void testIteratorException() {
+        Iterator iter = createRange(1, 2).iterator();
+        iter.next();
+        iter.next();
+        try {
+            iter.next();
+            fail("Should have thrown NoSuchElementException");
+        } catch(NoSuchElementException e) {
+
+        }
+    }
+
     public void testIteratorAndStep1() {
         Range r = createRange(5, 11);
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/445869f4/src/test/groovy/lang/ShortObjectRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/ShortObjectRangeTest.java b/src/test/groovy/lang/ShortObjectRangeTest.java
index a2d0ccc..67b37bf 100644
--- a/src/test/groovy/lang/ShortObjectRangeTest.java
+++ b/src/test/groovy/lang/ShortObjectRangeTest.java
@@ -25,7 +25,6 @@ public class ShortObjectRangeTest extends NumberRangeTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        expectNullFromExhausted = true;
     }
 
     /**


Mime
View raw message