1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration2.builder;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertSame;
21 import static org.mockito.Mockito.mock;
22
23 import java.util.Map;
24
25 import javax.naming.Context;
26
27 import org.apache.commons.configuration2.beanutils.BeanHelper;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34 public class TestJndiBuilderParametersImpl {
35
36
37 private JndiBuilderParametersImpl params;
38
39 @BeforeEach
40 public void setUp() throws Exception {
41 params = new JndiBuilderParametersImpl();
42 }
43
44
45
46
47 @Test
48 void testGetParametersBaseProperties() {
49 params.setPrefix("somePrefix");
50 params.setThrowExceptionOnMissing(true);
51 final Map<String, Object> paramsMap = params.getParameters();
52 assertEquals(Boolean.TRUE, paramsMap.get("throwExceptionOnMissing"));
53 }
54
55
56
57
58 @Test
59 void testSetBeanProperties() throws Exception {
60 final Context ctx = mock(Context.class);
61 final String prefix = "testJndiPrefix";
62 BeanHelper.setProperty(params, "context", ctx);
63 BeanHelper.setProperty(params, "prefix", prefix);
64 final Map<String, Object> paramsMap = params.getParameters();
65 assertSame(ctx, paramsMap.get("context"));
66 assertEquals(prefix, paramsMap.get("prefix"));
67 }
68
69
70
71
72 @Test
73 void testSetContext() {
74 final Context ctx = mock(Context.class);
75 assertSame(params, params.setContext(ctx));
76 final Map<String, Object> paramsMap = params.getParameters();
77 assertSame(ctx, paramsMap.get("context"));
78 }
79
80
81
82
83 @Test
84 void testSetPrefix() {
85 final String prefix = "testJndiPrefix";
86 assertSame(params, params.setPrefix(prefix));
87 final Map<String, Object> paramsMap = params.getParameters();
88 assertEquals(prefix, paramsMap.get("prefix"));
89 }
90 }