1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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 }