diff --git a/Plan/dependency-reduced-pom.xml b/Plan/dependency-reduced-pom.xml index d42de35ea..736538ff4 100644 --- a/Plan/dependency-reduced-pom.xml +++ b/Plan/dependency-reduced-pom.xml @@ -3,9 +3,10 @@ 4.0.0 com.djrapitops Plan - 3.6.0 + 3.6.3 ${basedir}/src + ${basedir}/test clean package install @@ -16,6 +17,7 @@ *.js *.yml *.html + *.txt @@ -70,18 +72,9 @@ - org.pitest - pitest-maven - 1.1.8 - - - main.java.com.djrapitops.plan.* - - - test.java.main.java.com.djrapitops.plan.* - - 1000 - + org.jacoco + jacoco-maven-plugin + 0.7.9 maven-checkstyle-plugin @@ -181,6 +174,9 @@ java + ${project.basedir}/target/jacoco.exec + reuseReports + jacoco 1.8 UTF-8 1.8 diff --git a/Plan/pom.xml b/Plan/pom.xml index 1595f4805..629025f40 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -100,6 +100,7 @@ clean package install ${project.name} ${basedir}/src + ${basedir}/test . @@ -165,18 +166,9 @@ - org.pitest - pitest-maven - 1.1.8 - - - main.java.com.djrapitops.plan.* - - - test.java.main.java.com.djrapitops.plan.* - - 1000 - + org.jacoco + jacoco-maven-plugin + 0.7.9 org.apache.maven.plugins @@ -202,5 +194,8 @@ 1.8 1.8 java + jacoco + reuseReports + ${project.basedir}/target/jacoco.exec \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/UserData.java b/Plan/src/main/java/com/djrapitops/plan/data/UserData.java index 3c3d8dda8..d67bf4fe4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/UserData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/UserData.java @@ -212,8 +212,8 @@ public class UserData { if (addIps.isEmpty()) { return; } - ips.addAll(addIps.stream().filter(Verify::notNull).collect(Collectors.toList())); + ips.addAll(addIps.stream().filter(Verify::notNull).collect(Collectors.toList())); } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java index 008a58c3e..6388ae57d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java @@ -54,8 +54,8 @@ public class PluginConfigSectionHandler { String pluginName = dataSource.getSourcePlugin(); if (!section.getBoolean(pluginName + ".Enabled")) { return false; - } + String source = dataSource.placeholder; return section.getBoolean(pluginName + ".Data." + source); } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java index be713b4e8..e45b93153 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java @@ -60,7 +60,7 @@ public class AnalysisCacheHandler { * @return true if there is data in the cache. */ public boolean isCached() { - return (cache != null); + return cache != null; } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java index e26e44fcc..efa4701d2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/GeolocationCacheHandler.java @@ -9,7 +9,6 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; -import java.util.Map; /** * This class contains the geolocation cache. @@ -48,12 +47,10 @@ public class GeolocationCacheHandler { public static String getCountry(String ipAddress) { Log.debug("Started country retrieval from IP Address " + ipAddress); - Map geolocationMap = geolocationCache.asMap(); - String country = geolocationMap.get(ipAddress); - - Log.debug("Got country from " + ipAddress + " out of cache: " + country + " (if null, country wasn't cached)"); + String country = getCachedCountry(ipAddress); if (country != null) { + Log.debug("Got cached country from IP Address " + ipAddress + ": " + country); return country; } else { country = getUncachedCountry(ipAddress); @@ -77,7 +74,7 @@ public class GeolocationCacheHandler { * @see http://freegeoip.net * @see #getCountry(String) */ - private static String getUncachedCountry(String ipAddress) { + public static String getUncachedCountry(String ipAddress) { Benchmark.start("getUncachedCountry"); URL url; @@ -104,4 +101,24 @@ public class GeolocationCacheHandler { Benchmark.stop("getUncachedCountry"); } } + + /** + * Returns the cached country + * + * @param ipAddress The IP Address which is retrieved out of the cache + * @return The cached country, {@code null} if the country is not cached + */ + public static String getCachedCountry(String ipAddress) { + return geolocationCache.getIfPresent(ipAddress); + } + + /** + * Checks if the IP Address is cached + * + * @param ipAddress The IP Address which is checked + * @return true if the IP Address is cached + */ + public static boolean isCached(String ipAddress) { + return geolocationCache.asMap().containsKey(ipAddress); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/PageCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/PageCacheHandler.java index e913c34c9..55af7836a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/PageCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/PageCacheHandler.java @@ -4,6 +4,9 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import main.java.com.djrapitops.plan.ui.webserver.response.Response; +import java.util.Map; +import java.util.function.Predicate; + /** * This class contains the page cache. *

@@ -67,10 +70,35 @@ public class PageCacheHandler { pageCache.put(identifier, response); } + /** + * Checks if the page is cached. + * + * @param identifier The identifier of the page + * @return true if the page is cached + */ + public static boolean isCached(String identifier) { + return pageCache.asMap().containsKey(identifier); + } + + /** + * Removes all of the elements of this cache that satisfy the given predicate. + * + * @param filter a predicate which returns true for entries to be removed + */ + public static void removeIf(Predicate filter) { + Map pageCacheMap = pageCache.asMap(); + + for (String identifier : pageCacheMap.keySet()) { + if (filter.test(identifier)) { + pageCache.invalidate(identifier); + } + } + } + /** * Clears the cache from all its contents. */ public static void clearCache() { - pageCache.asMap().clear(); + pageCache.invalidateAll(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java index 4d4d35b4c..23e521a86 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java @@ -50,8 +50,7 @@ public class DataCacheGetQueue extends Queue } boolean containsUUIDtoBeCached(UUID uuid) { - return uuid != null - && queue.stream() + return uuid != null && queue.stream() .map(map -> map.get(uuid)) .filter(Objects::nonNull) .anyMatch(list -> list.size() >= 2); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java index 75042f01f..ce4535c22 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java @@ -4,6 +4,8 @@ import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.KillData; import main.java.com.djrapitops.plan.data.UserData; +import org.apache.commons.lang3.text.WordUtils; +import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -54,4 +56,14 @@ public class KillHandling { data.setMobKills(data.getMobKills() + 1); } } + + /** + * Normalizes a material name + * + * @param material The material + * @return The normalized material name + */ + public static String normalizeMaterialName(Material material) { + return WordUtils.capitalizeFully(material.name(), '_').replace('_', ' '); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java index dc7f59cce..723830e56 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java @@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.data.listeners; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.cache.DataCacheHandler; +import main.java.com.djrapitops.plan.data.handling.KillHandling; import main.java.com.djrapitops.plan.data.handling.info.DeathInfo; import main.java.com.djrapitops.plan.data.handling.info.KillInfo; import main.java.com.djrapitops.plan.utilities.MiscUtils; @@ -68,7 +69,7 @@ public class PlanDeathEventListener implements Listener { } } - handler.addToPool(new KillInfo(killer.getUniqueId(), time, dead, itemInHand.name())); + handler.addToPool(new KillInfo(killer.getUniqueId(), time, dead, KillHandling.normalizeMaterialName(itemInHand))); return; } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java index 6a5333848..51b49efb4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java @@ -29,7 +29,6 @@ public class PlanGamemodeChangeListener implements Listener { */ public PlanGamemodeChangeListener(Plan plugin) { handler = plugin.getHandler(); - } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java deleted file mode 100644 index 4c4564a6c..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java +++ /dev/null @@ -1,152 +0,0 @@ -package main.java.com.djrapitops.plan.ui.webserver; - -import main.java.com.djrapitops.plan.Log; - -import java.io.*; -import java.util.Arrays; -import java.util.Optional; - -/** - * Represents a HTTP Request. - *

- * Request is read from the given InputStream. - *

- * Closing the Request closes the InputStream. (Closing Socket InputStream - * closes the socket.) - *

- * Request Strings should not be logged because they may contain base64 encoded - * user:password Authorization combinations. - * - * @author Rsl1122 - * @since 3.5.2 - */ -public class Request implements Closeable { - - private final InputStream input; - private String request; - private String target; - private String authorization; - - private Closeable close; - - /** - * Creates a new Request object. - * - * @param input InputStream to read the socket. - */ - public Request(InputStream input) { - this.input = input; - } - - /** - * Reads the information in the Request and parses required information. - *

- * Parses Request (GET, POST etc.) - *

- * Parses Target (/home/etc) - *

- * Parses Authorization (Authorization header). - * - * @throws java.io.IOException if InputStream can not be read. - */ - public void parse() throws IOException { - StringBuilder headerB = new StringBuilder(); - BufferedReader in = new BufferedReader(new InputStreamReader(input)); - close = in; - while (true) { - String line = in.readLine(); - if (line == null || line.isEmpty()) { - break; - } - headerB.append(line); - headerB.append(":::"); - } - final String requestHeader = headerB.toString(); - String[] header = requestHeader.split(":::"); - parseRequestAndTarget(header); - parseAuthorization(header); - } - - /** - * Check if the request has Authorization: Basic header. - * - * @return true/false - */ - public boolean hasAuthorization() { - return authorization != null; - } - - /** - * Returns the base64 encoded Authorization if present. - * - * @return base64 encoded user:password or null. - */ - public String getAuthorization() { - return authorization; - } - - private void parseAuthorization(String[] header) { - Optional auth = Arrays.stream(header) - .filter(l -> l.contains("Authorization: Basic ")) - .findFirst(); - if (auth.isPresent()) { - Log.debug("Found Authorization."); - authorization = auth.get().replace("Authorization: Basic ", ""); - } else { - Log.debug("Not Authorized."); - } - } - - private void parseRequestAndTarget(String[] header) { - String req = header[0]; - String[] reqLine = req.split(" "); - if (reqLine.length >= 2) { - request = reqLine[0]; - target = reqLine[1].replace("%20", " ") - .replace("%2E", "."); - ; - } else { - request = "GET"; - target = "/"; - } - } - - /** - * Used to get the request type. - * - * @return GET, POST, etc. - */ - public String getRequest() { - return request; - } - - /** - * Used to get the target. - * - * @return for example '/home/etc' - */ - public String getTarget() { - return target; - } - - /** - * Closes the Request. - *

- * Closes the InputStream. - * - * @throws IOException if the stream can not be closed. - */ - @Override - public void close() throws IOException { - close.close(); - } - - @Override - public String toString() { - return "Request{" + - "request='" + request + '\'' + - ", target='" + target + '\'' + - ", authorization='" + authorization + '\'' + - '}'; - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java index cb22979d5..2c32c3cd4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java @@ -38,4 +38,22 @@ public abstract class Response { public int getCode() { return header == null ? 500 : Integer.parseInt(header.split(" ")[1]); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Response response = (Response) o; + + return (header != null ? header.equals(response.header) : response.header == null) + && (content != null ? content.equals(response.content) : response.content == null); + } + + @Override + public int hashCode() { + int result = header != null ? header.hashCode() : 0; + result = 31 * result + (content != null ? content.hashCode() : 0); + return result; + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index 182c26606..103be7822 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -165,8 +165,10 @@ public class Analysis { Log.info(Locale.get(Msg.ANALYSIS_FINISHED).parse(String.valueOf(time), HtmlUtils.getServerAnalysisUrlWithProtocol())); } + PageCacheHandler.removeIf(identifier -> identifier.startsWith("inspectPage: ")); PageCacheHandler.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getUiServer().getDataReqHandler())); PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin)); + ExportUtility.export(analysisData, rawData); } catch (Exception e) { Log.toLog(this.getClass().getName(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java index bdaa55a54..0b2876b77 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java @@ -90,12 +90,7 @@ public class DumpLog { * @param line The content of the line */ private void addLine(CharSequence line) { - if (line == null) { - lines.add("\n"); - return; - } - - lines.add(line.toString()); + lines.add(line == null ? "\n" : line.toString()); } /** @@ -138,16 +133,13 @@ public class DumpLog { connection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); - wr.writeBytes(content); + wr.writeBytes(this.toString()); wr.flush(); wr.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - - String response = reader.readLine(); - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(response); + JSONObject json = (JSONObject) parser.parse(reader.readLine()); return "https://hastebin.com/" + json.get("key"); } catch (IOException | ParseException e) { diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/PermissionsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/PermissionsTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/PermissionsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/PermissionsTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/SettingsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/SettingsTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/SettingsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/SettingsTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/KillDataTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/KillDataTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/KillDataTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/KillDataTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/SessionDataTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/SessionDataTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/SessionDataTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/SessionDataTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/UserDataTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/UserDataTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/UserDataTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/UserDataTest.java index 076f4a4dc..4ca06f744 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/UserDataTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/UserDataTest.java @@ -10,8 +10,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import test.java.utils.MockUtils; import test.java.utils.TestInit; +import test.java.utils.MockUtils; import java.io.IOException; import java.net.InetAddress; diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/additional/AnalysisTypeTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/additional/AnalysisTypeTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/additional/AnalysisTypeTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/additional/AnalysisTypeTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/GeolocationCacheTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/GeolocationCacheTest.java new file mode 100644 index 000000000..7eb8afef7 --- /dev/null +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/GeolocationCacheTest.java @@ -0,0 +1,76 @@ +package test.java.main.java.com.djrapitops.plan.data.cache; + +import main.java.com.djrapitops.plan.data.cache.GeolocationCacheHandler; +import org.bukkit.plugin.java.JavaPlugin; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import test.java.utils.TestInit; + +import java.util.HashMap; +import java.util.Map; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; + +/** + * @author Fuzzlemann + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(JavaPlugin.class) +public class GeolocationCacheTest { + + private Map ipsToCountries = new HashMap<>(); + + @Before + public void setUp() { + ipsToCountries.put("8.8.8.8", "United States"); + ipsToCountries.put("8.8.4.4", "United States"); + ipsToCountries.put("4.4.2.2", "United States"); + ipsToCountries.put("208.67.222.222", "United States"); + ipsToCountries.put("208.67.220.220", "United States"); + ipsToCountries.put("205.210.42.205", "Canada"); + ipsToCountries.put("64.68.200.200", "Canada"); + ipsToCountries.put("0.0.0.0", "Not Known"); + ipsToCountries.put("127.0.0.1", "Not Known"); + } + + @Test + public void testCountryGetting() throws Exception { + TestInit.init(); + + for (Map.Entry entry : ipsToCountries.entrySet()) { + String ip = entry.getKey(); + String expCountry = entry.getValue(); + + String country = GeolocationCacheHandler.getUncachedCountry(ip); + + assertEquals(country, expCountry); + } + } + + @Test + public void testCaching() throws Exception { + TestInit.init(); + + for (Map.Entry entry : ipsToCountries.entrySet()) { + String ip = entry.getKey(); + String expIp = entry.getValue(); + + String countryFirstCall = GeolocationCacheHandler.getUncachedCountry(ip); + assertFalse(GeolocationCacheHandler.isCached(ip)); + + String countrySecondCall = GeolocationCacheHandler.getCountry(ip); + assertTrue(GeolocationCacheHandler.isCached(ip)); + + String countryThirdCall = GeolocationCacheHandler.getCachedCountry(ip); + + assertEquals(countryFirstCall, countrySecondCall); + assertEquals(countrySecondCall, countryThirdCall); + assertEquals(countryThirdCall, expIp); + } + } +} diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/PageCacheHandlerTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/PageCacheHandlerTest.java new file mode 100644 index 000000000..fef18ad14 --- /dev/null +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/PageCacheHandlerTest.java @@ -0,0 +1,62 @@ +package test.java.main.java.com.djrapitops.plan.data.cache; + +import main.java.com.djrapitops.plan.data.cache.PageCacheHandler; +import main.java.com.djrapitops.plan.data.cache.PageLoader; +import main.java.com.djrapitops.plan.ui.webserver.response.Response; +import org.junit.Test; +import test.java.utils.RandomData; + +import static junit.framework.TestCase.*; + +/** + * @author Fuzzlemann + */ +public class PageCacheHandlerTest { + private final String IDENTIFIER = RandomData.randomString(10); + private final String RESPONSE_STRING = RandomData.randomString(10); + private final Response RESPONSE = new Response() { + @Override + public String getResponse() { + return RESPONSE_STRING; + } + }; + private final PageLoader LOADER = () -> RESPONSE; + + @Test + public void testCreateResponse() { + String expResponse = RESPONSE.getResponse(); + String response = LOADER.createResponse().getResponse(); + + assertEquals(expResponse, response); + } + + @Test + public void testCache() { + Response expResponse = LOADER.createResponse(); + + assertFalse(PageCacheHandler.isCached(IDENTIFIER)); + + Response response = PageCacheHandler.loadPage(IDENTIFIER, LOADER); + assertTrue(PageCacheHandler.isCached(IDENTIFIER)); + + assertEquals(expResponse, response); + } + + @Test + public void testClearCache() { + PageCacheHandler.cachePage(IDENTIFIER, LOADER); + assertTrue(PageCacheHandler.isCached(IDENTIFIER)); + + PageCacheHandler.clearCache(); + assertFalse(PageCacheHandler.isCached(IDENTIFIER)); + } + + @Test + public void testRemoveIf() { + PageCacheHandler.cachePage(IDENTIFIER, LOADER); + assertTrue(PageCacheHandler.isCached(IDENTIFIER)); + + PageCacheHandler.removeIf(identifier -> identifier.equals(IDENTIFIER)); + assertFalse(PageCacheHandler.isCached(IDENTIFIER)); + } +} diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/SessionCacheTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/SessionCacheTest.java similarity index 95% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/SessionCacheTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/SessionCacheTest.java index 9815f778d..c527869c1 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/SessionCacheTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/SessionCacheTest.java @@ -36,18 +36,12 @@ public class SessionCacheTest { public SessionCacheTest() { } - /** - * - */ @Before public void setUp() throws Exception { TestInit.init(); test = new SessionCache(); } - /** - * - */ @Test public void testStartSession() { UUID uuid = MockUtils.getPlayerUUID(); @@ -55,9 +49,6 @@ public class SessionCacheTest { assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid)); } - /** - * - */ @Test public void testEndSession() { UUID uuid = MockUtils.getPlayerUUID(); @@ -69,9 +60,6 @@ public class SessionCacheTest { assertTrue("Session not valid", testSession.isValid()); } - /** - * - */ @Test public void testAddSession() { UUID uuid = MockUtils.getPlayerUUID(); diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueueTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueueTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueueTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueueTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/ChatHandlingTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/ChatHandlingTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/ChatHandlingTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/ChatHandlingTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java similarity index 92% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java index 6663fea02..8f9971caa 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java @@ -14,6 +14,7 @@ import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.databases.SQLiteDB; import main.java.com.djrapitops.plan.database.tables.UsersTable; import main.java.com.djrapitops.plan.utilities.MiscUtils; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.junit.After; @@ -132,4 +133,13 @@ public class KillHandlingTest { assertEquals(exp, result); } + @Test + public void testNormalizeMaterialName() { + Material material = Material.GOLD_SWORD; + String name = material.name(); + String normalizedName = KillHandling.normalizeMaterialName(material); + + assertEquals(name, "GOLD_SWORD"); + assertEquals(normalizedName, "Gold Sword"); + } } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/LoginHandlingTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/LoginHandlingTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/LoginHandlingTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/LoginHandlingTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/LogoutHandlingTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/LogoutHandlingTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/LogoutHandlingTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/LogoutHandlingTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ChatInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/ChatInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ChatInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/ChatInfoTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/DeathInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/DeathInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/DeathInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/DeathInfoTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/HandlingInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/HandlingInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/HandlingInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/HandlingInfoTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/InfoUuidCorrectionTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/InfoUuidCorrectionTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/InfoUuidCorrectionTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/InfoUuidCorrectionTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KickInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/KickInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KickInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/KickInfoTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java index c4c47cb9f..8c4a4f62e 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java @@ -20,8 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import test.java.utils.MockUtils; import test.java.utils.TestInit; +import test.java.utils.MockUtils; import java.sql.SQLException; import java.util.UUID; diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java index 5d0ae3789..3b031fd41 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java @@ -14,8 +14,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import test.java.utils.MockUtils; import test.java.utils.TestInit; +import test.java.utils.MockUtils; import java.net.InetAddress; import java.net.UnknownHostException; diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/time/GMTimesTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/time/GMTimesTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/data/time/GMTimesTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/data/time/GMTimesTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DBUtilsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/database/DBUtilsTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/database/DBUtilsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/database/DBUtilsTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseCommitTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseCommitTest.java similarity index 90% rename from Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseCommitTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseCommitTest.java index a8047bd79..fc034fc37 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseCommitTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseCommitTest.java @@ -29,18 +29,18 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @RunWith(PowerMockRunner.class) @PrepareForTest(JavaPlugin.class) public class DatabaseCommitTest { - private Plan plan; private Database db; private int rows; - @Before public void setUp() throws Exception { TestInit t = TestInit.init(); @@ -89,7 +89,7 @@ public class DatabaseCommitTest { db.saveCommandUse(c); db.close(); db.init(); - assertTrue(!db.getCommandUse().isEmpty()); + assertFalse(db.getCommandUse().isEmpty()); } @Test @@ -99,7 +99,7 @@ public class DatabaseCommitTest { db.getTpsTable().saveTPSData(tps); db.close(); db.init(); - assertTrue(!db.getTpsTable().getTPSData().isEmpty()); + assertFalse(db.getTpsTable().getTPSData().isEmpty()); } @Test @@ -109,7 +109,7 @@ public class DatabaseCommitTest { db.saveUserData(userData); db.close(); db.init(); - assertTrue(!db.getUserDataForUUIDS(Collections.singletonList(MockUtils.getPlayerUUID())).isEmpty()); + assertFalse(db.getUserDataForUUIDS(Collections.singletonList(MockUtils.getPlayerUUID())).isEmpty()); } @Test @@ -120,17 +120,16 @@ public class DatabaseCommitTest { db.saveMultipleUserData(data); db.close(); db.init(); - assertTrue(!db.getUserDataForUUIDS(uuids).isEmpty()); + assertFalse(db.getUserDataForUUIDS(uuids).isEmpty()); } @Test public void testCommitToDBFile5() throws SQLException, PassEncryptUtil.CannotPerformOperationException { db.init(); - List data = RandomData.randomUserData(); WebUser webUser = new WebUser("Test", "SHA1:rioegnorgiengoieng:oiegnoeigneo:352", 0); db.getSecurityTable().addNewUser(webUser); db.close(); db.init(); - assertTrue(webUser.equals(db.getSecurityTable().getWebUser("Test"))); + assertEquals(webUser, db.getSecurityTable().getWebUser("Test")); } } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/ui/HtmlTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/ui/HtmlTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/ui/HtmlTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/ui/HtmlTest.java diff --git a/Plan/src/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 similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/ui/graphs/PlayerActivityGraphCreatorTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/PlayerActivityGraphCreatorTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/FormatUtilsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/FormatUtilsTest.java similarity index 91% rename from Plan/src/test/java/main/java/com/djrapitops/plan/utilities/FormatUtilsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/utilities/FormatUtilsTest.java index ea4c64314..5709a9153 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/FormatUtilsTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/FormatUtilsTest.java @@ -5,14 +5,14 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import test.java.utils.MockUtils; import test.java.utils.TestInit; +import test.java.utils.MockUtils; +import java.text.SimpleDateFormat; import java.util.Date; import static org.junit.Assert.*; @@ -63,26 +63,30 @@ public class FormatUtilsTest { assertEquals(expResult, result); } - /** - * - */ @Test - @Ignore public void testFormatTimeStamp() { + SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd',' HH':'mm"); + + Date date = new Date(); + date.setTime(0); + + String expResult = dateFormat.format(date); + long epochZero = 0L; - String expResult = "Jan 01, 01:00"; String result = FormatUtils.formatTimeStamp(epochZero); assertEquals(expResult, result); } - /** - * - */ @Test - @Ignore public void testFormatTimeStampYear() { + SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd YYYY',' HH':'mm"); + + Date date = new Date(); + date.setTime(0); + + String expResult = dateFormat.format(date); + long epochZero = 0L; - String expResult = "Jan 01 1970, 01:00"; String result = FormatUtils.formatTimeStampYear(epochZero); assertEquals(expResult, result); } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/MiscUtilsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/MiscUtilsTest.java similarity index 95% rename from Plan/src/test/java/main/java/com/djrapitops/plan/utilities/MiscUtilsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/utilities/MiscUtilsTest.java index b19bec2f7..5a5717628 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/MiscUtilsTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/MiscUtilsTest.java @@ -43,9 +43,6 @@ public class MiscUtilsTest { public void setUp() throws Exception { } - /** - * - */ @Test public void testGetPlayerDisplaynameArgsPerm() { String[] args = new String[]{"Rsl1122", "Test"}; @@ -55,9 +52,6 @@ public class MiscUtilsTest { assertEquals(expResult, result); } - /** - * - */ @Test public void testGetPlayerDisplaynameArgsNoPerm() { String[] args = new String[]{"Rsl1122", "Test"}; @@ -67,9 +61,6 @@ public class MiscUtilsTest { assertEquals(expResult, result); } - /** - * - */ @Test public void testGetPlayerDisplaynameNoArgsPerm() { String[] args = new String[]{}; @@ -79,9 +70,6 @@ public class MiscUtilsTest { assertEquals(expResult, result); } - /** - * - */ @Test public void testGetPlayerDisplaynameNoArgsNoPerm() { String[] args = new String[]{}; @@ -91,9 +79,6 @@ public class MiscUtilsTest { assertEquals(expResult, result); } - /** - * - */ @Test public void testGetPlayerDisplaynameOwnNameNoPerm() { String[] args = new String[]{"testname2"}; @@ -103,9 +88,6 @@ public class MiscUtilsTest { assertEquals(expResult, result); } - /** - * - */ @Test public void testGetPlayerDisplaynameConsole() { String[] args = new String[]{"TestConsoleSender"}; @@ -115,9 +97,6 @@ public class MiscUtilsTest { assertEquals(expResult, result); } - /** - * - */ @Test @Ignore("DB mock") public void testGetMatchingDisplaynames() throws Exception { @@ -131,9 +110,6 @@ public class MiscUtilsTest { assertEquals(exp2, result.get(1)); } - /** - * - */ @Test @Ignore("DB mock") public void testGetMatchingDisplaynames2() throws Exception { diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/NewPlayerCreatorTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/NewPlayerCreatorTest.java similarity index 94% rename from Plan/src/test/java/main/java/com/djrapitops/plan/utilities/NewPlayerCreatorTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/utilities/NewPlayerCreatorTest.java index 84159b03f..e5c5d585c 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/NewPlayerCreatorTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/NewPlayerCreatorTest.java @@ -55,7 +55,7 @@ public class NewPlayerCreatorTest { * */ @Test - public void testCreateNewPlayer_Player() { + public void testCreateNewPlayer() { IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer2()); UserData result = NewPlayerCreator.createNewOfflinePlayer(p); UserData exp = new UserData(p); @@ -73,7 +73,7 @@ public class NewPlayerCreatorTest { * */ @Test - public void testCreateNewPlayer_OfflinePlayer() { + public void testCreateNewOfflinePlayer() { IPlayer p = BukkitPlayer.wrap(MockUtils.mockPlayer2()); UserData result = NewPlayerCreator.createNewPlayer(p); UserData exp = new UserData(p); @@ -91,7 +91,7 @@ public class NewPlayerCreatorTest { * */ @Test - public void testCreateNewPlayer_OfflinePlayer_Gamemode() { + public void testCreateNewPlayerWithGameMode() { IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer()); UserData result = NewPlayerCreator.createNewPlayer(p, Gamemode.CREATIVE); UserData exp = new UserData(p); diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtilsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtilsTest.java similarity index 100% rename from Plan/src/test/java/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtilsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtilsTest.java diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/analysis/MathUtilsTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/analysis/MathUtilsTest.java similarity index 93% rename from Plan/src/test/java/main/java/com/djrapitops/plan/utilities/analysis/MathUtilsTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/utilities/analysis/MathUtilsTest.java index 6424f233c..96ca6279e 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/analysis/MathUtilsTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/analysis/MathUtilsTest.java @@ -56,7 +56,7 @@ public class MathUtilsTest { * */ @Test - public void testAverageLong_Collection() { + public void testAverageLongCollection() { List l = new ArrayList<>(); double exp = 10; l.add(0L); @@ -154,4 +154,12 @@ public class MathUtilsTest { double result = MathUtils.sumDouble(l.stream()); assertTrue(result + "/" + exp, Double.compare(exp, result) == 0); } + + @Test + public void testRoundDouble() { + double exp = 412.5123125123; + double roundedExp = MathUtils.round(exp); + + assertTrue("", Double.compare(412.51, roundedExp) == 0); + } } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java similarity index 99% rename from Plan/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java rename to Plan/test/test/java/main/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java index 082398f3d..0731b1aa0 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java @@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals; public class ComparatorTest { - private Random r = new Random(); - @Test public void testHandlingInfoComparator() { List test = RandomData.randomHandlingInfo(); diff --git a/Plan/src/test/java/utils/MockUtils.java b/Plan/test/test/java/utils/MockUtils.java similarity index 100% rename from Plan/src/test/java/utils/MockUtils.java rename to Plan/test/test/java/utils/MockUtils.java diff --git a/Plan/src/test/java/utils/RandomData.java b/Plan/test/test/java/utils/RandomData.java similarity index 98% rename from Plan/src/test/java/utils/RandomData.java rename to Plan/test/test/java/utils/RandomData.java index 5646c7256..35b3b42fc 100644 --- a/Plan/src/test/java/utils/RandomData.java +++ b/Plan/test/test/java/utils/RandomData.java @@ -31,9 +31,6 @@ public class RandomData { return test; } - /** - * Random enough. - */ public static String randomString(int size) { return RandomStringUtils.random(size); } diff --git a/Plan/src/test/java/utils/TestInit.java b/Plan/test/test/java/utils/TestInit.java similarity index 100% rename from Plan/src/test/java/utils/TestInit.java rename to Plan/test/test/java/utils/TestInit.java