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    package org.apache.commons.configuration.interpol;
018    
019    import static org.junit.Assert.assertEquals;
020    import static org.junit.Assert.assertNull;
021    
022    import java.util.Iterator;
023    
024    import org.apache.commons.configuration.EnvironmentConfiguration;
025    import org.junit.Before;
026    import org.junit.Test;
027    
028    /**
029     * Test class for EnvironmentLookup.
030     *
031     * @author <a
032     *         href="http://commons.apache.org/configuration/team-list.html">Commons
033     *         Configuration team</a>
034     * @version $Id: TestEnvironmentLookup.java 1225658 2011-12-29 21:11:03Z oheger $
035     */
036    public class TestEnvironmentLookup
037    {
038        /** The lookup to be tested. */
039        private EnvironmentLookup lookup;
040    
041        @Before
042        public void setUp() throws Exception
043        {
044            lookup = new EnvironmentLookup();
045        }
046    
047        /**
048         * Tests whether environment variables can be queried.
049         */
050        @Test
051        public void testLookup()
052        {
053            EnvironmentConfiguration envConf = new EnvironmentConfiguration();
054            for (Iterator<String> it = envConf.getKeys(); it.hasNext();)
055            {
056                String var = it.next();
057                assertEquals("Wrong value for " + var, envConf.getString(var),
058                        lookup.lookup(var));
059            }
060        }
061    
062        /**
063         * Tries to lookup a non existing property.
064         */
065        @Test
066        public void testLookupNonExisting()
067        {
068            assertNull("Got result for non existing environment variable", lookup
069                    .lookup("a non existing variable!"));
070        }
071    }