1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl3.internal.introspection;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.util.ArrayList;
25 import java.util.NoSuchElementException;
26
27 import org.apache.commons.jexl3.JexlEngine;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33
34 public class MiscIntrospectionTest {
35 @Test
36 public void testArrayIterator() {
37
38 assertThrows(IllegalArgumentException.class, () -> new ArrayIterator(new ArrayList<>()));
39
40 ArrayIterator ai0 = new ArrayIterator(null);
41 assertFalse(ai0.hasNext());
42 assertThrows(NoSuchElementException.class, ai0::next);
43
44 ai0 = new ArrayIterator(new int[] { 42 });
45 assertTrue(ai0.hasNext());
46 assertEquals(42, ai0.next());
47 assertFalse(ai0.hasNext());
48 assertThrows(NoSuchElementException.class, ai0::next);
49
50 assertThrows(UnsupportedOperationException.class, ai0::remove);
51 }
52
53 @Test
54 public void testArrayListWrapper() {
55 ArrayListWrapper alw;
56 assertThrows(IllegalArgumentException.class, () -> new ArrayListWrapper(1));
57 final Integer[] ai = { 1, 2 };
58 alw = new ArrayListWrapper(ai);
59 assertEquals(1, alw.indexOf(2));
60 assertEquals(-1, alw.indexOf(null));
61 }
62
63 @Test
64 public void testEmptyContext() {
65 assertThrows(UnsupportedOperationException.class, () -> JexlEngine.EMPTY_CONTEXT.set("nope", 42));
66 }
67
68 }