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.text.lookup;
18  
19  import static org.junit.jupiter.api.Assertions.assertSame;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.junit.jupiter.api.Test;
25  
26  /**
27   * Tests {@link DefaultStringLookup}.
28   */
29  public class DefaultStringLookupTest {
30  
31      @Test
32      public void testEnumValues() {
33          final Map<String, StringLookup> stringLookupMap = new HashMap<>();
34          StringLookupFactory.INSTANCE.addDefaultStringLookups(stringLookupMap);
35          // Loop through all enums
36          for (final DefaultStringLookup stringLookup : DefaultStringLookup.values()) {
37              assertSame(stringLookupMap.get(stringLookup.getKey()), stringLookupMap.get(stringLookup.getKey()));
38          }
39      }
40  
41      @Test
42      public void testIndividualEnums() {
43          assertSame(DefaultStringLookup.BASE64_DECODER.getStringLookup(),
44              StringLookupFactory.INSTANCE.base64DecoderStringLookup());
45          assertSame(DefaultStringLookup.BASE64_ENCODER.getStringLookup(),
46              StringLookupFactory.INSTANCE.base64EncoderStringLookup());
47          assertSame(DefaultStringLookup.CONST.getStringLookup(), StringLookupFactory.INSTANCE.constantStringLookup());
48          assertSame(DefaultStringLookup.DATE.getStringLookup(), StringLookupFactory.INSTANCE.dateStringLookup());
49          assertSame(DefaultStringLookup.DNS.getStringLookup(), StringLookupFactory.INSTANCE.dnsStringLookup());
50          assertSame(DefaultStringLookup.ENVIRONMENT.getStringLookup(),
51              StringLookupFactory.INSTANCE.environmentVariableStringLookup());
52          assertSame(DefaultStringLookup.FILE.getStringLookup(), StringLookupFactory.INSTANCE.fileStringLookup());
53          assertSame(DefaultStringLookup.JAVA.getStringLookup(), StringLookupFactory.INSTANCE.javaPlatformStringLookup());
54          assertSame(DefaultStringLookup.LOCAL_HOST.getStringLookup(),
55              StringLookupFactory.INSTANCE.localHostStringLookup());
56          assertSame(DefaultStringLookup.PROPERTIES.getStringLookup(),
57              StringLookupFactory.INSTANCE.propertiesStringLookup());
58          assertSame(DefaultStringLookup.RESOURCE_BUNDLE.getStringLookup(),
59              StringLookupFactory.INSTANCE.resourceBundleStringLookup());
60          assertSame(DefaultStringLookup.SCRIPT.getStringLookup(), StringLookupFactory.INSTANCE.scriptStringLookup());
61          assertSame(DefaultStringLookup.SYSTEM_PROPERTIES.getStringLookup(),
62              StringLookupFactory.INSTANCE.systemPropertyStringLookup());
63          assertSame(DefaultStringLookup.URL.getStringLookup(), StringLookupFactory.INSTANCE.urlStringLookup());
64          assertSame(DefaultStringLookup.URL_DECODER.getStringLookup(),
65              StringLookupFactory.INSTANCE.urlDecoderStringLookup());
66          assertSame(DefaultStringLookup.URL_ENCODER.getStringLookup(),
67              StringLookupFactory.INSTANCE.urlEncoderStringLookup());
68          assertSame(DefaultStringLookup.XML.getStringLookup(), StringLookupFactory.INSTANCE.xmlStringLookup());
69      }
70  
71  }