1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.text.matcher;
19
20 import static org.junit.jupiter.api.Assertions.assertNull;
21 import static org.junit.jupiter.api.Assertions.assertSame;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import org.apache.commons.text.StringSubstitutor;
26 import org.junit.jupiter.api.Test;
27
28
29
30
31 class StringSubstitutorGetSetTest {
32
33
34
35
36 @Test
37 void testGetSetPrefix() {
38 final StringSubstitutor sub = new StringSubstitutor();
39 assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
40 sub.setVariablePrefix('<');
41 assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharMatcher);
42
43 sub.setVariablePrefix("<<");
44 assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
45 assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefix((String) null));
46 assertTrue(sub.getVariablePrefixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
47
48 final StringMatcher matcher = StringMatcherFactory.INSTANCE.commaMatcher();
49 sub.setVariablePrefixMatcher(matcher);
50 assertSame(matcher, sub.getVariablePrefixMatcher());
51 assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefixMatcher((StringMatcher) null));
52 assertSame(matcher, sub.getVariablePrefixMatcher());
53 }
54
55
56
57
58 @Test
59 void testGetSetSuffix() {
60 final StringSubstitutor sub = new StringSubstitutor();
61 assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharMatcher);
62 sub.setVariableSuffix('<');
63 assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharMatcher);
64
65 sub.setVariableSuffix("<<");
66 assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
67 assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffix((String) null));
68 assertTrue(sub.getVariableSuffixMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
69
70 final StringMatcher matcher = StringMatcherFactory.INSTANCE.commaMatcher();
71 sub.setVariableSuffixMatcher(matcher);
72 assertSame(matcher, sub.getVariableSuffixMatcher());
73 assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffixMatcher((StringMatcher) null));
74 assertSame(matcher, sub.getVariableSuffixMatcher());
75 }
76
77
78
79
80 @Test
81 void testGetSetValueDelimiter() {
82 final StringSubstitutor sub = new StringSubstitutor();
83 assertTrue(sub.getValueDelimiterMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
84 sub.setValueDelimiter(':');
85 assertTrue(sub.getValueDelimiterMatcher() instanceof AbstractStringMatcher.CharMatcher);
86
87 sub.setValueDelimiter("||");
88 assertTrue(sub.getValueDelimiterMatcher() instanceof AbstractStringMatcher.CharArrayMatcher);
89 sub.setValueDelimiter((String) null);
90 assertNull(sub.getValueDelimiterMatcher());
91
92 final StringMatcher matcher = StringMatcherFactory.INSTANCE.commaMatcher();
93 sub.setValueDelimiterMatcher(matcher);
94 assertSame(matcher, sub.getValueDelimiterMatcher());
95 sub.setValueDelimiterMatcher((StringMatcher) null);
96 assertNull(sub.getValueDelimiterMatcher());
97 }
98
99 }