Update tests
This commit is contained in:
1 parent
6544e982c6
commit
5f1cbad0ee
3 files changed
+63
-9
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user