mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-15 04:31:34 +01:00
Merge pull request #244 from Fuzzlemann/master
PR for 3.6.3 (Fuzzlemann) (3)
This commit is contained in:
commit
45aaaaafeb
@ -3,9 +3,10 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.djrapitops</groupId>
|
<groupId>com.djrapitops</groupId>
|
||||||
<artifactId>Plan</artifactId>
|
<artifactId>Plan</artifactId>
|
||||||
<version>3.6.0</version>
|
<version>3.6.3</version>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>${basedir}/src</sourceDirectory>
|
<sourceDirectory>${basedir}/src</sourceDirectory>
|
||||||
|
<testSourceDirectory>${basedir}/test</testSourceDirectory>
|
||||||
<defaultGoal>clean package install</defaultGoal>
|
<defaultGoal>clean package install</defaultGoal>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
@ -16,6 +17,7 @@
|
|||||||
<include>*.js</include>
|
<include>*.js</include>
|
||||||
<include>*.yml</include>
|
<include>*.yml</include>
|
||||||
<include>*.html</include>
|
<include>*.html</include>
|
||||||
|
<include>*.txt</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
@ -70,18 +72,9 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.pitest</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>pitest-maven</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>1.1.8</version>
|
<version>0.7.9</version>
|
||||||
<configuration>
|
|
||||||
<targetClasses>
|
|
||||||
<param>main.java.com.djrapitops.plan.*</param>
|
|
||||||
</targetClasses>
|
|
||||||
<targetTests>
|
|
||||||
<param>test.java.main.java.com.djrapitops.plan.*</param>
|
|
||||||
</targetTests>
|
|
||||||
<timeoutConstant>1000</timeoutConstant>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
@ -181,6 +174,9 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<sonar.language>java</sonar.language>
|
<sonar.language>java</sonar.language>
|
||||||
|
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
|
||||||
|
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
|
||||||
|
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
19
Plan/pom.xml
19
Plan/pom.xml
@ -100,6 +100,7 @@
|
|||||||
<defaultGoal>clean package install</defaultGoal>
|
<defaultGoal>clean package install</defaultGoal>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
<sourceDirectory>${basedir}/src</sourceDirectory>
|
<sourceDirectory>${basedir}/src</sourceDirectory>
|
||||||
|
<testSourceDirectory>${basedir}/test</testSourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<targetPath>.</targetPath>
|
<targetPath>.</targetPath>
|
||||||
@ -165,18 +166,9 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.pitest</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>pitest-maven</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>1.1.8</version>
|
<version>0.7.9</version>
|
||||||
<configuration>
|
|
||||||
<targetClasses>
|
|
||||||
<param>main.java.com.djrapitops.plan.*</param>
|
|
||||||
</targetClasses>
|
|
||||||
<targetTests>
|
|
||||||
<param>test.java.main.java.com.djrapitops.plan.*</param>
|
|
||||||
</targetTests>
|
|
||||||
<timeoutConstant>1000</timeoutConstant>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@ -202,5 +194,8 @@
|
|||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<sonar.language>java</sonar.language>
|
<sonar.language>java</sonar.language>
|
||||||
|
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
|
||||||
|
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
|
||||||
|
<sonar.jacoco.reportPaths>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPaths>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
@ -212,8 +212,8 @@ public class UserData {
|
|||||||
if (addIps.isEmpty()) {
|
if (addIps.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ips.addAll(addIps.stream().filter(Verify::notNull).collect(Collectors.toList()));
|
|
||||||
|
|
||||||
|
ips.addAll(addIps.stream().filter(Verify::notNull).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,8 +54,8 @@ public class PluginConfigSectionHandler {
|
|||||||
String pluginName = dataSource.getSourcePlugin();
|
String pluginName = dataSource.getSourcePlugin();
|
||||||
if (!section.getBoolean(pluginName + ".Enabled")) {
|
if (!section.getBoolean(pluginName + ".Enabled")) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String source = dataSource.placeholder;
|
String source = dataSource.placeholder;
|
||||||
return section.getBoolean(pluginName + ".Data." + source);
|
return section.getBoolean(pluginName + ".Data." + source);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class AnalysisCacheHandler {
|
|||||||
* @return true if there is data in the cache.
|
* @return true if there is data in the cache.
|
||||||
*/
|
*/
|
||||||
public boolean isCached() {
|
public boolean isCached() {
|
||||||
return (cache != null);
|
return cache != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,6 @@ import java.io.BufferedReader;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains the geolocation cache.
|
* This class contains the geolocation cache.
|
||||||
@ -48,12 +47,10 @@ public class GeolocationCacheHandler {
|
|||||||
public static String getCountry(String ipAddress) {
|
public static String getCountry(String ipAddress) {
|
||||||
Log.debug("Started country retrieval from IP Address " + ipAddress);
|
Log.debug("Started country retrieval from IP Address " + ipAddress);
|
||||||
|
|
||||||
Map<String, String> geolocationMap = geolocationCache.asMap();
|
String country = getCachedCountry(ipAddress);
|
||||||
String country = geolocationMap.get(ipAddress);
|
|
||||||
|
|
||||||
Log.debug("Got country from " + ipAddress + " out of cache: " + country + " (if null, country wasn't cached)");
|
|
||||||
|
|
||||||
if (country != null) {
|
if (country != null) {
|
||||||
|
Log.debug("Got cached country from IP Address " + ipAddress + ": " + country);
|
||||||
return country;
|
return country;
|
||||||
} else {
|
} else {
|
||||||
country = getUncachedCountry(ipAddress);
|
country = getUncachedCountry(ipAddress);
|
||||||
@ -77,7 +74,7 @@ public class GeolocationCacheHandler {
|
|||||||
* @see <a href="http://freegeoip.net">http://freegeoip.net</a>
|
* @see <a href="http://freegeoip.net">http://freegeoip.net</a>
|
||||||
* @see #getCountry(String)
|
* @see #getCountry(String)
|
||||||
*/
|
*/
|
||||||
private static String getUncachedCountry(String ipAddress) {
|
public static String getUncachedCountry(String ipAddress) {
|
||||||
Benchmark.start("getUncachedCountry");
|
Benchmark.start("getUncachedCountry");
|
||||||
|
|
||||||
URL url;
|
URL url;
|
||||||
@ -104,4 +101,24 @@ public class GeolocationCacheHandler {
|
|||||||
Benchmark.stop("getUncachedCountry");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ import com.google.common.cache.Cache;
|
|||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import main.java.com.djrapitops.plan.ui.webserver.response.Response;
|
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.
|
* This class contains the page cache.
|
||||||
* <p>
|
* <p>
|
||||||
@ -67,10 +70,35 @@ public class PageCacheHandler {
|
|||||||
pageCache.put(identifier, response);
|
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<String> filter) {
|
||||||
|
Map<String, Response> pageCacheMap = pageCache.asMap();
|
||||||
|
|
||||||
|
for (String identifier : pageCacheMap.keySet()) {
|
||||||
|
if (filter.test(identifier)) {
|
||||||
|
pageCache.invalidate(identifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the cache from all its contents.
|
* Clears the cache from all its contents.
|
||||||
*/
|
*/
|
||||||
public static void clearCache() {
|
public static void clearCache() {
|
||||||
pageCache.asMap().clear();
|
pageCache.invalidateAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,7 @@ public class DataCacheGetQueue extends Queue<Map<UUID, List<DBCallableProcessor>
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean containsUUIDtoBeCached(UUID uuid) {
|
boolean containsUUIDtoBeCached(UUID uuid) {
|
||||||
return uuid != null
|
return uuid != null && queue.stream()
|
||||||
&& queue.stream()
|
|
||||||
.map(map -> map.get(uuid))
|
.map(map -> map.get(uuid))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.anyMatch(list -> list.size() >= 2);
|
.anyMatch(list -> list.size() >= 2);
|
||||||
|
@ -4,6 +4,8 @@ import main.java.com.djrapitops.plan.Log;
|
|||||||
import main.java.com.djrapitops.plan.Plan;
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
import main.java.com.djrapitops.plan.data.KillData;
|
import main.java.com.djrapitops.plan.data.KillData;
|
||||||
import main.java.com.djrapitops.plan.data.UserData;
|
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.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -54,4 +56,14 @@ public class KillHandling {
|
|||||||
data.setMobKills(data.getMobKills() + 1);
|
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('_', ' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.Plan;
|
||||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
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.DeathInfo;
|
||||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ public class PlanGamemodeChangeListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
public PlanGamemodeChangeListener(Plan plugin) {
|
public PlanGamemodeChangeListener(Plan plugin) {
|
||||||
handler = plugin.getHandler();
|
handler = plugin.getHandler();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.
|
|
||||||
* <p>
|
|
||||||
* Request is read from the given InputStream.
|
|
||||||
* <p>
|
|
||||||
* Closing the Request closes the InputStream. (Closing Socket InputStream
|
|
||||||
* closes the socket.)
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
* <p>
|
|
||||||
* Parses Request (GET, POST etc.)
|
|
||||||
* <p>
|
|
||||||
* Parses Target (/home/etc)
|
|
||||||
* <p>
|
|
||||||
* 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<String> 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.
|
|
||||||
* <p>
|
|
||||||
* 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 + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -38,4 +38,22 @@ public abstract class Response {
|
|||||||
public int getCode() {
|
public int getCode() {
|
||||||
return header == null ? 500 : Integer.parseInt(header.split(" ")[1]);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,8 +165,10 @@ public class Analysis {
|
|||||||
Log.info(Locale.get(Msg.ANALYSIS_FINISHED).parse(String.valueOf(time), HtmlUtils.getServerAnalysisUrlWithProtocol()));
|
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("analysisPage", () -> new AnalysisPageResponse(plugin.getUiServer().getDataReqHandler()));
|
||||||
PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin));
|
PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin));
|
||||||
|
|
||||||
ExportUtility.export(analysisData, rawData);
|
ExportUtility.export(analysisData, rawData);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
|
@ -90,12 +90,7 @@ public class DumpLog {
|
|||||||
* @param line The content of the line
|
* @param line The content of the line
|
||||||
*/
|
*/
|
||||||
private void addLine(CharSequence line) {
|
private void addLine(CharSequence line) {
|
||||||
if (line == null) {
|
lines.add(line == null ? "\n" : line.toString());
|
||||||
lines.add("\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.add(line.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,16 +133,13 @@ public class DumpLog {
|
|||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
||||||
wr.writeBytes(content);
|
wr.writeBytes(this.toString());
|
||||||
wr.flush();
|
wr.flush();
|
||||||
wr.close();
|
wr.close();
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
String response = reader.readLine();
|
|
||||||
|
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
JSONObject json = (JSONObject) parser.parse(response);
|
JSONObject json = (JSONObject) parser.parse(reader.readLine());
|
||||||
|
|
||||||
return "https://hastebin.com/" + json.get("key");
|
return "https://hastebin.com/" + json.get("key");
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
|
@ -10,8 +10,8 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import test.java.utils.MockUtils;
|
|
||||||
import test.java.utils.TestInit;
|
import test.java.utils.TestInit;
|
||||||
|
import test.java.utils.MockUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
76
Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/GeolocationCacheTest.java
vendored
Normal file
76
Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/GeolocationCacheTest.java
vendored
Normal file
@ -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<String, String> 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<String, String> 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<String, String> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/PageCacheHandlerTest.java
vendored
Normal file
62
Plan/test/test/java/main/java/com/djrapitops/plan/data/cache/PageCacheHandlerTest.java
vendored
Normal file
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -36,18 +36,12 @@ public class SessionCacheTest {
|
|||||||
public SessionCacheTest() {
|
public SessionCacheTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
TestInit.init();
|
TestInit.init();
|
||||||
test = new SessionCache();
|
test = new SessionCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartSession() {
|
public void testStartSession() {
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
UUID uuid = MockUtils.getPlayerUUID();
|
||||||
@ -55,9 +49,6 @@ public class SessionCacheTest {
|
|||||||
assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid));
|
assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testEndSession() {
|
public void testEndSession() {
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
UUID uuid = MockUtils.getPlayerUUID();
|
||||||
@ -69,9 +60,6 @@ public class SessionCacheTest {
|
|||||||
assertTrue("Session not valid", testSession.isValid());
|
assertTrue("Session not valid", testSession.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddSession() {
|
public void testAddSession() {
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
UUID uuid = MockUtils.getPlayerUUID();
|
@ -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.databases.SQLiteDB;
|
||||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -132,4 +133,13 @@ public class KillHandlingTest {
|
|||||||
assertEquals(exp, result);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
@ -20,8 +20,8 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import test.java.utils.MockUtils;
|
|
||||||
import test.java.utils.TestInit;
|
import test.java.utils.TestInit;
|
||||||
|
import test.java.utils.MockUtils;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
@ -14,8 +14,8 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import test.java.utils.MockUtils;
|
|
||||||
import test.java.utils.TestInit;
|
import test.java.utils.TestInit;
|
||||||
|
import test.java.utils.MockUtils;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
@ -29,18 +29,18 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertFalse;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest(JavaPlugin.class)
|
@PrepareForTest(JavaPlugin.class)
|
||||||
public class DatabaseCommitTest {
|
public class DatabaseCommitTest {
|
||||||
|
|
||||||
|
|
||||||
private Plan plan;
|
private Plan plan;
|
||||||
private Database db;
|
private Database db;
|
||||||
private int rows;
|
private int rows;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
TestInit t = TestInit.init();
|
TestInit t = TestInit.init();
|
||||||
@ -89,7 +89,7 @@ public class DatabaseCommitTest {
|
|||||||
db.saveCommandUse(c);
|
db.saveCommandUse(c);
|
||||||
db.close();
|
db.close();
|
||||||
db.init();
|
db.init();
|
||||||
assertTrue(!db.getCommandUse().isEmpty());
|
assertFalse(db.getCommandUse().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -99,7 +99,7 @@ public class DatabaseCommitTest {
|
|||||||
db.getTpsTable().saveTPSData(tps);
|
db.getTpsTable().saveTPSData(tps);
|
||||||
db.close();
|
db.close();
|
||||||
db.init();
|
db.init();
|
||||||
assertTrue(!db.getTpsTable().getTPSData().isEmpty());
|
assertFalse(db.getTpsTable().getTPSData().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -109,7 +109,7 @@ public class DatabaseCommitTest {
|
|||||||
db.saveUserData(userData);
|
db.saveUserData(userData);
|
||||||
db.close();
|
db.close();
|
||||||
db.init();
|
db.init();
|
||||||
assertTrue(!db.getUserDataForUUIDS(Collections.singletonList(MockUtils.getPlayerUUID())).isEmpty());
|
assertFalse(db.getUserDataForUUIDS(Collections.singletonList(MockUtils.getPlayerUUID())).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -120,17 +120,16 @@ public class DatabaseCommitTest {
|
|||||||
db.saveMultipleUserData(data);
|
db.saveMultipleUserData(data);
|
||||||
db.close();
|
db.close();
|
||||||
db.init();
|
db.init();
|
||||||
assertTrue(!db.getUserDataForUUIDS(uuids).isEmpty());
|
assertFalse(db.getUserDataForUUIDS(uuids).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommitToDBFile5() throws SQLException, PassEncryptUtil.CannotPerformOperationException {
|
public void testCommitToDBFile5() throws SQLException, PassEncryptUtil.CannotPerformOperationException {
|
||||||
db.init();
|
db.init();
|
||||||
List<UserData> data = RandomData.randomUserData();
|
|
||||||
WebUser webUser = new WebUser("Test", "SHA1:rioegnorgiengoieng:oiegnoeigneo:352", 0);
|
WebUser webUser = new WebUser("Test", "SHA1:rioegnorgiengoieng:oiegnoeigneo:352", 0);
|
||||||
db.getSecurityTable().addNewUser(webUser);
|
db.getSecurityTable().addNewUser(webUser);
|
||||||
db.close();
|
db.close();
|
||||||
db.init();
|
db.init();
|
||||||
assertTrue(webUser.equals(db.getSecurityTable().getWebUser("Test")));
|
assertEquals(webUser, db.getSecurityTable().getWebUser("Test"));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,14 +5,14 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import test.java.utils.MockUtils;
|
|
||||||
import test.java.utils.TestInit;
|
import test.java.utils.TestInit;
|
||||||
|
import test.java.utils.MockUtils;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
@ -63,26 +63,30 @@ public class FormatUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testFormatTimeStamp() {
|
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;
|
long epochZero = 0L;
|
||||||
String expResult = "Jan 01, 01:00";
|
|
||||||
String result = FormatUtils.formatTimeStamp(epochZero);
|
String result = FormatUtils.formatTimeStamp(epochZero);
|
||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testFormatTimeStampYear() {
|
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;
|
long epochZero = 0L;
|
||||||
String expResult = "Jan 01 1970, 01:00";
|
|
||||||
String result = FormatUtils.formatTimeStampYear(epochZero);
|
String result = FormatUtils.formatTimeStampYear(epochZero);
|
||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
@ -43,9 +43,6 @@ public class MiscUtilsTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerDisplaynameArgsPerm() {
|
public void testGetPlayerDisplaynameArgsPerm() {
|
||||||
String[] args = new String[]{"Rsl1122", "Test"};
|
String[] args = new String[]{"Rsl1122", "Test"};
|
||||||
@ -55,9 +52,6 @@ public class MiscUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerDisplaynameArgsNoPerm() {
|
public void testGetPlayerDisplaynameArgsNoPerm() {
|
||||||
String[] args = new String[]{"Rsl1122", "Test"};
|
String[] args = new String[]{"Rsl1122", "Test"};
|
||||||
@ -67,9 +61,6 @@ public class MiscUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerDisplaynameNoArgsPerm() {
|
public void testGetPlayerDisplaynameNoArgsPerm() {
|
||||||
String[] args = new String[]{};
|
String[] args = new String[]{};
|
||||||
@ -79,9 +70,6 @@ public class MiscUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerDisplaynameNoArgsNoPerm() {
|
public void testGetPlayerDisplaynameNoArgsNoPerm() {
|
||||||
String[] args = new String[]{};
|
String[] args = new String[]{};
|
||||||
@ -91,9 +79,6 @@ public class MiscUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerDisplaynameOwnNameNoPerm() {
|
public void testGetPlayerDisplaynameOwnNameNoPerm() {
|
||||||
String[] args = new String[]{"testname2"};
|
String[] args = new String[]{"testname2"};
|
||||||
@ -103,9 +88,6 @@ public class MiscUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerDisplaynameConsole() {
|
public void testGetPlayerDisplaynameConsole() {
|
||||||
String[] args = new String[]{"TestConsoleSender"};
|
String[] args = new String[]{"TestConsoleSender"};
|
||||||
@ -115,9 +97,6 @@ public class MiscUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("DB mock")
|
@Ignore("DB mock")
|
||||||
public void testGetMatchingDisplaynames() throws Exception {
|
public void testGetMatchingDisplaynames() throws Exception {
|
||||||
@ -131,9 +110,6 @@ public class MiscUtilsTest {
|
|||||||
assertEquals(exp2, result.get(1));
|
assertEquals(exp2, result.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("DB mock")
|
@Ignore("DB mock")
|
||||||
public void testGetMatchingDisplaynames2() throws Exception {
|
public void testGetMatchingDisplaynames2() throws Exception {
|
@ -55,7 +55,7 @@ public class NewPlayerCreatorTest {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewPlayer_Player() {
|
public void testCreateNewPlayer() {
|
||||||
IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer2());
|
IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer2());
|
||||||
UserData result = NewPlayerCreator.createNewOfflinePlayer(p);
|
UserData result = NewPlayerCreator.createNewOfflinePlayer(p);
|
||||||
UserData exp = new UserData(p);
|
UserData exp = new UserData(p);
|
||||||
@ -73,7 +73,7 @@ public class NewPlayerCreatorTest {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewPlayer_OfflinePlayer() {
|
public void testCreateNewOfflinePlayer() {
|
||||||
IPlayer p = BukkitPlayer.wrap(MockUtils.mockPlayer2());
|
IPlayer p = BukkitPlayer.wrap(MockUtils.mockPlayer2());
|
||||||
UserData result = NewPlayerCreator.createNewPlayer(p);
|
UserData result = NewPlayerCreator.createNewPlayer(p);
|
||||||
UserData exp = new UserData(p);
|
UserData exp = new UserData(p);
|
||||||
@ -91,7 +91,7 @@ public class NewPlayerCreatorTest {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewPlayer_OfflinePlayer_Gamemode() {
|
public void testCreateNewPlayerWithGameMode() {
|
||||||
IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer());
|
IOfflinePlayer p = BukkitOfflinePlayer.wrap(MockUtils.mockPlayer());
|
||||||
UserData result = NewPlayerCreator.createNewPlayer(p, Gamemode.CREATIVE);
|
UserData result = NewPlayerCreator.createNewPlayer(p, Gamemode.CREATIVE);
|
||||||
UserData exp = new UserData(p);
|
UserData exp = new UserData(p);
|
@ -56,7 +56,7 @@ public class MathUtilsTest {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAverageLong_Collection() {
|
public void testAverageLongCollection() {
|
||||||
List<Long> l = new ArrayList<>();
|
List<Long> l = new ArrayList<>();
|
||||||
double exp = 10;
|
double exp = 10;
|
||||||
l.add(0L);
|
l.add(0L);
|
||||||
@ -154,4 +154,12 @@ public class MathUtilsTest {
|
|||||||
double result = MathUtils.sumDouble(l.stream());
|
double result = MathUtils.sumDouble(l.stream());
|
||||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals;
|
|||||||
|
|
||||||
public class ComparatorTest {
|
public class ComparatorTest {
|
||||||
|
|
||||||
private Random r = new Random();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlingInfoComparator() {
|
public void testHandlingInfoComparator() {
|
||||||
List<HandlingInfo> test = RandomData.randomHandlingInfo();
|
List<HandlingInfo> test = RandomData.randomHandlingInfo();
|
@ -31,9 +31,6 @@ public class RandomData {
|
|||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Random enough.
|
|
||||||
*/
|
|
||||||
public static String randomString(int size) {
|
public static String randomString(int size) {
|
||||||
return RandomStringUtils.random(size);
|
return RandomStringUtils.random(size);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user