From e9b06f4581f58a04ba2c99214eea25ef6780101d Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 17 Aug 2017 10:24:39 +0300 Subject: [PATCH] Removed old PlayerActivityGraphCreatorTest Fix some code smells --- .../com/djrapitops/plan/locale/Locale.java | 4 ++ .../plan/ui/webserver/WebServer.java | 4 +- .../plan/utilities/ManageUtils.java | 5 +-- .../plan/utilities/file/FileUtil.java | 4 ++ .../plan/utilities/metrics/Metrics.java | 4 +- .../PlayerActivityGraphCreatorTest.java | 44 ------------------- 6 files changed, 15 insertions(+), 50 deletions(-) delete mode 100644 Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/PlayerActivityGraphCreatorTest.java diff --git a/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java b/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java index 46f3bdc96..52275b9cb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java +++ b/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java @@ -341,6 +341,10 @@ public class Locale { private static class LocaleHolder { + private LocaleHolder() { + throw new IllegalStateException("Static variable holder class"); + } + private static Locale locale; public static Locale getLocale() { diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java index d3b1dad5a..b8fb2903d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java @@ -283,8 +283,8 @@ public class WebServer { String content = "

403 Forbidden - Access Denied

" + "

Unauthorized User.
" + "Make sure your user has the correct access level.
" - + "This page requires permission level of " + String.valueOf(required) + ",
" - + "This user has permission level of " + String.valueOf(permLevel) + "

"; + + "This page requires permission level of " + required + ",
" + + "This user has permission level of " + permLevel + "

"; response403.setContent(content); return response403; }); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java index c3fed49b9..229b673a9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java @@ -39,7 +39,7 @@ public class ManageUtils { return false; } backupDB.init(); - return clearAndCopy(backupDB, copyFromDB, uuids); + return clearAndCopy(backupDB, copyFromDB); } /** @@ -64,10 +64,9 @@ public class ManageUtils { * @param clearAndCopyToDB Database that will be cleared data will be copied * to. * @param copyFromDB Database where data will be copied from - * @param fromDBsavedUUIDs UUID collection of saved uuids in the copyFromDB * @return success? */ - public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB, Collection fromDBsavedUUIDs) { + public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB) { try { clearAndCopyToDB.removeAllData(); List allUserData = copyFromDB.getUserDataForUUIDS(copyFromDB.getSavedUUIDs()); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java index 23e7a0c15..281a58215 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java @@ -20,6 +20,10 @@ import java.util.stream.Stream; public class FileUtil { + private FileUtil() { + throw new IllegalStateException("Utility class"); + } + public static String getStringFromResource(String fileName) throws FileNotFoundException { InputStream resourceStream = null; Scanner scanner = null; diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/Metrics.java b/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/Metrics.java index fee5b030f..51b2f37df 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/Metrics.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/Metrics.java @@ -194,6 +194,8 @@ public class Metrics { * Starts the Scheduler which submits our data every 30 minutes. */ private void startSubmitting() { + final Metrics metrics = this; + final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags timer.scheduleAtFixedRate(new TimerTask() { @Override @@ -204,7 +206,7 @@ public class Metrics { } // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, () -> submitData()); + Bukkit.getScheduler().runTask(plugin, metrics::submitData); } }, TimeAmount.MINUTE.ms() * 5, TimeAmount.MINUTE.ms() * 30); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/PlayerActivityGraphCreatorTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/PlayerActivityGraphCreatorTest.java deleted file mode 100644 index ea2a8cb6e..000000000 --- a/Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/PlayerActivityGraphCreatorTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package test.java.main.java.com.djrapitops.plan.ui.graphs; - -import main.java.com.djrapitops.plan.data.SessionData; -import org.junit.Before; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Random; - -/** - * @author Rsl1122 - */ -public class PlayerActivityGraphCreatorTest { - - /** - * - */ - public PlayerActivityGraphCreatorTest() { - } - - /** - * @return - */ - public static List createRandomSessionDataList() { - List list = new ArrayList<>(); - Random r = new Random(); - long now = new Date().toInstant().getEpochSecond(); - while (list.size() < 500) { - int randomStart = r.nextInt(2592000); - long start = now - (long) (randomStart + 10); - long end = start + (long) r.nextInt(randomStart); - list.add(new SessionData((start * (long) 1000), (end * (long) 1000))); - } - return list; - } - - /** - * - */ - @Before - public void setUp() throws Exception { - } -}