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;
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  public class BuilderTest {
35      private static JexlBuilder builder() {
36          return new JexlBuilder();
37      }
38  
39      @Test
40      public 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      }
58  
59      @Test
60      public void testOther() {
61          final ClassLoader cls = getClass().getClassLoader().getParent();
62          assertEquals(cls, builder().loader(cls).loader());
63          final Charset cs = StandardCharsets.UTF_16;
64          assertEquals(cs, builder().charset(cs).charset());
65          assertEquals(cs, builder().loader(cs).charset());
66          final JexlUberspect u0 = builder().create().getUberspect();
67          final JexlSandbox sandbox = new JexlSandbox();
68          final JexlUberspect uberspect = new SandboxUberspect(u0, sandbox);
69          assertEquals(sandbox, builder().sandbox(sandbox).sandbox());
70          assertEquals(uberspect, builder().uberspect(uberspect).uberspect());
71      }
72  
73      @Test
74      public void testValues() {
75          assertEquals(1, builder().collectMode(1).collectMode());
76          assertEquals(0, builder().collectMode(0).collectMode());
77          assertEquals(32, builder().cacheThreshold(32).cacheThreshold());
78          assertEquals(8, builder().stackOverflow(8).stackOverflow());
79      }
80  }