#39 Fixed tests and added some more
This commit is contained in:
@@ -33,6 +33,7 @@ public final class Main {
|
||||
*/
|
||||
public static void main(final String[] args) throws ConfigurationException {
|
||||
Config config = Config.getInstance();
|
||||
config.loadConfig();
|
||||
String amznBaseUrl = config.getProperty("AMAZON_API_URL");
|
||||
String amznApiKey = config.getProperty("AMAZON_API_KEY");
|
||||
String testProduct = null;
|
||||
|
||||
@@ -16,7 +16,22 @@ public final class Config {
|
||||
/**
|
||||
* Config file location.
|
||||
*/
|
||||
private static final String CONFIG_LOCATION = "config/config.properties";
|
||||
private String configLocation = "config/config.properties";
|
||||
|
||||
/**
|
||||
* @return the configLocation
|
||||
*/
|
||||
public String getConfigLocation() {
|
||||
return configLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newConfigLocation the configLocation to set
|
||||
*/
|
||||
public void setConfigLocation(final String newConfigLocation) {
|
||||
configLocation = newConfigLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the config values.
|
||||
*/
|
||||
@@ -27,10 +42,10 @@ public final class Config {
|
||||
private static Config instance = null;
|
||||
|
||||
/**
|
||||
* Private constructor to prevent unwanted instantiation.
|
||||
* Private constructor to prevent external instantiation.
|
||||
*/
|
||||
private Config() throws ConfigurationException {
|
||||
loadConfig();
|
||||
private Config() {
|
||||
// Do Nothing
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +54,7 @@ public final class Config {
|
||||
* @return Config instance
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public static Config getInstance() throws ConfigurationException {
|
||||
public static Config getInstance() {
|
||||
if (instance == null) {
|
||||
return new Config();
|
||||
}
|
||||
@@ -54,7 +69,7 @@ public final class Config {
|
||||
*/
|
||||
public void loadConfig() throws ConfigurationException {
|
||||
Properties newProps = new Properties();
|
||||
try (FileInputStream input = new FileInputStream(CONFIG_LOCATION)) {
|
||||
try (FileInputStream input = new FileInputStream(configLocation)) {
|
||||
newProps.load(input);
|
||||
properties = newProps;
|
||||
} catch (IOException e) {
|
||||
@@ -70,10 +85,18 @@ public final class Config {
|
||||
* @throws NoSuchElementException Required key missing
|
||||
*/
|
||||
public String getProperty(final String key) throws NoSuchElementException {
|
||||
String value = properties.getProperty(key);
|
||||
String value = null;
|
||||
|
||||
try {
|
||||
value = properties.getProperty(key);
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSuchElementException("Config has not been loaded");
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
throw new NoSuchElementException("Requested config value does not exist");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user