diff --git a/src/main/java/netneutrality/utils/Settings.java b/src/main/java/netneutrality/utils/Settings.java index 17205be..f0c515e 100644 --- a/src/main/java/netneutrality/utils/Settings.java +++ b/src/main/java/netneutrality/utils/Settings.java @@ -1,5 +1,7 @@ package netneutrality.utils; +import org.apache.commons.io.FileUtils; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -12,17 +14,28 @@ public class Settings { private final Properties prop = new Properties(); public Settings() { - File file = new File("bot.properties"); + File propFile = new File("bot.properties"); + File exampleFile = new File("bot.properties.example"); FileInputStream fis = null; try { - file.createNewFile(); - fis = new FileInputStream(file); + if (!propFile.exists() && !exampleFile.exists()) { + System.err.println("Missing example config file in root directory."); + System.exit(1); + } + + if (!propFile.exists()) { + FileUtils.copyFile(exampleFile, propFile); + System.err.println("Config file was created, please edit bot.properties before launching bot"); + } + + fis = new FileInputStream(propFile); prop.load(fis); loadEnvironmentVariables(); } catch (IOException e) { - e.printStackTrace(); + System.err.println("Can't find config file: bot.properties"); + System.exit(1); } finally { try { if (fis != null) diff --git a/src/test/java/netneutrality/music/LoadableSourceTest.java b/src/test/java/netneutrality/music/LoadableSourceTest.java index 5a63ef4..826a477 100644 --- a/src/test/java/netneutrality/music/LoadableSourceTest.java +++ b/src/test/java/netneutrality/music/LoadableSourceTest.java @@ -10,6 +10,7 @@ import netneutrality.music.loadable.AppleMostPlayed; import netneutrality.music.loadable.CachedSource; import netneutrality.music.loadable.LoadableSong; import netneutrality.music.loadable.LoadableSourceManager; +import org.junit.Before; import org.junit.Test; import java.util.List; @@ -18,11 +19,18 @@ import static org.junit.Assert.*; public class LoadableSourceTest { - @Test - public void getAppleMostPlayed() { - LoadableSourceManager loadableSourceManager = new LoadableSourceManager(); - CachedSource cachedSource = loadableSourceManager.get(new AppleMostPlayed()); + LoadableSourceManager loadableSourceManager; - assertTrue(cachedSource.getSongs().size() > 0); + @Before + public void setUp() throws Exception { + loadableSourceManager = new LoadableSourceManager(); + } + + @Test + public void cachedSourceAccess() { + CachedSource cachedSource = loadableSourceManager.get(new AppleMostPlayed()); + CachedSource sameCachedSource = loadableSourceManager.get(new AppleMostPlayed()); + + assertTrue(cachedSource.getLastAccess().isEqual(sameCachedSource.getLastAccess())); } } \ No newline at end of file diff --git a/src/test/java/netneutrality/utils/SettingsTest.java b/src/test/java/netneutrality/utils/SettingsTest.java new file mode 100644 index 0000000..3c7f452 --- /dev/null +++ b/src/test/java/netneutrality/utils/SettingsTest.java @@ -0,0 +1,33 @@ +package netneutrality.utils; +/* + * Copyright (c) anthorob + * + * https://xtremcommunity.com/ + * https://discord.gg/CdFcyQ + */ + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SettingsTest { + + private Settings instance; + + @Before + public void setUp() { + instance = Settings.getInstance(); + } + + @Test + public void get() { + assertNotNull(instance.get("BOT_TOKEN")); + } + + @Test + public void getCreator() { + String creator = instance.getCreatorId(); + assertNotNull(creator); + } +}