This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit 38e6e95c53dad0350bd0d1ac275926056f4db9c5
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Jun 1 11:11:44 2024 -0400

    Use assertThrows()
---
 .../apache/commons/jexl3/internal/RangeTest.java   | 48 ++++------------------
 1 file changed, 9 insertions(+), 39 deletions(-)

diff --git a/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java 
b/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
index 0221399d..6b86a9e2 100644
--- a/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
+++ b/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
@@ -19,7 +19,7 @@ package org.apache.commons.jexl3.internal;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
@@ -88,44 +88,24 @@ public class RangeTest extends JexlTestCase {
     public void testAscIterator() {
         final Iterator<Integer> ii = new AscIntegerIterator(3, 5);
         Integer i = 3;
-        while(ii.hasNext()) {
+        while (ii.hasNext()) {
             assertEquals(i, ii.next());
             i += 1;
         }
-        try {
-            ii.next();
-            fail("iterator exhausted");
-        } catch(final NoSuchElementException e) {
-            assertNotNull(e);
-        }
-        try {
-            ii.remove();
-            fail("remove not implemented");
-        } catch(final UnsupportedOperationException e) {
-            assertNotNull(e);
-        }
+        assertThrows(NoSuchElementException.class, ii::next, "iterator 
exhausted");
+        assertThrows(UnsupportedOperationException.class, ii::remove, "remove 
not implemented");
     }
 
     @Test
     public void testAscLongIterator() {
         final Iterator<Long> ii = new AscLongIterator(3L, 5L);
         Long i = 3L;
-        while(ii.hasNext()) {
+        while (ii.hasNext()) {
             assertEquals(i, ii.next());
             i += 1;
         }
-        try {
-            ii.next();
-            fail("iterator exhausted");
-        } catch(final NoSuchElementException e) {
-            assertNotNull(e);
-        }
-        try {
-            ii.remove();
-            fail("remove not implemented");
-        } catch(final UnsupportedOperationException e) {
-            assertNotNull(e);
-        }
+        assertThrows(NoSuchElementException.class, ii::next, "iterator 
exhausted");
+        assertThrows(UnsupportedOperationException.class, ii::remove, "remove 
not implemented");
     }
 
     @Test public void testMisc() {
@@ -193,12 +173,7 @@ public class RangeTest extends JexlTestCase {
             lc0 -= 1;
         }
         assertEquals(9L, lc0);
-        try {
-            il0.next();
-            fail();
-        } catch (final NoSuchElementException xns) {
-            // ok
-        }
+        assertThrows(NoSuchElementException.class, il0::next);
 
         int ic0 = 20;
         final Iterator<Integer> ii0 = ir0.iterator();
@@ -220,12 +195,7 @@ public class RangeTest extends JexlTestCase {
             ic0 -= 1;
         }
         assertEquals(9, ic0);
-        try {
-            ii0.next();
-            fail();
-        } catch (final NoSuchElementException xns) {
-            // ok
-        }
+        assertThrows(NoSuchElementException.class, ii0::next);
     }
 
     @Test

Reply via email to