[Debt] Removed Settings#setTemporaryValue method.

This method was used in tests, but is not the optimal way of performing
temporary test values as APF supports in memory configuration object.

Old usages were commented in order to preserve assumed temporary values.

Affected issues: none
This commit is contained in:
Rsl1122 2018-09-18 17:30:57 +03:00
parent 2b1cf4b3cb
commit fca93578af
16 changed files with 33 additions and 128 deletions

View File

@ -101,25 +101,14 @@ public enum Settings implements Setting {
BUNGEE_NETWORK_NAME("Network.Name"); BUNGEE_NETWORK_NAME("Network.Name");
private final String configPath; private final String configPath;
private Object tempValue;
Settings(String path) { Settings(String path) {
this.configPath = path; this.configPath = path;
} }
/** @Override
* Used to get the String path of a the config setting eg.
* Settings.WebServer.Enabled
*
* @return Path of the config setting.
*/
public String getPath() { public String getPath() {
return configPath; return configPath;
} }
@Deprecated
public void setTemporaryValue(Object value) {
this.tempValue = value;
}
} }

View File

@ -7,6 +7,13 @@ package com.djrapitops.plan.system.settings.config;
*/ */
public interface Setting { public interface Setting {
/**
* Used to get the String path of a the config setting.
* <p>
* Path separates nested levels with a dot.
*
* @return Example: Settings.WebServer.Enabled
*/
String getPath(); String getPath();
} }

View File

@ -5,7 +5,6 @@ import org.junit.ClassRule;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import utilities.Teardown;
import utilities.mocks.SystemMockUtil; import utilities.mocks.SystemMockUtil;
/** /**
@ -21,7 +20,6 @@ public class FormattersTest {
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
SystemMockUtil.setUp(temporaryFolder.getRoot()) SystemMockUtil.setUp(temporaryFolder.getRoot())
.enableConfigSystem(); .enableConfigSystem();
Teardown.resetSettingsTempValues();
} }
@Test @Test

View File

@ -6,12 +6,10 @@ package com.djrapitops.plan.system;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.settings.Settings;
import org.junit.*; import org.junit.*;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.mocks.BukkitMockUtil; import utilities.mocks.BukkitMockUtil;
/** /**
@ -38,23 +36,17 @@ public class BukkitSystemTest {
planMock = mockUtil.getPlanMock(); planMock = mockUtil.getPlanMock();
} }
@Before
public void setUp() {
Teardown.resetSettingsTempValues();
}
@After @After
public void tearDown() { public void tearDown() {
if (bukkitSystem != null) { if (bukkitSystem != null) {
bukkitSystem.disable(); bukkitSystem.disable();
} }
Teardown.resetSettingsTempValues();
} }
@Test @Test
@Ignore @Ignore
public void testEnable() throws EnableException { public void testEnable() throws EnableException {
Settings.WEBSERVER_PORT.setTemporaryValue(9005); // Settings.WEBSERVER_PORT.setTemporaryValue(9005);
bukkitSystem = null; //TODO bukkitSystem = null; //TODO
bukkitSystem.enable(); bukkitSystem.enable();

View File

@ -8,13 +8,11 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import org.junit.*; import org.junit.*;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.mocks.BukkitMockUtil; import utilities.mocks.BukkitMockUtil;
import utilities.mocks.BungeeMockUtil; import utilities.mocks.BungeeMockUtil;
@ -59,13 +57,6 @@ public class BungeeBukkitConnectionTest {
bungeeMock = bungeeMockUtil.getPlanMock(); bungeeMock = bungeeMockUtil.getPlanMock();
} }
@Before
public void setUp() {
Teardown.resetSettingsTempValues();
Settings.DEBUG.setTemporaryValue("console");
Settings.DEV_MODE.setTemporaryValue(true);
}
@After @After
public void tearDown() { public void tearDown() {
System.out.println("------------------------------"); System.out.println("------------------------------");
@ -77,11 +68,10 @@ public class BungeeBukkitConnectionTest {
if (bungeeSystem != null) { if (bungeeSystem != null) {
bungeeSystem.disable(); bungeeSystem.disable();
} }
Teardown.resetSettingsTempValues();
} }
public void enable() throws EnableException { public void enable() throws EnableException {
Settings.WEBSERVER_PORT.setTemporaryValue(9005); // Settings.WEBSERVER_PORT.setTemporaryValue(9005);
bukkitSystem = null; // TODO bukkitSystem = null; // TODO
bukkitSystem.enable(); bukkitSystem.enable();
@ -90,9 +80,9 @@ public class BungeeBukkitConnectionTest {
bungeeSystem = null; // TODO bungeeSystem = null; // TODO
Settings.WEBSERVER_PORT.setTemporaryValue(9250); // Settings.WEBSERVER_PORT.setTemporaryValue(9250);
Settings.BUNGEE_IP.setTemporaryValue("localhost"); // Settings.BUNGEE_IP.setTemporaryValue("localhost");
Settings.DB_TYPE.setTemporaryValue("sqlite"); // Settings.DB_TYPE.setTemporaryValue("sqlite");
// bungeeSystem.setDatabaseSystem(new BukkitDBSystem(new Locale())); // bungeeSystem.setDatabaseSystem(new BukkitDBSystem(new Locale()));
bungeeSystem.enable(); bungeeSystem.enable();

View File

@ -6,13 +6,11 @@ package com.djrapitops.plan.system;
import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.settings.Settings;
import org.junit.*; import org.junit.*;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.mocks.BungeeMockUtil; import utilities.mocks.BungeeMockUtil;
/** /**
@ -41,18 +39,11 @@ public class BungeeSystemTest {
planMock = mockUtil.getPlanMock(); planMock = mockUtil.getPlanMock();
} }
@Before
public void setUp() {
Teardown.resetSettingsTempValues();
}
@After @After
public void tearDown() { public void tearDown() {
if (bungeeSystem != null) { if (bungeeSystem != null) {
bungeeSystem.disable(); bungeeSystem.disable();
} }
Teardown.resetSettingsTempValues();
} }
@Test @Test
@ -60,9 +51,9 @@ public class BungeeSystemTest {
public void testEnable() throws EnableException { public void testEnable() throws EnableException {
bungeeSystem = null; //TODO bungeeSystem = null; //TODO
Settings.WEBSERVER_PORT.setTemporaryValue(9005); // Settings.WEBSERVER_PORT.setTemporaryValue(9005);
Settings.BUNGEE_IP.setTemporaryValue("8.8.8.8"); // Settings.BUNGEE_IP.setTemporaryValue("8.8.8.8");
Settings.DB_TYPE.setTemporaryValue("sqlite"); // Settings.DB_TYPE.setTemporaryValue("sqlite");
// bungeeSystem.setDatabaseSystem(new BukkitDBSystem(Locale::new)); // bungeeSystem.setDatabaseSystem(new BukkitDBSystem(Locale::new));
bungeeSystem.enable(); bungeeSystem.enable();
@ -76,8 +67,8 @@ public class BungeeSystemTest {
bungeeSystem = null; //TODO bungeeSystem = null; //TODO
Settings.WEBSERVER_PORT.setTemporaryValue(9005); // Settings.WEBSERVER_PORT.setTemporaryValue(9005);
Settings.DB_TYPE.setTemporaryValue("sqlite"); // Settings.DB_TYPE.setTemporaryValue("sqlite");
// bungeeSystem.setDatabaseSystem(new BukkitDBSystem(Locale::new)); // bungeeSystem.setDatabaseSystem(new BukkitDBSystem(Locale::new));
bungeeSystem.enable(); bungeeSystem.enable();

View File

@ -6,12 +6,10 @@ package com.djrapitops.plan.system;
import com.djrapitops.plan.PlanSponge; import com.djrapitops.plan.PlanSponge;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.settings.Settings;
import org.junit.*; import org.junit.*;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.mocks.SpongeMockUtil; import utilities.mocks.SpongeMockUtil;
/** /**
@ -36,23 +34,17 @@ public class SpongeSystemTest {
planMock = mockUtil.getPlanMock(); planMock = mockUtil.getPlanMock();
} }
@Before
public void setUp() {
Teardown.resetSettingsTempValues();
}
@After @After
public void tearDown() { public void tearDown() {
if (spongeSystem != null) { if (spongeSystem != null) {
spongeSystem.disable(); spongeSystem.disable();
} }
Teardown.resetSettingsTempValues();
} }
@Test @Test
@Ignore("Sponge mock required") @Ignore("Sponge mock required")
public void testEnable() throws EnableException { public void testEnable() throws EnableException {
Settings.WEBSERVER_PORT.setTemporaryValue(9005); // Settings.WEBSERVER_PORT.setTemporaryValue(9005);
spongeSystem = null; //TODO spongeSystem = null; //TODO
spongeSystem.enable(); spongeSystem.enable();

View File

@ -3,11 +3,12 @@ package com.djrapitops.plan.system.cache;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import org.junit.*; import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import utilities.Teardown;
import utilities.mocks.BukkitMockUtil; import utilities.mocks.BukkitMockUtil;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -25,7 +26,6 @@ public class GeolocationCacheTest {
@BeforeClass @BeforeClass
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
Teardown.resetSettingsTempValues();
BukkitMockUtil mockUtil = BukkitMockUtil.setUp() BukkitMockUtil mockUtil = BukkitMockUtil.setUp()
.withDataFolder(temporaryFolder.getRoot()) .withDataFolder(temporaryFolder.getRoot())
.withLogging() .withLogging()
@ -36,15 +36,10 @@ public class GeolocationCacheTest {
StaticHolder.saveInstance(GeolocationCacheTest.class, planMock.getClass()); StaticHolder.saveInstance(GeolocationCacheTest.class, planMock.getClass());
} }
@AfterClass
public static void tearDownClass() {
Teardown.resetSettingsTempValues();
}
@Test @Test
@Ignore @Ignore
public void testGeolocationCache() throws EnableException { public void testGeolocationCache() throws EnableException {
Settings.WEBSERVER_PORT.setTemporaryValue(9005); // Settings.WEBSERVER_PORT.setTemporaryValue(9005);
PlanSystem system = null; //TODO PlanSystem system = null; //TODO
try { try {
system.enable(); system.enable();

View File

@ -33,7 +33,6 @@ import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.OptionalAssert; import utilities.OptionalAssert;
import utilities.RandomData; import utilities.RandomData;
import utilities.Teardown;
import utilities.TestConstants; import utilities.TestConstants;
import utilities.mocks.SystemMockUtil; import utilities.mocks.SystemMockUtil;
@ -81,7 +80,6 @@ public class SQLiteTest {
if (db != null) { if (db != null) {
db.close(); db.close();
} }
Teardown.resetSettingsTempValues();
} }
@Before @Before

View File

@ -5,14 +5,10 @@ import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.tables.ServerTable; import com.djrapitops.plan.system.database.databases.sql.tables.ServerTable;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;
import org.junit.*; import org.junit.*;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import utilities.Teardown;
import utilities.TestConstants; import utilities.TestConstants;
import utilities.TestErrorManager;
import utilities.mocks.SystemMockUtil; import utilities.mocks.SystemMockUtil;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -25,7 +21,6 @@ public class NetworkSettingsTest {
@BeforeClass @BeforeClass
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
Teardown.resetSettingsTempValues();
StaticHolder.saveInstance(NetworkSettingsTest.class, Plan.class); StaticHolder.saveInstance(NetworkSettingsTest.class, Plan.class);
SystemMockUtil mockUtil = SystemMockUtil.setUp(temporaryFolder.getRoot()) SystemMockUtil mockUtil = SystemMockUtil.setUp(temporaryFolder.getRoot())
@ -34,9 +29,9 @@ public class NetworkSettingsTest {
mockUtil.enableDatabaseSystem(db) mockUtil.enableDatabaseSystem(db)
.enableServerInfoSystem(); .enableServerInfoSystem();
Log.setErrorManager(new TestErrorManager()); // Log.setErrorManager(new TestErrorManager());
Log.setDebugMode("console"); // Log.setDebugMode("console");
Settings.DEV_MODE.setTemporaryValue(true); // Settings.DEV_MODE.setTemporaryValue(true);
} }
@AfterClass @AfterClass
@ -44,7 +39,6 @@ public class NetworkSettingsTest {
if (db != null) { if (db != null) {
db.close(); db.close();
} }
Teardown.resetSettingsTempValues();
} }
@Before @Before

View File

@ -3,13 +3,11 @@ package com.djrapitops.plan.system.webserver;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.Base64Util; import com.djrapitops.plan.utilities.Base64Util;
import org.junit.*; import org.junit.*;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.mocks.BukkitMockUtil; import utilities.mocks.BukkitMockUtil;
import javax.net.ssl.*; import javax.net.ssl.*;
@ -41,12 +39,12 @@ public class HTTPSWebServerAuthTest {
String keyStore = resource.getPath(); String keyStore = resource.getPath();
String absolutePath = new File(keyStore).getAbsolutePath(); String absolutePath = new File(keyStore).getAbsolutePath();
Settings.WEBSERVER_CERTIFICATE_PATH.setTemporaryValue(absolutePath); // Settings.WEBSERVER_CERTIFICATE_PATH.setTemporaryValue(absolutePath);
Settings.WEBSERVER_CERTIFICATE_KEYPASS.setTemporaryValue("MnD3bU5HpmPXag0e"); // Settings.WEBSERVER_CERTIFICATE_KEYPASS.setTemporaryValue("MnD3bU5HpmPXag0e");
Settings.WEBSERVER_CERTIFICATE_STOREPASS.setTemporaryValue("wDwwf663NLTm73gL"); // Settings.WEBSERVER_CERTIFICATE_STOREPASS.setTemporaryValue("wDwwf663NLTm73gL");
Settings.WEBSERVER_CERTIFICATE_ALIAS.setTemporaryValue("DefaultPlanCert"); // Settings.WEBSERVER_CERTIFICATE_ALIAS.setTemporaryValue("DefaultPlanCert");
//
Settings.WEBSERVER_PORT.setTemporaryValue(9005); // Settings.WEBSERVER_PORT.setTemporaryValue(9005);
bukkitSystem = null; //TODO bukkitSystem = null; //TODO
// bukkitSystem.enable(); // bukkitSystem.enable();
@ -55,16 +53,6 @@ public class HTTPSWebServerAuthTest {
// .webUser(new WebUser("test", PassEncryptUtil.createHash("testPass"), 0)); // .webUser(new WebUser("test", PassEncryptUtil.createHash("testPass"), 0));
} }
@Before
public void setUp() {
Teardown.resetSettingsTempValues();
}
@After
public void tearDown() {
Teardown.resetSettingsTempValues();
}
@AfterClass @AfterClass
public static void tearDownClass() { public static void tearDownClass() {
if (bukkitSystem != null) { if (bukkitSystem != null) {

View File

@ -6,7 +6,6 @@ import org.junit.BeforeClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import utilities.Teardown;
import utilities.mocks.SystemMockUtil; import utilities.mocks.SystemMockUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -30,7 +29,6 @@ public class PlayersTableTest {
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
SystemMockUtil.setUp(temporaryFolder.getRoot()) SystemMockUtil.setUp(temporaryFolder.getRoot())
.enableConfigSystem(); .enableConfigSystem();
Teardown.resetSettingsTempValues();
} }
@Test @Test

View File

@ -1,21 +0,0 @@
/*
* License is provided in the jar as LICENSE also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
*/
package utilities;
import com.djrapitops.plan.system.settings.Settings;
/**
* Test utility for {@code @Teardown} tags.
*
* @author Rsl1122
*/
public class Teardown {
public static void resetSettingsTempValues() {
for (Settings settings : Settings.values()) {
settings.setTemporaryValue(null);
}
}
}

View File

@ -16,7 +16,6 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.TestConstants; import utilities.TestConstants;
import utilities.mocks.objects.FakeConsoleCmdSender; import utilities.mocks.objects.FakeConsoleCmdSender;
import utilities.mocks.objects.TestLogger; import utilities.mocks.objects.TestLogger;
@ -41,7 +40,6 @@ public class BukkitMockUtil extends MockUtil {
} }
public static BukkitMockUtil setUp() { public static BukkitMockUtil setUp() {
Teardown.resetSettingsTempValues();
return new BukkitMockUtil().mockPlugin(); return new BukkitMockUtil().mockPlugin();
} }

View File

@ -17,7 +17,6 @@ import net.md_5.bungee.api.plugin.PluginDescription;
import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.api.plugin.PluginManager;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.TestConstants; import utilities.TestConstants;
import utilities.mocks.objects.FakeBungeeConsole; import utilities.mocks.objects.FakeBungeeConsole;
import utilities.mocks.objects.TestLogger; import utilities.mocks.objects.TestLogger;
@ -41,7 +40,6 @@ public class BungeeMockUtil extends MockUtil {
} }
public static BungeeMockUtil setUp() { public static BungeeMockUtil setUp() {
Teardown.resetSettingsTempValues();
return new BungeeMockUtil().mockPlugin(); return new BungeeMockUtil().mockPlugin();
} }

View File

@ -12,7 +12,6 @@ import com.djrapitops.plugin.task.thread.ThreadRunnable;
import com.djrapitops.plugin.task.thread.ThreadRunnableFactory; import com.djrapitops.plugin.task.thread.ThreadRunnableFactory;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import utilities.Teardown;
import utilities.mocks.objects.TestLogger; import utilities.mocks.objects.TestLogger;
import java.io.File; import java.io.File;
@ -32,7 +31,6 @@ public class SpongeMockUtil extends MockUtil {
} }
public static SpongeMockUtil setUp() { public static SpongeMockUtil setUp() {
Teardown.resetSettingsTempValues();
return new SpongeMockUtil().mockPlugin(); return new SpongeMockUtil().mockPlugin();
} }