View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * Checks the CacheMap.MethodKey implementation
32   */
33  
34  public class MiscIntrospectionTest {
35      @Test
36      public void testArrayIterator() {
37          // not on lists
38          assertThrows(IllegalArgumentException.class, () -> new ArrayIterator(new ArrayList<>()));
39          // wih null ?
40          ArrayIterator ai0 = new ArrayIterator(null);
41          assertFalse(ai0.hasNext());
42          assertThrows(NoSuchElementException.class, ai0::next);
43          // an array
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          // no remove
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  }