|
16 | 16 | */ |
17 | 17 | package org.apache.commons.text.lookup; |
18 | 18 |
|
| 19 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 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 | + |
19 | 25 | import java.util.HashMap; |
20 | 26 | import java.util.HashSet; |
| 27 | +import java.util.Locale; |
21 | 28 | import java.util.Map; |
22 | 29 | import java.util.Properties; |
23 | 30 | import java.util.Set; |
24 | 31 |
|
25 | 32 | import javax.xml.XMLConstants; |
26 | 33 |
|
27 | | -import org.junit.jupiter.api.Assertions; |
28 | 34 | import org.junit.jupiter.api.Test; |
29 | 35 |
|
30 | 36 | /** |
@@ -60,12 +66,12 @@ private static void assertMappedLookups(final Map<String, StringLookup> lookupMa |
60 | 66 |
|
61 | 67 | for (final String key : keys) { |
62 | 68 | final String normalizedKey = StringLookupFactory.toKey(key); |
63 | | - Assertions.assertNotNull(normalizedKey, () -> "Expected map to contain string lookup for key " + key); |
| 69 | + assertNotNull(normalizedKey, () -> "Expected map to contain string lookup for key " + key); |
64 | 70 |
|
65 | 71 | remainingKeys.remove(normalizedKey); |
66 | 72 | } |
67 | 73 |
|
68 | | - Assertions.assertTrue(remainingKeys.isEmpty(), () -> "Unexpected keys in lookup map: " + remainingKeys); |
| 74 | + assertTrue(remainingKeys.isEmpty(), () -> "Unexpected keys in lookup map: " + remainingKeys); |
69 | 75 | } |
70 | 76 |
|
71 | 77 | private static void checkDefaultStringLookupsHolder(final Properties props, final String... keys) { |
@@ -157,9 +163,9 @@ public void testDefaultStringLookupsHolder_invalidLookupsDefinition() { |
157 | 163 | final Properties props = new Properties(); |
158 | 164 | props.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, "base64_encoder nope"); |
159 | 165 |
|
160 | | - final Exception exc = Assertions.assertThrows(IllegalArgumentException.class, |
| 166 | + final Exception exc = assertThrows(IllegalArgumentException.class, |
161 | 167 | () -> new StringLookupFactory.DefaultStringLookupsHolder(props)); |
162 | | - Assertions.assertEquals("Invalid default string lookups definition: base64_encoder nope", exc.getMessage()); |
| 168 | + assertEquals("Invalid default string lookups definition: base64_encoder nope", exc.getMessage()); |
163 | 169 | } |
164 | 170 |
|
165 | 171 | @Test |
@@ -215,30 +221,57 @@ public void testDefaultStringLookupsHolder_multipleLookups() { |
215 | 221 | @Test |
216 | 222 | public void testSingletons() { |
217 | 223 | final StringLookupFactory stringLookupFactory = StringLookupFactory.INSTANCE; |
218 | | - Assertions.assertSame(StringLookupFactory.INSTANCE_BASE64_DECODER, |
| 224 | + assertSame(StringLookupFactory.INSTANCE_BASE64_DECODER, |
219 | 225 | stringLookupFactory.base64DecoderStringLookup()); |
220 | | - Assertions.assertSame(StringLookupFactory.INSTANCE_BASE64_ENCODER, |
| 226 | + assertSame(StringLookupFactory.INSTANCE_BASE64_ENCODER, |
221 | 227 | stringLookupFactory.base64EncoderStringLookup()); |
222 | | - Assertions.assertSame(ConstantStringLookup.INSTANCE, stringLookupFactory.constantStringLookup()); |
223 | | - Assertions.assertSame(DateStringLookup.INSTANCE, stringLookupFactory.dateStringLookup()); |
224 | | - Assertions.assertSame(DnsStringLookup.INSTANCE, stringLookupFactory.dnsStringLookup()); |
225 | | - Assertions.assertSame(StringLookupFactory.INSTANCE_ENVIRONMENT_VARIABLES, |
| 228 | + assertSame(ConstantStringLookup.INSTANCE, stringLookupFactory.constantStringLookup()); |
| 229 | + assertSame(DateStringLookup.INSTANCE, stringLookupFactory.dateStringLookup()); |
| 230 | + assertSame(DnsStringLookup.INSTANCE, stringLookupFactory.dnsStringLookup()); |
| 231 | + assertSame(StringLookupFactory.INSTANCE_ENVIRONMENT_VARIABLES, |
226 | 232 | stringLookupFactory.environmentVariableStringLookup()); |
227 | | - Assertions.assertSame(InterpolatorStringLookup.INSTANCE, stringLookupFactory.interpolatorStringLookup()); |
228 | | - Assertions.assertSame(JavaPlatformStringLookup.INSTANCE, stringLookupFactory.javaPlatformStringLookup()); |
229 | | - Assertions.assertSame(InetAddressStringLookup.LOCAL_HOST, stringLookupFactory.localHostStringLookup()); |
230 | | - Assertions.assertSame(InetAddressStringLookup.LOOPACK_ADDRESS, stringLookupFactory.loopbackAddressStringLookup()); |
231 | | - Assertions.assertSame(StringLookupFactory.INSTANCE_NULL, stringLookupFactory.nullStringLookup()); |
232 | | - Assertions.assertSame(ResourceBundleStringLookup.INSTANCE, stringLookupFactory.resourceBundleStringLookup()); |
233 | | - Assertions.assertSame(ScriptStringLookup.INSTANCE, stringLookupFactory.scriptStringLookup()); |
234 | | - Assertions.assertSame(StringLookupFactory.INSTANCE_SYSTEM_PROPERTIES, |
| 233 | + assertSame(InterpolatorStringLookup.INSTANCE, stringLookupFactory.interpolatorStringLookup()); |
| 234 | + assertSame(JavaPlatformStringLookup.INSTANCE, stringLookupFactory.javaPlatformStringLookup()); |
| 235 | + assertSame(InetAddressStringLookup.LOCAL_HOST, stringLookupFactory.localHostStringLookup()); |
| 236 | + assertSame(InetAddressStringLookup.LOOPACK_ADDRESS, stringLookupFactory.loopbackAddressStringLookup()); |
| 237 | + assertSame(StringLookupFactory.INSTANCE_NULL, stringLookupFactory.nullStringLookup()); |
| 238 | + assertSame(ResourceBundleStringLookup.INSTANCE, stringLookupFactory.resourceBundleStringLookup()); |
| 239 | + assertSame(ScriptStringLookup.INSTANCE, stringLookupFactory.scriptStringLookup()); |
| 240 | + assertSame(StringLookupFactory.INSTANCE_SYSTEM_PROPERTIES, |
235 | 241 | stringLookupFactory.systemPropertyStringLookup()); |
236 | | - Assertions.assertSame(UrlDecoderStringLookup.INSTANCE, stringLookupFactory.urlDecoderStringLookup()); |
237 | | - Assertions.assertSame(UrlEncoderStringLookup.INSTANCE, stringLookupFactory.urlEncoderStringLookup()); |
238 | | - Assertions.assertSame(UrlStringLookup.INSTANCE, stringLookupFactory.urlStringLookup()); |
239 | | - Assertions.assertSame(XmlStringLookup.INSTANCE, stringLookupFactory.xmlStringLookup()); |
240 | | - Assertions.assertSame(XmlDecoderStringLookup.INSTANCE, stringLookupFactory.xmlDecoderStringLookup()); |
241 | | - Assertions.assertSame(XmlEncoderStringLookup.INSTANCE, stringLookupFactory.xmlEncoderStringLookup()); |
| 242 | + assertSame(UrlDecoderStringLookup.INSTANCE, stringLookupFactory.urlDecoderStringLookup()); |
| 243 | + assertSame(UrlEncoderStringLookup.INSTANCE, stringLookupFactory.urlEncoderStringLookup()); |
| 244 | + assertSame(UrlStringLookup.INSTANCE, stringLookupFactory.urlStringLookup()); |
| 245 | + assertSame(XmlStringLookup.INSTANCE, stringLookupFactory.xmlStringLookup()); |
| 246 | + assertSame(XmlDecoderStringLookup.INSTANCE, stringLookupFactory.xmlDecoderStringLookup()); |
| 247 | + assertSame(XmlEncoderStringLookup.INSTANCE, stringLookupFactory.xmlEncoderStringLookup()); |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * Tests that we return the singleton. |
| 252 | + */ |
| 253 | + @Test |
| 254 | + public void testDefault() { |
| 255 | + final StringLookupFactory stringLookupFactory = StringLookupFactory.INSTANCE; |
| 256 | + final Map<String, StringLookup> stringLookupMap = new HashMap<>(); |
| 257 | + stringLookupFactory.addDefaultStringLookups(stringLookupMap); |
| 258 | + assertTrue(stringLookupMap.containsKey("base64")); |
| 259 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_BASE64_ENCODER.toLowerCase(Locale.ROOT))); |
| 260 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_CONST.toLowerCase(Locale.ROOT))); |
| 261 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_DATE)); |
| 262 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_ENV.toLowerCase(Locale.ROOT))); |
| 263 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_FILE.toLowerCase(Locale.ROOT))); |
| 264 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_JAVA.toLowerCase(Locale.ROOT))); |
| 265 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_LOCALHOST.toLowerCase(Locale.ROOT))); |
| 266 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_LOOPBACK_ADDRESS.toLowerCase(Locale.ROOT))); |
| 267 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_PROPERTIES.toLowerCase(Locale.ROOT))); |
| 268 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_RESOURCE_BUNDLE.toLowerCase(Locale.ROOT))); |
| 269 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_SYS.toLowerCase(Locale.ROOT))); |
| 270 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_URL_DECODER.toLowerCase(Locale.ROOT))); |
| 271 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_URL_ENCODER.toLowerCase(Locale.ROOT))); |
| 272 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_XML.toLowerCase(Locale.ROOT))); |
| 273 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_XML_DECODER.toLowerCase(Locale.ROOT))); |
| 274 | + assertTrue(stringLookupMap.containsKey(StringLookupFactory.KEY_XML_ENCODER.toLowerCase(Locale.ROOT))); |
242 | 275 | } |
243 | 276 |
|
244 | 277 | @Test |
|
0 commit comments