Added all suggested changes from the comments by reviewers
This commit is contained in:
parent
244ec5ee10
commit
26483e6d13
4 changed files with 22 additions and 25 deletions
|
|
@ -5,14 +5,11 @@ import java.util.List;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
/*
|
|
||||||
Sets parameters for what the config file needs with a config
|
|
||||||
Object that will be used in the ConfigService object
|
|
||||||
*/
|
|
||||||
private String language = "en";
|
private String language = "en";
|
||||||
private String serverUrl = "http://localhost:8080";
|
private String serverUrl = "http://localhost:8080";
|
||||||
|
|
||||||
private List<String> favourites = new ArrayList<>();
|
private List<Long> favourites = new ArrayList<>();
|
||||||
private List<String> shoppingList = new ArrayList<>();
|
private List<String> shoppingList = new ArrayList<>();
|
||||||
|
|
||||||
public Config(){}
|
public Config(){}
|
||||||
|
|
@ -25,7 +22,7 @@ public class Config {
|
||||||
return shoppingList;
|
return shoppingList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getFavourites() {
|
public List<Long> getFavourites() {
|
||||||
return favourites;
|
return favourites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +38,7 @@ public class Config {
|
||||||
this.serverUrl = serverUrl;
|
this.serverUrl = serverUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFavourites(List<String> favourites) {
|
public void setFavourites(List<Long> favourites) {
|
||||||
this.favourites = favourites;
|
this.favourites = favourites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,21 +31,18 @@ public class ConfigService {
|
||||||
*/
|
*/
|
||||||
private void load(){
|
private void load(){
|
||||||
File file = configPath.toFile(); //reads the config file as file
|
File file = configPath.toFile(); //reads the config file as file
|
||||||
if(file.exists()){
|
if (!file.exists()) { //if file doesn't exist then it creates a config object
|
||||||
try{
|
config = new Config();
|
||||||
config = mapper.readValue(file, Config.class); //uses Jackson to map the file to the config attribute
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (StreamReadException e) {
|
try{
|
||||||
throw new RuntimeException(e);
|
config = mapper.readValue(file, Config.class); //uses Jackson to map the file to the config attribute
|
||||||
} catch (DatabindException e) {
|
|
||||||
throw new RuntimeException(e);
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
throw new RuntimeException(e);
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
config = new Config(); // if file doesn't exist, it creates one
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path getConfigPath() {
|
public Path getConfigPath() {
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,9 @@ public class ConfigServiceTest {
|
||||||
assertEquals("de", config.getLanguage());
|
assertEquals("de", config.getLanguage());
|
||||||
assertEquals("http://exmple12.com", config.getServerUrl());
|
assertEquals("http://exmple12.com", config.getServerUrl());
|
||||||
|
|
||||||
List<String> x = new ArrayList<>();
|
List<Long> x = new ArrayList<>();
|
||||||
x.add("banana bread");
|
x.add(23412L);
|
||||||
x.add("pineapple pie");
|
x.add(25412L);
|
||||||
|
|
||||||
List<String> y = new ArrayList<>();
|
List<String> y = new ArrayList<>();
|
||||||
y.add("milk");
|
y.add("milk");
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,11 @@ public class ConfigTest {
|
||||||
ArrayList<String> x = new ArrayList<>();
|
ArrayList<String> x = new ArrayList<>();
|
||||||
x.add("Lava Cake");
|
x.add("Lava Cake");
|
||||||
x.add("Brownie");
|
x.add("Brownie");
|
||||||
config.setFavourites(x);
|
ArrayList<Long> y = new ArrayList<>();
|
||||||
assertEquals(config.getFavourites(), x);
|
y.add(1234L);
|
||||||
|
y.add(1235L);
|
||||||
|
config.setFavourites(y);
|
||||||
|
assertEquals(config.getFavourites(), y);
|
||||||
config.setShoppingList(x);
|
config.setShoppingList(x);
|
||||||
assertEquals(config.getShoppingList(), x);
|
assertEquals(config.getShoppingList(), x);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue