001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.lang.text;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026: import junit.textui.TestRunner;
027:
028: /**
029: * Test class for StrLookup.
030: *
031: * @version $Id: StrLookupTest.java 437554 2006-08-28 06:21:41Z bayard $
032: */
033: public class StrLookupTest extends TestCase {
034:
035: /**
036: * Main method.
037: *
038: * @param args command line arguments, ignored
039: */
040: public static void main(String[] args) {
041: TestRunner.run(suite());
042: }
043:
044: /**
045: * Return a new test suite containing this test case.
046: *
047: * @return a new test suite containing this test case
048: */
049: public static Test suite() {
050: TestSuite suite = new TestSuite(StrLookupTest.class);
051: suite.setName("StrLookup Tests");
052: return suite;
053: }
054:
055: protected void setUp() throws Exception {
056: super .setUp();
057: }
058:
059: protected void tearDown() throws Exception {
060: super .tearDown();
061: }
062:
063: //-----------------------------------------------------------------------
064: public void testNoneLookup() {
065: assertEquals(null, StrLookup.noneLookup().lookup(null));
066: assertEquals(null, StrLookup.noneLookup().lookup(""));
067: assertEquals(null, StrLookup.noneLookup().lookup("any"));
068: }
069:
070: public void testSystemProperiesLookup() {
071: assertEquals(System.getProperty("os.name"), StrLookup
072: .systemPropertiesLookup().lookup("os.name"));
073: assertEquals(null, StrLookup.systemPropertiesLookup()
074: .lookup(""));
075: assertEquals(null, StrLookup.systemPropertiesLookup().lookup(
076: "other"));
077: try {
078: StrLookup.systemPropertiesLookup().lookup(null);
079: fail();
080: } catch (NullPointerException ex) {
081: // expected
082: }
083: }
084:
085: public void testMapLookup() {
086: Map map = new HashMap();
087: map.put("key", "value");
088: map.put("number", new Integer(2));
089: assertEquals("value", StrLookup.mapLookup(map).lookup("key"));
090: assertEquals("2", StrLookup.mapLookup(map).lookup("number"));
091: assertEquals(null, StrLookup.mapLookup(map).lookup(null));
092: assertEquals(null, StrLookup.mapLookup(map).lookup(""));
093: assertEquals(null, StrLookup.mapLookup(map).lookup("other"));
094: }
095:
096: public void testMapLookup_nullMap() {
097: Map map = null;
098: assertEquals(null, StrLookup.mapLookup(map).lookup(null));
099: assertEquals(null, StrLookup.mapLookup(map).lookup(""));
100: assertEquals(null, StrLookup.mapLookup(map).lookup("any"));
101: }
102:
103: }
|