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    *      https://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;
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.assertTrue;
22  
23  import java.nio.charset.Charset;
24  import java.nio.charset.StandardCharsets;
25  
26  import org.apache.commons.jexl3.internal.introspection.SandboxUberspect;
27  import org.apache.commons.jexl3.introspection.JexlSandbox;
28  import org.apache.commons.jexl3.introspection.JexlUberspect;
29  import org.junit.jupiter.api.Test;
30  
31  /**
32   * Checking the builder basics.
33   */
34  class BuilderTest {
35      private static JexlBuilder builder() {
36          return new JexlBuilder();
37      }
38  
39      @Test
40      void testFlags() {
41          assertTrue(builder().antish(true).antish());
42          assertFalse(builder().antish(false).antish());
43          assertTrue(builder().cancellable(true).cancellable());
44          assertFalse(builder().cancellable(false).cancellable());
45          assertTrue(builder().safe(true).safe());
46          assertFalse(builder().safe(false).safe());
47          assertTrue(builder().silent(true).silent());
48          assertFalse(builder().silent(false).silent());
49          assertTrue(builder().lexical(true).lexical());
50          assertFalse(builder().lexical(false).lexical());
51          assertTrue(builder().lexicalShade(true).lexicalShade());
52          assertFalse(builder().lexicalShade(false).lexicalShade());
53          assertTrue(builder().silent(true).silent());
54          assertFalse(builder().silent(false).silent());
55          assertTrue(builder().strict(true).strict());
56          assertFalse(builder().strict(false).strict());
57          assertTrue(builder().booleanLogical(true).options().isBooleanLogical());
58          assertFalse(builder().booleanLogical(false).options().isBooleanLogical());
59          assertTrue(builder().strictInterpolation(true).options().isStrictInterpolation());
60          assertFalse(builder().strictInterpolation(false).options().isStrictInterpolation());
61      }
62  
63      @Test
64      void testOther() {
65          final ClassLoader cls = getClass().getClassLoader().getParent();
66          assertEquals(cls, builder().loader(cls).loader());
67          final Charset cs = StandardCharsets.UTF_16;
68          assertEquals(cs, builder().charset(cs).charset());
69          assertEquals(cs, builder().loader(cs).charset());
70          final JexlUberspect u0 = builder().create().getUberspect();
71          final JexlSandbox sandbox = new JexlSandbox();
72          final JexlUberspect uberspect = new SandboxUberspect(u0, sandbox);
73          assertEquals(sandbox, builder().sandbox(sandbox).sandbox());
74          assertEquals(uberspect, builder().uberspect(uberspect).uberspect());
75      }
76  
77      @Test
78      void testValues() {
79          assertEquals(1, builder().collectMode(1).collectMode());
80          assertEquals(0, builder().collectMode(0).collectMode());
81          assertEquals(32, builder().cacheThreshold(32).cacheThreshold());
82          assertEquals(8, builder().stackOverflow(8).stackOverflow());
83      }
84  }