From f31249bde39263622c0022880a9e1b57dc8ca237 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 1 Sep 2024 19:00:22 -0400 Subject: [PATCH] Use Assertions.assertInstanceOf() --- .../commons/jexl3/ArithmeticOperatorTest.java | 6 +++--- .../apache/commons/jexl3/ArrayLiteralTest.java | 5 +++-- .../apache/commons/jexl3/ArrayTypeTest.java | 3 ++- .../apache/commons/jexl3/Issues100Test.java | 11 ++++++----- .../apache/commons/jexl3/Issues200Test.java | 3 ++- .../apache/commons/jexl3/Issues300Test.java | 15 ++++++++------- .../apache/commons/jexl3/Issues400Test.java | 5 +++-- .../org/apache/commons/jexl3/JXLTTest.java | 3 ++- .../org/apache/commons/jexl3/JexlTest.java | 5 +++-- .../org/apache/commons/jexl3/LambdaTest.java | 15 ++++++++------- .../org/apache/commons/jexl3/LexicalTest.java | 3 ++- .../apache/commons/jexl3/MapLiteralTest.java | 4 ++-- .../org/apache/commons/jexl3/PragmaTest.java | 3 ++- .../org/apache/commons/jexl3/RangeTest.java | 8 ++++---- .../apache/commons/jexl3/SideEffectTest.java | 12 ++++++------ .../commons/jexl3/TryCatchFinallyTest.java | 4 +++- .../commons/jexl3/examples/StreamTest.java | 7 ++++--- .../internal/introspection/DiscoveryTest.java | 18 +++++++++--------- .../JexlScriptEngineOptionalTest.java | 4 ++-- .../jexl3/scripting/JexlScriptEngineTest.java | 3 ++- 20 files changed, 76 insertions(+), 61 deletions(-) diff --git a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java index ecaf7e302..61f045fe4 100644 --- a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java +++ b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java @@ -18,8 +18,8 @@ package org.apache.commons.jexl3; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.io.StringWriter; @@ -397,7 +397,7 @@ public void testInterval() throws Exception { script = jexl.createScript("1 .. 3"); result = script.execute(null); - assertTrue(result instanceof Iterable); + assertInstanceOf(Iterable.class, result); Iterator ii = ((Iterable) result).iterator(); assertEquals(Integer.valueOf(1), ii.next()); assertEquals(Integer.valueOf(2), ii.next()); @@ -405,7 +405,7 @@ public void testInterval() throws Exception { script = jexl.createScript("(4 - 3) .. (9 / 3)"); result = script.execute(null); - assertTrue(result instanceof Iterable); + assertInstanceOf(Iterable.class, result); ii = ((Iterable) result).iterator(); assertEquals(Integer.valueOf(1), ii.next()); assertEquals(Integer.valueOf(2), ii.next()); diff --git a/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java b/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java index f1053e4cc..d640740f3 100644 --- a/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java +++ b/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -60,10 +61,10 @@ public void testEmptyArrayLiteral() throws Exception { final JexlContext jc = new MapContext(); Object o; o = JEXL.createExpression("[]").evaluate(jc); - assertTrue(o instanceof Object[]); + assertInstanceOf(Object[].class, o); assertEquals(0, ((Object[]) o).length); o = JEXL.createExpression("[...]").evaluate(jc); - assertTrue(o instanceof List); + assertInstanceOf(List.class, o); assertEquals(0, ((List) o).size()); assertThrows(JexlException.Parsing.class, () -> JEXL.createExpression("[ , ]")); assertThrows(JexlException.Parsing.class, () -> JEXL.createExpression("[ ... , ]")); diff --git a/src/test/java/org/apache/commons/jexl3/ArrayTypeTest.java b/src/test/java/org/apache/commons/jexl3/ArrayTypeTest.java index f339f4c9a..08bb83936 100644 --- a/src/test/java/org/apache/commons/jexl3/ArrayTypeTest.java +++ b/src/test/java/org/apache/commons/jexl3/ArrayTypeTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.Serializable; @@ -149,6 +150,6 @@ public void testArrayTypes() { script = jexl.createScript("[ a, b, c, d, ... ]", "a", "b", "c", "d"); // intersect a, b, c, c -> classA result = script.execute(null, a, b, c, c); - assertTrue(result instanceof List); + assertInstanceOf(List.class, result); } } diff --git a/src/test/java/org/apache/commons/jexl3/Issues100Test.java b/src/test/java/org/apache/commons/jexl3/Issues100Test.java index a85d9530a..de504244b 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues100Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues100Test.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -317,10 +318,10 @@ public void test108() throws Exception { expr = jexl.createScript("if (false) { [] } else { {:} }"); value = expr.execute(null); - assertTrue(value instanceof Map); + assertInstanceOf(Map.class, value); expr = jexl.createScript(expr.getParsedText()); value = expr.execute(null); - assertTrue(value instanceof Map); + assertInstanceOf(Map.class, value); } @Test @@ -647,13 +648,13 @@ public void test148a() throws Exception { String src = "u.asList(['foo', 'bar'])"; JexlScript e = jexl.createScript(src); Object o = e.execute(jc); - assertTrue(o instanceof List); + assertInstanceOf(List.class, o); assertEquals(Arrays.asList("foo", "bar"), o); src = "u.asList([1, 2])"; e = jexl.createScript(src); o = e.execute(jc); - assertTrue(o instanceof List); + assertInstanceOf(List.class, o); assertEquals(Arrays.asList(1, 2), o); } @@ -675,7 +676,7 @@ public void test179() throws Exception { final String src = "x = new ('java.util.HashSet'); x.add(1); x"; final JexlScript e = jexl.createScript(src); final Object o = e.execute(jc); - assertTrue(o instanceof Set); + assertInstanceOf(Set.class, o); assertTrue(((Set) o).contains(1)); } diff --git a/src/test/java/org/apache/commons/jexl3/Issues200Test.java b/src/test/java/org/apache/commons/jexl3/Issues200Test.java index a02c3c5ae..a0c2182db 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues200Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues200Test.java @@ -17,6 +17,7 @@ package org.apache.commons.jexl3; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -569,7 +570,7 @@ public void test267() throws Exception { // explicitly returning the lambda script = jexl.createScript("return (x, y)->{ x + y}"); result = script.execute(ctxt); - assertTrue(result instanceof JexlScript); + assertInstanceOf(JexlScript.class, result); } @Test diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java index 4019324f1..2d4f9aad9 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java @@ -20,6 +20,7 @@ import static org.apache.commons.jexl3.introspection.JexlPermissions.RESTRICTED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -569,7 +570,7 @@ public void test317() { "x"); // @formatter:on result = script.execute(ctxt, 21); - assertTrue(result instanceof JexlScript); + assertInstanceOf(JexlScript.class, result); script = (JexlScript) result; info = JexlInfo.from(script); assertNotNull(info); @@ -922,7 +923,7 @@ public void test379a() { assertNotNull(script); final Object result = script.execute(null); assertNotNull(result); - assertTrue(result instanceof LinkedHashMap); + assertInstanceOf(LinkedHashMap.class, result); assertEquals(1, ((Map) result).size()); } @@ -1118,11 +1119,11 @@ public void testDow() { final JexlEngine jexl = new JexlBuilder().create(); final JexlScript script = jexl.createScript(src); Object r = script.execute(null, 2023, 3, 1); - assertTrue(r instanceof Number); + assertInstanceOf(Number.class, r); Number dow = (Number) r; assertEquals(3, dow.intValue()); r = script.execute(null, 1969, 7, 20); - assertTrue(r instanceof Number); + assertInstanceOf(Number.class, r); dow = (Number) r; assertEquals(0, dow.intValue()); } @@ -1170,7 +1171,7 @@ public void testIssue398a() { final JexlEngine jexl = new JexlBuilder().create(); final JexlScript script = jexl.createScript(src); final Object result = script.execute(null); - assertTrue(result instanceof Map); + assertInstanceOf(Map.class, result); final Map map = (Map) result; assertEquals(2, map.size()); } @@ -1191,7 +1192,7 @@ public void testIssue398b() { final JexlEngine jexl = new JexlBuilder().create(); JexlScript script = jexl.createScript(src); Object result = script.execute(ctxt); - assertTrue(result instanceof Map); + assertInstanceOf(Map.class, result); Map map = (Map) result; assertEquals(2, map.size()); assertEquals(1, map.get("x")); @@ -1199,7 +1200,7 @@ public void testIssue398b() { script = jexl.createScript(src, "foo", "bar"); result = script.execute(null, foo, bar); - assertTrue(result instanceof Map); + assertInstanceOf(Map.class, result); map = (Map) result; assertEquals(2, map.size()); assertEquals(1, map.get("x")); diff --git a/src/test/java/org/apache/commons/jexl3/Issues400Test.java b/src/test/java/org/apache/commons/jexl3/Issues400Test.java index df1417533..1c3e2670f 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues400Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues400Test.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -140,7 +141,7 @@ void test403() { final JexlScript script = jexl.createScript(src); for (int i = 0; i < 2; ++i) { final Object result = script.execute(null); - assertTrue(result instanceof Map); + assertInstanceOf(Map.class, result); final Map map = (Map) result; assertEquals(1, map.size()); Object val = jexl.createScript("m -> m[1]").execute(null, map); @@ -285,7 +286,7 @@ void test412() { final JexlEngine jexl = new JexlBuilder().create(); final JexlScript e = jexl.createScript(fnsrc); final Object o = e.execute(jc); - assertTrue(o instanceof Map); + assertInstanceOf(Map.class, o); final Map map = (Map) o; assertEquals(map, ctl); } diff --git a/src/test/java/org/apache/commons/jexl3/JXLTTest.java b/src/test/java/org/apache/commons/jexl3/JXLTTest.java index 39937ee6c..148c1e268 100644 --- a/src/test/java/org/apache/commons/jexl3/JXLTTest.java +++ b/src/test/java/org/apache/commons/jexl3/JXLTTest.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; @@ -528,7 +529,7 @@ public Object propertySet(Map list, String property, Object value) { Object result; script = jexl.createScript("let x = 42; let y = `${x}`; y"); result = script.execute(null); - assertTrue(result instanceof String); + assertInstanceOf(String.class, result); assertEquals("42", result); Map map = Collections.singletonMap("42", S42); diff --git a/src/test/java/org/apache/commons/jexl3/JexlTest.java b/src/test/java/org/apache/commons/jexl3/JexlTest.java index 129c9be62..33d3e501b 100644 --- a/src/test/java/org/apache/commons/jexl3/JexlTest.java +++ b/src/test/java/org/apache/commons/jexl3/JexlTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -599,7 +600,7 @@ public void testNewImports() throws Exception { Object result; expr = jexl.createExpression("new LinkedList([1,2,3,...])"); result = expr.evaluate(null); - assertTrue(result instanceof LinkedList); + assertInstanceOf(LinkedList.class, result); } /** @@ -683,7 +684,7 @@ public void testProperty() throws Exception { jc.set("foo", new Foo()); final Object o = e.evaluate(jc); - assertTrue(o instanceof String, "o not instanceof String"); + assertInstanceOf(String.class, o, "o not instanceof String"); assertEquals(GET_METHOD_STRING, o, "o incorrect"); } diff --git a/src/test/java/org/apache/commons/jexl3/LambdaTest.java b/src/test/java/org/apache/commons/jexl3/LambdaTest.java index ae2051800..184c2b6e1 100644 --- a/src/test/java/org/apache/commons/jexl3/LambdaTest.java +++ b/src/test/java/org/apache/commons/jexl3/LambdaTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -281,7 +282,7 @@ public void testHoistLambda() { strs = "(x)->{ (y)->{ x + y } }"; s42 = jexl.createScript(strs); result = s42.execute(ctx, 15); - assertTrue(result instanceof JexlScript); + assertInstanceOf(JexlScript.class, result); s15 = (JexlScript) result; localv = s15.getLocalVariables(); assertEquals(0, localv.length); @@ -294,7 +295,7 @@ public void testHoistLambda() { strs = "(x)->{ (y)->{ var z = 169; var x; x + y } }"; s42 = jexl.createScript(strs); result = s42.execute(ctx, 15); - assertTrue(result instanceof JexlScript); + assertInstanceOf(JexlScript.class, result); s15 = (JexlScript) result; localv = s15.getLocalVariables(); assertNotNull(localv); @@ -381,7 +382,7 @@ public void testLambdaClosure() { final JexlEngine jexl = createEngine(); final JexlScript script = jexl.createScript(src); final Object result = script.execute(null, 21); - assertTrue(result instanceof Set); + assertInstanceOf(Set.class, result); final Set set = (Set) result; assertEquals(1, set.size()); assertTrue(set.contains(42)); @@ -392,7 +393,7 @@ public void testLambdaClosure() { final JexlEngine jexl = createEngine(); final JexlScript script = jexl.createScript(src); final Object result = script.execute(null, 21); - assertTrue(result instanceof Set); + assertInstanceOf(Set.class, result); final Set set = (Set) result; assertEquals(1, set.size()); assertTrue(set.contains(42)); @@ -443,7 +444,7 @@ public void testNestLambada() throws Exception { assertEquals(s42.hashCode(), s42b.hashCode()); assertEquals(s42, s42b); Object result = s42.execute(null, 15); - assertTrue(result instanceof JexlScript); + assertInstanceOf(JexlScript.class, result); final Object resultb = s42.execute(null, 15); assertEquals(result.hashCode(), resultb.hashCode()); assertEquals(result, resultb); @@ -597,7 +598,7 @@ public void testScriptContext() { Object result; script = jexl.createScript(src); result = script.execute(null); - assertTrue(result instanceof JexlScript); + assertInstanceOf(JexlScript.class, result); script = jexl.createScript("f()", "f"); result = script.execute(null, result); assertEquals(42, result); @@ -612,7 +613,7 @@ public void testScriptContext() { Object result; script = jexl.createScript(src); result = script.execute(null); - assertTrue(result instanceof JexlScript); + assertInstanceOf(JexlScript.class, result); script = jexl.createScript("f()", "f"); result = script.execute(null, result); assertEquals(142, result); diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java b/src/test/java/org/apache/commons/jexl3/LexicalTest.java index f541a760b..2c95ac9a2 100644 --- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java +++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java @@ -19,6 +19,7 @@ import static org.apache.commons.jexl3.JexlTestCase.createEngine; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -515,7 +516,7 @@ void testContextualOptions1() { // run it a second time, new 3.2 semantics, lexical/shade = true result = runner.execute(ctxt, true, tested, catchFn); // result is exception! - assertTrue(result instanceof JexlException.Variable); + assertInstanceOf(JexlException.Variable.class, result); } @Test diff --git a/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java b/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java index aba1e03fb..d795998cd 100644 --- a/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java +++ b/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java @@ -18,9 +18,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; 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 java.util.Arrays; import java.util.Collections; @@ -176,7 +176,7 @@ public void testSizeOfSimpleMapLiteral() throws Exception { public void testVariableMap() throws Exception { final JexlScript script = JEXL.createScript("{ ['1', '2'.toString()] : someValue }", "someValue"); final Object result = script.execute(null, 42); - assertTrue(result instanceof Map); + assertInstanceOf(Map.class, result); Object key = null; Object value = null; for(final Map.Entry e : ((Map) result).entrySet()) { diff --git a/src/test/java/org/apache/commons/jexl3/PragmaTest.java b/src/test/java/org/apache/commons/jexl3/PragmaTest.java index 3ea85ee67..902b2f154 100644 --- a/src/test/java/org/apache/commons/jexl3/PragmaTest.java +++ b/src/test/java/org/apache/commons/jexl3/PragmaTest.java @@ -17,6 +17,7 @@ package org.apache.commons.jexl3; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -219,7 +220,7 @@ public void testImportPragmaValueSet() { final JexlScript script = JEXL.createScript(src); final Map pragmas = script.getPragmas(); final Object importz = pragmas.get("jexl.import"); - assertTrue(importz instanceof Set); + assertInstanceOf(Set.class, importz); final Set importzz = (Set) importz; assertTrue(importzz.contains("java.util")); assertTrue(importzz.contains("java.io")); diff --git a/src/test/java/org/apache/commons/jexl3/RangeTest.java b/src/test/java/org/apache/commons/jexl3/RangeTest.java index 491752388..adeafad0b 100644 --- a/src/test/java/org/apache/commons/jexl3/RangeTest.java +++ b/src/test/java/org/apache/commons/jexl3/RangeTest.java @@ -18,8 +18,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collection; @@ -55,7 +55,7 @@ public void testIntegerRange() throws Exception { final Object o0 = e.evaluate(jc); final Object o = e.evaluate(jc); - assertTrue(o instanceof Collection); + assertInstanceOf(Collection.class, o); final Collection c = (Collection) o; assertEquals(32, c.size()); @@ -101,7 +101,7 @@ public void testIntegerRangeOne() throws Exception { final JexlContext jc = new MapContext(); final Object o = e.evaluate(jc); - assertTrue(o instanceof Collection); + assertInstanceOf(Collection.class, o); final Collection c = (Collection) o; assertEquals(1, c.size()); final Object[] a = c.toArray(); @@ -139,7 +139,7 @@ public void testLongRange() throws Exception { final Object o0 = e.evaluate(jc); final Object o = e.evaluate(jc); - assertTrue(o instanceof Collection); + assertInstanceOf(Collection.class, o); final Collection c = (Collection) o; assertEquals(32, c.size()); assertFalse((Boolean) JEXL.createScript("empty x", "x").execute(null, e)); diff --git a/src/test/java/org/apache/commons/jexl3/SideEffectTest.java b/src/test/java/org/apache/commons/jexl3/SideEffectTest.java index e495a88f0..570ed4a51 100644 --- a/src/test/java/org/apache/commons/jexl3/SideEffectTest.java +++ b/src/test/java/org/apache/commons/jexl3/SideEffectTest.java @@ -17,9 +17,9 @@ package org.apache.commons.jexl3; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -299,7 +299,7 @@ private void run246(final JexlArithmetic j246) throws Exception { try { script.execute(ctx, "42"); zz = ctx.get("z"); - assertTrue(zz instanceof List); + assertInstanceOf(List.class, zz); z = (List) zz; assertEquals(1, z.size()); } catch (JexlException | ArithmeticException xjexl) { @@ -321,7 +321,7 @@ protected void runSelfIncrement(final JexlEngine jexl, final JexlContext jc) { final AtomicInteger i11 = new AtomicInteger(3115); for(final Object v : Arrays.asList(v11, i11)) { final Object result = script.execute(jc, v); - assertTrue(result instanceof int[]); + assertInstanceOf(int[].class, result); final int[] r = (int[]) result; assertEquals(3115, r[0]); assertEquals(3115, r[1]); @@ -333,7 +333,7 @@ protected void runSelfIncrement(final JexlEngine jexl, final JexlContext jc) { final AtomicInteger i12 = new AtomicInteger(3189); for(final Object v : Arrays.asList(v12, i12)) { final Object result = script.execute(jc, v); - assertTrue(result instanceof int[]); + assertInstanceOf(int[].class, result); final int[] r = (int[]) result; assertEquals(3189, r[0]); assertEquals(3190, r[1]); @@ -344,7 +344,7 @@ protected void runSelfIncrement(final JexlEngine jexl, final JexlContext jc) { final Var v13 = new Var(3115); for(final Object v : Arrays.asList(v13)) { final Object result = script.execute(jc, v13); - assertTrue(result instanceof int[]); + assertInstanceOf(int[].class, result); final int[] r = (int[]) result; assertEquals(3115, r[0]); assertEquals(3115, r[1]); @@ -355,7 +355,7 @@ protected void runSelfIncrement(final JexlEngine jexl, final JexlContext jc) { final Var v14 = new Var(3189); for(final Object v : Arrays.asList(v14)) { final Object result = script.execute(jc, v); - assertTrue(result instanceof int[]); + assertInstanceOf(int[].class, result); final int[] r = (int[]) result; assertEquals(3189, r[0]); assertEquals(3188, r[1]); diff --git a/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java b/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java index 79a49ba4a..adadedae0 100644 --- a/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java +++ b/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java @@ -18,11 +18,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; 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 java.io.IOException; +import java.io.UnsupportedEncodingException; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -95,7 +97,7 @@ public void testExceptionType() throws Exception { final JexlScript e = JEXL.createScript("try { 'asb'.getBytes('NoSuchCharacterSet'); } catch (let ex) { ex }"); final JexlContext jc = new MapContext(); final Object o = e.execute(jc); - assertTrue(o instanceof java.io.UnsupportedEncodingException); + assertInstanceOf(UnsupportedEncodingException.class, o); } @Test diff --git a/src/test/java/org/apache/commons/jexl3/examples/StreamTest.java b/src/test/java/org/apache/commons/jexl3/examples/StreamTest.java index 8d83962b8..f189cd3b3 100644 --- a/src/test/java/org/apache/commons/jexl3/examples/StreamTest.java +++ b/src/test/java/org/apache/commons/jexl3/examples/StreamTest.java @@ -18,6 +18,7 @@ import static java.lang.Boolean.TRUE; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.URI; @@ -134,7 +135,7 @@ public void testURICollection() { "list.filter(uri -> uri.scheme =^ 'http')", "list"); final Object filtered = filter.execute(sctxt, uris); - assertTrue(filtered instanceof List); + assertInstanceOf(List.class, filtered); List result = (List) filtered; assertEquals(2, result.size()); for(final URI uri : result) { @@ -146,7 +147,7 @@ public void testURICollection() { "list.map(uri -> uri.scheme =^ 'http'? URI:create(`https://${uri.host}`) : null)", "list"); final Object transformed = mapper.execute(sctxt, uris); - assertTrue(transformed instanceof List); + assertInstanceOf(List.class, transformed); result = (List) transformed; assertEquals(2, result.size()); for(final URI uri : result) { @@ -186,7 +187,7 @@ public void testURIStream() { sctxt.set("mapper", mapper); final Object transformed = transform.execute(sctxt, uris); - assertTrue(transformed instanceof List); + assertInstanceOf(List.class, transformed); assertEquals(control, transformed); } } diff --git a/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java b/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java index 00b637297..6b3f6f87e 100644 --- a/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java +++ b/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java @@ -17,9 +17,9 @@ package org.apache.commons.jexl3.internal.introspection; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.Serializable; import java.util.ArrayList; @@ -149,8 +149,8 @@ public void testBeanIntrospection() throws Exception { final JexlPropertyGet get = uber.getPropertyGet(bean, "value"); final JexlPropertySet set = uber.getPropertySet(bean, "value", "foo"); - assertTrue(get instanceof PropertyGetExecutor, "bean property getter"); - assertTrue(set instanceof PropertySetExecutor, "bean property setter"); + assertInstanceOf(PropertyGetExecutor.class, get, "bean property getter"); + assertInstanceOf(PropertySetExecutor.class, set, "bean property setter"); // introspector and uberspect should return same result assertEquals(get, uber.getPropertyGet(bean, "value")); assertEquals(set, uber.getPropertySet(bean, "value", "foo")); @@ -178,8 +178,8 @@ public void testDuckIntrospection() throws Exception { final JexlPropertyGet get = uber.getPropertyGet(duck, "value"); final JexlPropertySet set = uber.getPropertySet(duck, "value", "foo"); - assertTrue(get instanceof DuckGetExecutor, "duck property getter"); - assertTrue(set instanceof DuckSetExecutor, "duck property setter"); + assertInstanceOf(DuckGetExecutor.class, get, "duck property getter"); + assertInstanceOf(DuckSetExecutor.class, set, "duck property setter"); // introspector and uberspect should return same result assertEquals(get, uber.getPropertyGet(duck, "value")); assertEquals(set, uber.getPropertySet(duck, "value", "foo")); @@ -208,8 +208,8 @@ public void testListIntrospection() throws Exception { final JexlPropertyGet get = uber.getPropertyGet(list, 1); final JexlPropertySet set = uber.getPropertySet(list, 1, "foo"); - assertTrue(get instanceof ListGetExecutor, "list property getter"); - assertTrue(set instanceof ListSetExecutor, "list property setter"); + assertInstanceOf(ListGetExecutor.class, get, "list property getter"); + assertInstanceOf(ListSetExecutor.class, set, "list property setter"); // introspector and uberspect should return same result assertEquals(get, uber.getPropertyGet(list, 1)); assertEquals(set, uber.getPropertySet(list, 1, "foo")); @@ -239,8 +239,8 @@ public void testMapIntrospection() throws Exception { final JexlPropertyGet get = uber.getPropertyGet(map, "value"); final JexlPropertySet set = uber.getPropertySet(map, "value", "foo"); - assertTrue(get instanceof MapGetExecutor, "map property getter"); - assertTrue(set instanceof MapSetExecutor, "map property setter"); + assertInstanceOf(MapGetExecutor.class, get, "map property getter"); + assertInstanceOf(MapSetExecutor.class, set, "map property setter"); // introspector and uberspect should return same result assertEquals(get, uber.getPropertyGet(map, "value")); assertEquals(set, uber.getPropertySet(map, "value", "foo")); diff --git a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java index 47a53c881..eb670cc0f 100644 --- a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java +++ b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java @@ -18,7 +18,7 @@ package org.apache.commons.jexl3.scripting; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import java.io.StringWriter; @@ -36,7 +36,7 @@ public class JexlScriptEngineOptionalTest { @Test public void testCompilable() throws Exception { - assertTrue(engine instanceof Compilable, "Engine should implement Compilable"); + assertInstanceOf(Compilable.class, engine, "Engine should implement Compilable"); final Compilable cengine = (Compilable) engine; final CompiledScript script = cengine.compile("40 + 2"); assertEquals(42, script.eval()); diff --git a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java index 41319815e..7f5f1a655 100644 --- a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java +++ b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java @@ -18,6 +18,7 @@ package org.apache.commons.jexl3.scripting; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -121,7 +122,7 @@ public void testDottedNames() throws Exception { assertNull(engine.get("this.is.a.test")); assertEquals(Boolean.TRUE, engine.eval("empty(this.is.a.test)")); final Object mymap = engine.eval("testmap={ 'key1' : 'value1', 'key2' : 'value2' }"); - assertTrue(mymap instanceof Map); + assertInstanceOf(Map.class, mymap); assertEquals(2,((Map)mymap).size()); }