Coverage Report - be.objectify.led.DefaultPropertyContext
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultPropertyContext
100%
16/16
100%
8/8
3
 
 1  
 /*
 2  
  * Copyright 2009-2010 Steve Chaloner
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package be.objectify.led;
 17  
 
 18  
 import be.objectify.led.util.ContractUtils;
 19  
 import be.objectify.led.util.StringUtils;
 20  
 import org.slf4j.Logger;
 21  
 import org.slf4j.LoggerFactory;
 22  
 
 23  
 import java.util.Properties;
 24  
 
 25  
 /**
 26  
  * Default implementation of {@link PropertyContext} which
 27  
  *
 28  
  * @author Steve Chaloner
 29  
  */
 30  
 public class DefaultPropertyContext implements PropertyContext
 31  
 {
 32  1
     private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPropertyContext.class);
 33  
 
 34  57
     private final Properties properties = new Properties();
 35  
 
 36  
     public DefaultPropertyContext(Properties... properties)
 37  57
     {
 38  57
         ContractUtils.nonNull(properties, "properties");
 39  
 
 40  62
         for (Properties propertiesInstance : properties)
 41  
         {
 42  5
             this.properties.putAll(propertiesInstance);
 43  
         }
 44  57
     }
 45  
 
 46  
     /** {@inheritDoc} */
 47  
     public String getValue(String propertyName)
 48  
     {
 49  80
         String value = null;
 50  
 
 51  80
         if (properties.containsKey(propertyName))
 52  
         {
 53  3
             value = properties.getProperty(propertyName);
 54  
         }
 55  
 
 56  80
         String property = System.getProperty(propertyName);
 57  80
         if (!StringUtils.isEmpty(property))
 58  
         {
 59  61
             value = property;
 60  
         }
 61  
 
 62  80
         if (value != null)
 63  
         {
 64  63
             LOGGER.debug("Found value [{}] for property [{}]",
 65  
                          value,
 66  
                          propertyName);
 67  
         }
 68  
 
 69  80
         return value;
 70  
     }
 71  
 }