// Path: src/main/java/me/alb_i986/selenium/tinafw/config/ConfigException.java
// public class ConfigException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -6017026647523692805L;
// 
// 	public ConfigException() {
// 		super();
// 	}
// 
// 	public ConfigException(String message, Throwable cause,
// 			boolean enableSuppression, boolean writableStackTrace) {
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public ConfigException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public ConfigException(String message) {
// 		super(message);
// 	}
// 
// 	public ConfigException(Throwable cause) {
// 		super(cause);
// 	}
// 
// }
// 
// Path: src/main/java/me/alb_i986/selenium/tinafw/config/PropertyLoader.java
// public abstract class PropertyLoader {
// 
// 	/**
// 	 * @param key the name of the property
// 	 * 
// 	 * @return the value of the given property;
// 	 *         null if the property is not defined
// 	 */
// 	public abstract String getProperty(String key);
// 	
// 	/**
// 	 * @return true if the given property is defined in the source.
// 	 */
// 	public boolean isPropertyDefined(String key) {
// 		return getProperty(key) != null;
// 	}
// 
// 	/**
// 	 * @return true if the given property is not defined or it is an empty string
// 	 */
// 	public boolean isPropertyEmpty(String key) {
// 		if(!isPropertyDefined(key))
// 			return true;
// 		return getProperty(key).isEmpty();
// 	}
// 
// }
// 
// Path: src/main/java/me/alb_i986/selenium/tinafw/config/PropertyLoaderFromResource.java
// public class PropertyLoaderFromResource extends PropertyLoader {
// 
// 	private static final Logger logger = LogManager.getLogger(PropertyLoaderFromResource.class);
// 
// 	private Properties propsFromResource;
// 
// 	public PropertyLoaderFromResource(String resourceName, boolean isResourceRequired) {
// 		this.propsFromResource = loadPropsFromResource(resourceName, isResourceRequired);
// 	}
// 
// 	@Override
// 	public String getProperty(String key) {
// 		return propsFromResource.getProperty(key);
// 	}
// 	
// 	/**
// 	 * Load properties from a resource.
// 	 * 
// 	 * @param resourceName
// 	 * @param failOnResourceNotFoundOrNotLoaded when true, a ConfigException
// 	 *        is raised if the resource cannot be found or loaded
// 	 * @return a {@link Properties} instance with the properties loaded from the resource;
// 	 *         might be empty if the resource is not found or if it cannot be loaded
// 	 * @throws ConfigException if the resource cannot be found or loaded,
// 	 *         and failOnResourceNotFound is true
// 	 *         
// 	 * @see Properties#load(InputStream)
// 	 */
// 	private static Properties loadPropsFromResource(String resourceName, boolean failOnResourceNotFoundOrNotLoaded) {
// 		Properties props = new Properties();
// 		InputStream resource = PropertyLoaderFromResource.class.getResourceAsStream(resourceName);
// 		boolean resourceNotFound = (resource == null);
// 		if(resourceNotFound) {
// 			if(failOnResourceNotFoundOrNotLoaded) {
// 				throw new ConfigException("resource " + resourceName + " not found");
// 			} else {
// 				// if the resource is not found, return an empty Properties
// 				logger.warn("Skipping resource " + resourceName + ": file not found.");
// 				return props;
// 			}
// 		}
// 		try {
// 			props.load(resource);
// 		} catch (IOException e) {
// 			if(failOnResourceNotFoundOrNotLoaded)
// 				throw new ConfigException("Cannot load properties from " + resourceName, e);
// 			else
// 				logger.warn("Cannot load properties from " + resourceName + ": " + e.getMessage());
// 		}
// 		return props;
// 	}
// 
// }


import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import me.alb_i986.selenium.tinafw.config.ConfigException;
import me.alb_i986.selenium.tinafw.config.PropertyLoader;
import me.alb_i986.selenium.tinafw.config.PropertyLoaderFromResource;
import org.junit.Test;
package me.alb_i986.selenium.tinafw.config;



public class PropertyLoaderFromResourceTest {

	/**
	 * Testing the constructor
	 * {@link PropertyLoaderFromResource#PropertyLoaderFromResource(String, boolean)}.
	 * 
	 * <ul>
	 * <li>Given a resource which does not exist
	 * <li>When I instantiate a {@link PropertyLoaderFromResource} with
	 *     that resource, and the resource is <i>not</i> required
	 * <li>Then an exception should <i>not</i> be thrown
	 * </ul>
	 */
	@Test
	public void givenNonExistentResourceWhenNewAndResourceIsNotRequired() {
		String resourceName = givenNonExistingResource();
		boolean isResourceRequired = false;
		new PropertyLoaderFromResource(resourceName, isResourceRequired);
		// here it should NOT throw an exception
	}

	/**
	 * Testing the constructor
	 * {@link PropertyLoaderFromResource#PropertyLoaderFromResource(String, boolean)}.
	 * 
	 * <ul>
	 * <li>Given a resource which does not exist
	 * <li>When I instantiate a {@link PropertyLoaderFromResource} with
	 *     that resource, and the resource is required
	 * <li>Then an exception should be thrown
	 * </ul>
	 */
// Path: src/main/java/me/alb_i986/selenium/tinafw/config/ConfigException.java
// public class ConfigException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -6017026647523692805L;
// 
// 	public ConfigException() {
// 		super();
// 	}
// 
// 	public ConfigException(String message, Throwable cause,
// 			boolean enableSuppression, boolean writableStackTrace) {
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public ConfigException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public ConfigException(String message) {
// 		super(message);
// 	}
// 
// 	public ConfigException(Throwable cause) {
// 		super(cause);
// 	}
// 
// }
// 
// Path: src/main/java/me/alb_i986/selenium/tinafw/config/PropertyLoader.java
// public abstract class PropertyLoader {
// 
// 	/**
// 	 * @param key the name of the property
// 	 * 
// 	 * @return the value of the given property;
// 	 *         null if the property is not defined
// 	 */
// 	public abstract String getProperty(String key);
// 	
// 	/**
// 	 * @return true if the given property is defined in the source.
// 	 */
// 	public boolean isPropertyDefined(String key) {
// 		return getProperty(key) != null;
// 	}
// 
// 	/**
// 	 * @return true if the given property is not defined or it is an empty string
// 	 */
// 	public boolean isPropertyEmpty(String key) {
// 		if(!isPropertyDefined(key))
// 			return true;
// 		return getProperty(key).isEmpty();
// 	}
// 
// }
// 
// Path: src/main/java/me/alb_i986/selenium/tinafw/config/PropertyLoaderFromResource.java
// public class PropertyLoaderFromResource extends PropertyLoader {
// 
// 	private static final Logger logger = LogManager.getLogger(PropertyLoaderFromResource.class);
// 
// 	private Properties propsFromResource;
// 
// 	public PropertyLoaderFromResource(String resourceName, boolean isResourceRequired) {
// 		this.propsFromResource = loadPropsFromResource(resourceName, isResourceRequired);
// 	}
// 
// 	@Override
// 	public String getProperty(String key) {
// 		return propsFromResource.getProperty(key);
// 	}
// 	
// 	/**
// 	 * Load properties from a resource.
// 	 * 
// 	 * @param resourceName
// 	 * @param failOnResourceNotFoundOrNotLoaded when true, a ConfigException
// 	 *        is raised if the resource cannot be found or loaded
// 	 * @return a {@link Properties} instance with the properties loaded from the resource;
// 	 *         might be empty if the resource is not found or if it cannot be loaded
// 	 * @throws ConfigException if the resource cannot be found or loaded,
// 	 *         and failOnResourceNotFound is true
// 	 *         
// 	 * @see Properties#load(InputStream)
// 	 */
// 	private static Properties loadPropsFromResource(String resourceName, boolean failOnResourceNotFoundOrNotLoaded) {
// 		Properties props = new Properties();
// 		InputStream resource = PropertyLoaderFromResource.class.getResourceAsStream(resourceName);
// 		boolean resourceNotFound = (resource == null);
// 		if(resourceNotFound) {
// 			if(failOnResourceNotFoundOrNotLoaded) {
// 				throw new ConfigException("resource " + resourceName + " not found");
// 			} else {
// 				// if the resource is not found, return an empty Properties
// 				logger.warn("Skipping resource " + resourceName + ": file not found.");
// 				return props;
// 			}
// 		}
// 		try {
// 			props.load(resource);
// 		} catch (IOException e) {
// 			if(failOnResourceNotFoundOrNotLoaded)
// 				throw new ConfigException("Cannot load properties from " + resourceName, e);
// 			else
// 				logger.warn("Cannot load properties from " + resourceName + ": " + e.getMessage());
// 		}
// 		return props;
// 	}
// 
// }


// Path: src/test/java/me/alb_i986/selenium/tinafw/config/PropertyLoaderFromResourceTest.java
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import me.alb_i986.selenium.tinafw.config.ConfigException;
import me.alb_i986.selenium.tinafw.config.PropertyLoader;
import me.alb_i986.selenium.tinafw.config.PropertyLoaderFromResource;
import org.junit.Test;

package me.alb_i986.selenium.tinafw.config;



public class PropertyLoaderFromResourceTest {

	/**
	 * Testing the constructor
	 * {@link PropertyLoaderFromResource#PropertyLoaderFromResource(String, boolean)}.
	 * 
	 * <ul>
	 * <li>Given a resource which does not exist
	 * <li>When I instantiate a {@link PropertyLoaderFromResource} with
	 *     that resource, and the resource is <i>not</i> required
	 * <li>Then an exception should <i>not</i> be thrown
	 * </ul>
	 */
	@Test
	public void givenNonExistentResourceWhenNewAndResourceIsNotRequired() {
		String resourceName = givenNonExistingResource();
		boolean isResourceRequired = false;
		new PropertyLoaderFromResource(resourceName, isResourceRequired);
		// here it should NOT throw an exception
	}

	/**
	 * Testing the constructor
	 * {@link PropertyLoaderFromResource#PropertyLoaderFromResource(String, boolean)}.
	 * 
	 * <ul>
	 * <li>Given a resource which does not exist
	 * <li>When I instantiate a {@link PropertyLoaderFromResource} with
	 *     that resource, and the resource is required
	 * <li>Then an exception should be thrown
	 * </ul>
	 */
	@Test(expected = ConfigException.class)