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 bb2d295cba55ec7960e54adc74d8252a6542701a Author: Gary Gregory <[email protected]> AuthorDate: Sat Jun 1 11:01:00 2024 -0400 Use assertThrows() --- .../introspection/MiscIntrospectionTest.java | 51 +++++----------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/src/test/java/org/apache/commons/jexl3/internal/introspection/MiscIntrospectionTest.java b/src/test/java/org/apache/commons/jexl3/internal/introspection/MiscIntrospectionTest.java index fc62035f..d0742ea1 100644 --- a/src/test/java/org/apache/commons/jexl3/internal/introspection/MiscIntrospectionTest.java +++ b/src/test/java/org/apache/commons/jexl3/internal/introspection/MiscIntrospectionTest.java @@ -18,9 +18,8 @@ package org.apache.commons.jexl3.internal.introspection; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -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; import java.util.ArrayList; import java.util.NoSuchElementException; @@ -36,49 +35,26 @@ public class MiscIntrospectionTest { @Test public void testArrayIterator() { // not on lists - try { - new ArrayIterator(new ArrayList<>()); - } catch (final IllegalArgumentException xill) { - assertNotNull(xill); - } + assertThrows(IllegalArgumentException.class, () -> new ArrayIterator(new ArrayList<>())); // wih null ? ArrayIterator ai0 = new ArrayIterator(null); assertFalse(ai0.hasNext()); - try { - ai0.next(); - fail("should have failed"); - } catch (final NoSuchElementException no) { - assertNotNull(no); - } + assertThrows(NoSuchElementException.class, ai0::next); // an array - ai0 = new ArrayIterator(new int[]{42}); + ai0 = new ArrayIterator(new int[] { 42 }); assertTrue(ai0.hasNext()); assertEquals(42, ai0.next()); assertFalse(ai0.hasNext()); - try { - ai0.next(); - fail("iterator on null ?"); - } catch (final NoSuchElementException no) { - assertNotNull(no); - } + assertThrows(NoSuchElementException.class, ai0::next); // no remove - try { - ai0.remove(); - fail("should have failed"); - } catch (final UnsupportedOperationException no) { - assertNotNull(no); - } + assertThrows(UnsupportedOperationException.class, ai0::remove); } + @Test public void testArrayListWrapper() { - ArrayListWrapper alw ; - try { - new ArrayListWrapper(1); - fail("non-array wrap?"); - } catch (final IllegalArgumentException xil) { - assertNotNull(xil); - } - final Integer[] ai = {1, 2}; + ArrayListWrapper alw; + assertThrows(IllegalArgumentException.class, () -> new ArrayListWrapper(1)); + final Integer[] ai = { 1, 2 }; alw = new ArrayListWrapper(ai); assertEquals(1, alw.indexOf(2)); assertEquals(-1, alw.indexOf(null)); @@ -86,12 +62,7 @@ public class MiscIntrospectionTest { @Test public void testEmptyContext() { - try { - JexlEngine.EMPTY_CONTEXT.set("nope", 42); - fail("empty context should be readonly"); - } catch (final UnsupportedOperationException xun) { - assertNotNull(xun); - } + assertThrows(UnsupportedOperationException.class, () -> JexlEngine.EMPTY_CONTEXT.set("nope", 42)); } }
