Update tests

This commit is contained in:
anthorob committed 2022-06-23 12:01:54 -04:00
1 parent 6544e982c6
commit 5f1cbad0ee
3 files changed
+63 -9

No files matched your search

@@ -1,5 +1,7 @@
package netneutrality.utils; package netneutrality.utils;
import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@@ -12,17 +14,28 @@ public class Settings {
private final Properties prop = new Properties(); private final Properties prop = new Properties();
public Settings() { public Settings() {
File file = new File("bot.properties"); File propFile = new File("bot.properties");
File exampleFile = new File("bot.properties.example");
FileInputStream fis = null; FileInputStream fis = null;
try { try {
file.createNewFile(); if (!propFile.exists() && !exampleFile.exists()) {
fis = new FileInputStream(file); 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); prop.load(fis);
loadEnvironmentVariables(); loadEnvironmentVariables();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); System.err.println("Can't find config file: bot.properties");
System.exit(1);
} finally { } finally {
try { try {
if (fis != null) if (fis != null)
@@ -10,6 +10,7 @@ import netneutrality.music.loadable.AppleMostPlayed;
import netneutrality.music.loadable.CachedSource; import netneutrality.music.loadable.CachedSource;
import netneutrality.music.loadable.LoadableSong; import netneutrality.music.loadable.LoadableSong;
import netneutrality.music.loadable.LoadableSourceManager; import netneutrality.music.loadable.LoadableSourceManager;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.List; import java.util.List;
@@ -18,11 +19,18 @@ import static org.junit.Assert.*;
public class LoadableSourceTest { public class LoadableSourceTest {
@Test LoadableSourceManager loadableSourceManager;
public void getAppleMostPlayed() {
LoadableSourceManager loadableSourceManager = new LoadableSourceManager();
CachedSource cachedSource = loadableSourceManager.get(new AppleMostPlayed());
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()));
} }
} }
@@ -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);
}
}