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.configuration.interpol; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNull; 21 22 import java.util.Iterator; 23 24 import org.apache.commons.configuration.EnvironmentConfiguration; 25 import org.junit.Before; 26 import org.junit.Test; 27 28 /** 29 * Test class for EnvironmentLookup. 30 * 31 * @author <a 32 * href="http://commons.apache.org/configuration/team-list.html">Commons 33 * Configuration team</a> 34 * @version $Id: TestEnvironmentLookup.java 1225658 2011-12-29 21:11:03Z oheger $ 35 */ 36 public class TestEnvironmentLookup 37 { 38 /** The lookup to be tested. */ 39 private EnvironmentLookup lookup; 40 41 @Before 42 public void setUp() throws Exception 43 { 44 lookup = new EnvironmentLookup(); 45 } 46 47 /** 48 * Tests whether environment variables can be queried. 49 */ 50 @Test 51 public void testLookup() 52 { 53 EnvironmentConfiguration envConf = new EnvironmentConfiguration(); 54 for (Iterator<String> it = envConf.getKeys(); it.hasNext();) 55 { 56 String var = it.next(); 57 assertEquals("Wrong value for " + var, envConf.getString(var), 58 lookup.lookup(var)); 59 } 60 } 61 62 /** 63 * Tries to lookup a non existing property. 64 */ 65 @Test 66 public void testLookupNonExisting() 67 { 68 assertNull("Got result for non existing environment variable", lookup 69 .lookup("a non existing variable!")); 70 } 71 }