Skip to content

Commit

Permalink
Use Assertions.assertInstanceOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 1, 2024
1 parent aecb393 commit f31249b
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -397,15 +397,15 @@ public void testInterval() throws Exception {

script = jexl.createScript("1 .. 3");
result = script.execute(null);
assertTrue(result instanceof Iterable<?>);
assertInstanceOf(Iterable.class, result);
Iterator<Integer> ii = ((Iterable<Integer>) result).iterator();
assertEquals(Integer.valueOf(1), ii.next());
assertEquals(Integer.valueOf(2), ii.next());
assertEquals(Integer.valueOf(3), ii.next());

script = jexl.createScript("(4 - 3) .. (9 / 3)");
result = script.execute(null);
assertTrue(result instanceof Iterable<?>);
assertInstanceOf(Iterable.class, result);
ii = ((Iterable<Integer>) result).iterator();
assertEquals(Integer.valueOf(1), ii.next());
assertEquals(Integer.valueOf(2), ii.next());
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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("[ ... , ]"));
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/jexl3/ArrayTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
11 changes: 6 additions & 5 deletions src/test/java/org/apache/commons/jexl3/Issues100Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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));
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/jexl3/Issues200Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/org/apache/commons/jexl3/Issues300Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -1191,15 +1192,15 @@ 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"));
assertEquals(2, map.get("y"));

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"));
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/apache/commons/jexl3/Issues400Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/jexl3/JXLTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object,Object> map = Collections.singletonMap("42", S42);

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/apache/commons/jexl3/JexlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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");
}

Expand Down
15 changes: 8 additions & 7 deletions src/test/java/org/apache/commons/jexl3/LambdaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/jexl3/LexicalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/apache/commons/jexl3/MapLiteralTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/jexl3/PragmaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -219,7 +220,7 @@ public void testImportPragmaValueSet() {
final JexlScript script = JEXL.createScript(src);
final Map<String, Object> pragmas = script.getPragmas();
final Object importz = pragmas.get("jexl.import");
assertTrue(importz instanceof Set<?>);
assertInstanceOf(Set.class, importz);
final Set<String> importzz = (Set<String>) importz;
assertTrue(importzz.contains("java.util"));
assertTrue(importzz.contains("java.io"));
Expand Down
Loading

0 comments on commit f31249b

Please sign in to comment.