Coverage Report - org.jbehave.core.steps.needle.configuration.LoadResourceBundle
 
Classes in this File Line Coverage Branch Coverage Complexity
LoadResourceBundle
62%
5/8
50%
2/4
2
LoadResourceBundle$1
33%
1/3
N/A
2
LoadResourceBundle$1$1
0%
0/3
N/A
2
 
 1  
 package org.jbehave.core.steps.needle.configuration;
 2  
 
 3  
 import java.util.Enumeration;
 4  
 import java.util.MissingResourceException;
 5  
 import java.util.ResourceBundle;
 6  
 
 7  
 /**
 8  
  * Null safe Resource Loader. If ResourceBundle does not exist, an empty Bundle is returned.
 9  
  * 
 10  
  * @author Jan Galinski, Holisticon AG (jan.galinski@holisticon.de)
 11  
  * @author Simon Zambrovski, Holisticon AG (simon.zambrovski@holisticon.de)
 12  
  */
 13  2
 public enum LoadResourceBundle {
 14  1
         INSTANCE;
 15  
 
 16  1
         public static final ResourceBundle EMPTY_RESOURCE_BUNDLE = new ResourceBundle() {
 17  
 
 18  
                 @Override
 19  
                 public Enumeration<String> getKeys() {
 20  0
                         return new Enumeration<String>() {
 21  
 
 22  
                                 public boolean hasMoreElements() {
 23  0
                                         return false;
 24  
                                 }
 25  
 
 26  
                                 public String nextElement() {
 27  0
                                         return null;
 28  
                                 }
 29  
                         };
 30  
                 }
 31  
 
 32  
                 @Override
 33  
                 protected Object handleGetObject(final String key) {
 34  0
                         return "";
 35  
                 }
 36  
         };
 37  
 
 38  
         public final ResourceBundle apply(final String resourceName) {
 39  9
                 if (resourceName == null || "".equals(resourceName.trim())) {
 40  0
                         throw new IllegalArgumentException("resourceName must not be null or empty!");
 41  
                 }
 42  
 
 43  
                 try {
 44  9
                         return ResourceBundle.getBundle(resourceName);
 45  0
                 } catch (final MissingResourceException e) {
 46  0
                         return EMPTY_RESOURCE_BUNDLE;
 47  
                 }
 48  
         }
 49  
 
 50  
 }