mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-12 19:30:44 +01:00
Further Cleanup of Tests
This commit is contained in:
parent
825bb45806
commit
dc2b139ac6
@ -5,8 +5,8 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.TestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@ -15,17 +15,13 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class PermissionsTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PermissionsTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetPermission() {
|
||||
assertEquals("plan.inspect.other", Permissions.INSPECT_OTHER.getPerm());
|
||||
public void testGetPermission() throws NoSuchFieldException, IllegalAccessException {
|
||||
for (Permissions type : Permissions.values()) {
|
||||
String exp = TestUtils.getStringFieldValue(type, "permission");
|
||||
|
||||
assertEquals(exp, type.getPermission());
|
||||
assertEquals(exp, type.getPerm());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
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;
|
||||
@ -18,14 +18,17 @@ import static junit.framework.TestCase.assertFalse;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class ServerVariableHolderTest {
|
||||
|
||||
@Test
|
||||
public void testServerVariable() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerVariable() {
|
||||
boolean usingPaper = Plan.getInstance().getVariable().isUsingPaper();
|
||||
assertFalse(usingPaper);
|
||||
|
||||
String ip = Plan.getInstance().getVariable().getIp();
|
||||
assertEquals(ip, "0.0.0.0");
|
||||
String exp = Plan.getInstance().getVariable().getIp();
|
||||
assertEquals(exp, "0.0.0.0");
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@ -25,9 +25,6 @@ import static org.junit.Assert.*;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class SettingsTest {
|
||||
|
||||
public SettingsTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
@ -39,7 +36,7 @@ public class SettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsTrue2() {
|
||||
public void testSetValue() {
|
||||
Settings gatherCommands = Settings.LOG_UNKNOWN_COMMANDS;
|
||||
|
||||
gatherCommands.setValue(false);
|
||||
@ -61,9 +58,9 @@ public class SettingsTest {
|
||||
|
||||
@Test
|
||||
public void testGetStringList() {
|
||||
List<String> exp = new ArrayList<>();
|
||||
exp.add("ExampleTown");
|
||||
List<String> exp = Collections.singletonList("ExampleTown");
|
||||
List<String> result = Settings.HIDE_TOWNS.getStringList();
|
||||
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,9 @@ public class DBUtilsTest {
|
||||
for (int i = 0; i < 21336; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
|
||||
List<List<Integer>> result = DBUtils.splitIntoBatches(list);
|
||||
|
||||
assertEquals(3, result.size());
|
||||
assertEquals(10192, result.get(0).size());
|
||||
assertEquals(10192, result.get(1).size());
|
||||
@ -39,7 +41,9 @@ public class DBUtilsTest {
|
||||
for (int i = 0; i < 10192; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
|
||||
List<List<Integer>> result = DBUtils.splitIntoBatches(list);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(10192, result.get(0).size());
|
||||
}
|
||||
@ -53,7 +57,9 @@ public class DBUtilsTest {
|
||||
map.get(i).add(j);
|
||||
}
|
||||
}
|
||||
|
||||
List<List<Container<Integer>>> result = DBUtils.splitIntoBatchesId(map);
|
||||
|
||||
assertEquals(3, result.size());
|
||||
assertEquals(10192, result.get(0).size());
|
||||
assertEquals(10192, result.get(1).size());
|
||||
|
@ -59,6 +59,7 @@ public class DatabaseCommitTest {
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Errors were caught.", rows == rowsAgain);
|
||||
}
|
||||
|
||||
|
@ -9,46 +9,31 @@ import main.java.com.djrapitops.plan.utilities.html.Html;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class HtmlTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public HtmlTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testParseWithZeroArgs() {
|
||||
Html instance = Html.SPAN;
|
||||
String expResult = "${0}</span>";
|
||||
String result = instance.parse();
|
||||
String result = Html.SPAN.parse();
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testParseStringArr() {
|
||||
Html instance = Html.SPAN;
|
||||
String expResult = "Test</span>";
|
||||
String result = instance.parse("Test");
|
||||
String result = Html.SPAN.parse("Test");
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testNoBackSlash() {
|
||||
assertTrue("Null for some reason", Html.TABLELINE_2.parse("/\\", "0") != null);
|
||||
assertNotNull(Html.TABLELINE_2.parse("/\\", "0"));
|
||||
}
|
||||
}
|
||||
|
@ -62,14 +62,8 @@ public class GraphTest {
|
||||
|
||||
Map<String, String> expected = new LinkedHashMap<>();
|
||||
|
||||
String key = null;
|
||||
for (String resultString : splittedResult) {
|
||||
if (key == null) {
|
||||
key = resultString;
|
||||
} else {
|
||||
expected.put(key, resultString);
|
||||
key = null;
|
||||
}
|
||||
for (int i = 0; i < splittedResult.length; i++) {
|
||||
expected.put(splittedResult[i++], splittedResult[i]);
|
||||
}
|
||||
|
||||
int i2 = 0;
|
||||
|
@ -9,6 +9,7 @@ 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.RandomData;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -32,8 +33,10 @@ public class FormatUtilsTest {
|
||||
@Test
|
||||
public void testFormatTimeAmount() {
|
||||
long ms = 1000L;
|
||||
|
||||
String expResult = "1s";
|
||||
String result = FormatUtils.formatTimeAmount(ms);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -44,6 +47,7 @@ public class FormatUtilsTest {
|
||||
|
||||
String expResult = "10s";
|
||||
String result = FormatUtils.formatTimeAmountDifference(before.getTime(), now.getTime());
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -58,6 +62,7 @@ public class FormatUtilsTest {
|
||||
|
||||
long epochZero = 0L;
|
||||
String result = FormatUtils.formatTimeStamp(epochZero);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -72,6 +77,7 @@ public class FormatUtilsTest {
|
||||
|
||||
long epochZero = 0L;
|
||||
String result = FormatUtils.formatTimeStampYear(epochZero);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -86,6 +92,7 @@ public class FormatUtilsTest {
|
||||
|
||||
long epochZero = 0L;
|
||||
String result = FormatUtils.formatTimeStampSecond(epochZero);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -93,7 +100,9 @@ public class FormatUtilsTest {
|
||||
public void testRemoveLetters() {
|
||||
String dataPoint = "435729847jirggu.eiwb¤#¤%¤#";
|
||||
String expResult = "435729847.";
|
||||
|
||||
String result = FormatUtils.removeLetters(dataPoint);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -101,7 +110,9 @@ public class FormatUtilsTest {
|
||||
public void testRemoveNumbers() {
|
||||
String dataPoint = "34532453.5 $";
|
||||
String expResult = "$";
|
||||
|
||||
String result = FormatUtils.removeNumbers(dataPoint);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -109,7 +120,9 @@ public class FormatUtilsTest {
|
||||
public void testRemoveNumbers2() {
|
||||
String dataPoint = "l43r4545tl43 4.5";
|
||||
String expResult = "lrtl";
|
||||
|
||||
String result = FormatUtils.removeNumbers(dataPoint);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -117,7 +130,9 @@ public class FormatUtilsTest {
|
||||
public void testParseVersionNumber() {
|
||||
String versionString = "2.10.2";
|
||||
int expResult = 21002;
|
||||
|
||||
int result = FormatUtils.parseVersionNumber(versionString);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -125,41 +140,58 @@ public class FormatUtilsTest {
|
||||
public void testVersionNumber() {
|
||||
String versionString = "2.10.2";
|
||||
String versionString2 = "2.9.3";
|
||||
|
||||
int result = FormatUtils.parseVersionNumber(versionString);
|
||||
int result2 = FormatUtils.parseVersionNumber(versionString2);
|
||||
|
||||
assertTrue("Higher version not higher", result > result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMergeArrays() {
|
||||
String[][] arrays = new String[][]{new String[]{"Test", "One"}, new String[]{"Test", "Two"}};
|
||||
String[] expResult = new String[]{"Test", "One", "Test", "Two"};
|
||||
String randomString1 = RandomData.randomString(10);
|
||||
String randomString2 = RandomData.randomString(10);
|
||||
String randomString3 = RandomData.randomString(10);
|
||||
String randomString4 = RandomData.randomString(10);
|
||||
|
||||
String[][] arrays = new String[][]{new String[]{randomString1, randomString2}, new String[]{randomString3, randomString4}};
|
||||
String[] expResult = new String[]{randomString1, randomString2, randomString3, randomString4};
|
||||
|
||||
String[] result = FormatUtils.mergeArrays(arrays);
|
||||
|
||||
assertArrayEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatLocation() {
|
||||
int randomInt = RandomData.randomInt(0, 100);
|
||||
|
||||
World mockWorld = MockUtils.mockWorld();
|
||||
Location loc = new Location(mockWorld, 0, 0, 0);
|
||||
String expResult = "x 0 z 0 in World";
|
||||
Location loc = new Location(mockWorld, randomInt, randomInt, randomInt);
|
||||
|
||||
String expResult = "x " + randomInt + " z " + randomInt + " in World";
|
||||
String result = FormatUtils.formatLocation(loc);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCutDecimals() throws Exception {
|
||||
public void testCutDecimalsWhichIsRoundedDown() throws Exception {
|
||||
double d = 0.05234;
|
||||
String expResult = "0,05";
|
||||
|
||||
String result = FormatUtils.cutDecimals(d);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCutDecimals2() throws Exception {
|
||||
public void testCutDecimalsWhichIsRoundedUp() throws Exception {
|
||||
double d = 0.05634;
|
||||
String expResult = "0,06";
|
||||
|
||||
String result = FormatUtils.cutDecimals(d);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class HtmlUtilsTest {
|
||||
public void testRemoveXSS() {
|
||||
String randomString = RandomData.randomString(10);
|
||||
|
||||
String xss = "<script>" + randomString + "</script><!--";
|
||||
String xss = "<script>" + randomString + "</script><!---->";
|
||||
String result = HtmlUtils.removeXSS(xss);
|
||||
|
||||
assertEquals(randomString, result);
|
||||
|
@ -29,47 +29,59 @@ import static org.junit.Assert.assertEquals;
|
||||
public class MiscUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameArgsPerm() {
|
||||
public void testGetPlayerDisplayNameArgsPerm() {
|
||||
String[] args = new String[]{"Rsl1122", "Test"};
|
||||
ISender sender = new BukkitCMDSender(MockUtils.mockPlayer());
|
||||
|
||||
String expResult = "Rsl1122";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameArgsNoPerm() {
|
||||
public void testGetPlayerDisplayNameArgsNoPerm() throws Exception {
|
||||
TestInit.init();
|
||||
|
||||
String[] args = new String[]{"Rsl1122", "Test"};
|
||||
ISender sender = new BukkitCMDSender(MockUtils.mockPlayer());
|
||||
ISender sender = new BukkitCMDSender(MockUtils.mockPlayer2());
|
||||
|
||||
String expResult = "Rsl1122";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameNoArgsPerm() {
|
||||
public void testGetPlayerDisplayNameNoArgsPerm() {
|
||||
String[] args = new String[]{};
|
||||
ISender sender = new BukkitCMDSender(MockUtils.mockPlayer());
|
||||
|
||||
String expResult = "TestName";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameNoArgsNoPerm() {
|
||||
public void testGetPlayerDisplayNameNoArgsNoPerm() {
|
||||
String[] args = new String[]{};
|
||||
ISender sender = new BukkitCMDSender(MockUtils.mockPlayer2());
|
||||
|
||||
String expResult = "TestName2";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameOwnNameNoPerm() {
|
||||
public void testGetPlayerDisplayNameOwnNameNoPerm() {
|
||||
String[] args = new String[]{"testname2"};
|
||||
ISender sender = new BukkitCMDSender(MockUtils.mockPlayer2());
|
||||
|
||||
String expResult = "TestName2";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@ -77,19 +89,23 @@ public class MiscUtilsTest {
|
||||
public void testGetPlayerDisplaynameConsole() {
|
||||
String[] args = new String[]{"TestConsoleSender"};
|
||||
ISender sender = new BukkitCMDSender(MockUtils.mockConsoleSender());
|
||||
|
||||
String expResult = "TestConsoleSender";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("DB mock")
|
||||
public void testGetMatchingDisplaynames() throws Exception {
|
||||
public void testGetMatchingDisplayNames() throws Exception {
|
||||
TestInit.init();
|
||||
String search = "testname";
|
||||
|
||||
String exp1 = "TestName";
|
||||
String exp2 = "TestName2";
|
||||
List<String> result = MiscUtils.getMatchingPlayerNames(search);
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(exp1, result.get(0));
|
||||
assertEquals(exp2, result.get(1));
|
||||
@ -97,11 +113,14 @@ public class MiscUtilsTest {
|
||||
|
||||
@Test
|
||||
@Ignore("DB mock")
|
||||
public void testGetMatchingDisplaynames2() throws Exception {
|
||||
public void testGetMatchingDisplayNames2() throws Exception {
|
||||
TestInit.init();
|
||||
|
||||
String search = "2";
|
||||
String exp2 = "TestName2";
|
||||
|
||||
List<String> result = MiscUtils.getMatchingPlayerNames(search);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(exp2, result.get(0));
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ public class PassEncryptTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
String password = RandomData.randomString(RandomData.randomInt(1, 20));
|
||||
for (int i = 0; i < RandomData.randomInt(1, 10); i++) {
|
||||
String password = RandomData.randomString(RandomData.randomInt(5, 16));
|
||||
PASSWORD_MAP.put(password, PassEncryptUtil.createHash(password));
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@ -28,106 +26,81 @@ import static org.junit.Assert.assertEquals;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class AnalysisUtilsTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AnalysisUtilsTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testIsActive() {
|
||||
long lastPlayed = MiscUtils.getTime();
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 4;
|
||||
|
||||
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
|
||||
assertEquals(true, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testIsNotActive2() {
|
||||
long lastPlayed = MiscUtils.getTime();
|
||||
long playTime = 0L;
|
||||
int loginTimes = 4;
|
||||
|
||||
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
|
||||
assertEquals(false, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testIsNotActive3() {
|
||||
long lastPlayed = MiscUtils.getTime();
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 0;
|
||||
|
||||
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
|
||||
assertEquals(false, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testIsNotActive() {
|
||||
long lastPlayed = 0L;
|
||||
long playTime = 12638934876L;
|
||||
int loginTimes = 4;
|
||||
|
||||
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
|
||||
assertEquals(false, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetNewPlayers() {
|
||||
List<Long> registered = new ArrayList<>();
|
||||
registered.add(5L);
|
||||
registered.add(1L);
|
||||
List<Long> registered = Arrays.asList(5L, 1L);
|
||||
|
||||
long scale = 8L;
|
||||
long now = 10L;
|
||||
long result = AnalysisUtils.getNewPlayers(registered, scale, now);
|
||||
|
||||
assertEquals(1L, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGetNewPlayersEmpty() {
|
||||
List<Long> registered = new ArrayList<>();
|
||||
long scale = 1L;
|
||||
long now = 2L;
|
||||
long result = AnalysisUtils.getNewPlayers(registered, scale, now);
|
||||
long result = AnalysisUtils.getNewPlayers(Collections.emptyList(), scale, now);
|
||||
|
||||
assertEquals(0L, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testTransformSessionDataToLengths() {
|
||||
Collection<Session> data = new ArrayList<>();
|
||||
data.add(new Session(1, 0L, 5L, 0, 0));
|
||||
data.add(new Session(1, 0, 20L, 0, 0));
|
||||
List<Long> expResult = new ArrayList<>();
|
||||
expResult.add(5L);
|
||||
expResult.add(20L);
|
||||
Collection<Session> data = Arrays.asList(
|
||||
new Session(1, 0L, 5L, 0, 0),
|
||||
new Session(1, 0L, 20L, 0, 0)
|
||||
);
|
||||
|
||||
List<Long> expResult = Arrays.asList(5L, 20L);
|
||||
List<Long> result = AnalysisUtils.transformSessionDataToLengths(data);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,13 @@
|
||||
package main.java.com.djrapitops.plan.utilities.analysis;
|
||||
|
||||
import org.junit.Test;
|
||||
import test.java.utils.RandomData;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@ -22,45 +23,41 @@ public class MathUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testAverageInt() {
|
||||
List<Integer> l = new ArrayList<>();
|
||||
List<Integer> integers = Arrays.asList(0, 20, 5, 15);
|
||||
|
||||
double exp = 10;
|
||||
l.add(0);
|
||||
l.add(20);
|
||||
l.add(5);
|
||||
l.add(15);
|
||||
double result = MathUtils.averageInt(l.stream());
|
||||
double result = MathUtils.averageInt(integers.stream());
|
||||
|
||||
assertTrue(Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverageIntEmpty() {
|
||||
List<Integer> l = Collections.emptyList();
|
||||
List<Integer> integers = Collections.emptyList();
|
||||
|
||||
double exp = 0;
|
||||
double result = MathUtils.averageInt(l.stream());
|
||||
double result = MathUtils.averageInt(integers.stream());
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverageLongCollection() {
|
||||
List<Long> l = new ArrayList<>();
|
||||
List<Long> longs = Arrays.asList(0L, 20L, 5L, 15L);
|
||||
|
||||
double exp = 10;
|
||||
l.add(0L);
|
||||
l.add(20L);
|
||||
l.add(5L);
|
||||
l.add(15L);
|
||||
double result = MathUtils.averageLong(l);
|
||||
double result = MathUtils.averageLong(longs);
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAverageDouble() {
|
||||
List<Double> l = new ArrayList<>();
|
||||
List<Double> doubles = Arrays.asList(0.0, 20.5, 4.5, 15.0);
|
||||
|
||||
double exp = 10;
|
||||
l.add(0.0);
|
||||
l.add(20.5);
|
||||
l.add(4.5);
|
||||
l.add(15.0);
|
||||
double result = MathUtils.averageDouble(l.stream());
|
||||
double result = MathUtils.averageDouble(doubles.stream());
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
|
||||
}
|
||||
@ -69,64 +66,63 @@ public class MathUtilsTest {
|
||||
public void testAverage() {
|
||||
double exp = 10;
|
||||
double result = MathUtils.average(40, 4);
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountTrueBoolean() {
|
||||
List<Boolean> l = new ArrayList<>();
|
||||
int exp = new Random().nextInt(1000);
|
||||
List<Boolean> booleans = new ArrayList<>();
|
||||
|
||||
int exp = RandomData.randomInt(0, 1000);
|
||||
for (int i = 0; i < exp; i++) {
|
||||
l.add(true);
|
||||
booleans.add(true);
|
||||
}
|
||||
for (int i = exp; i < 1000; i++) {
|
||||
l.add(false);
|
||||
|
||||
for (int i = exp; i < RandomData.randomInt(100, 1000); i++) {
|
||||
booleans.add(false);
|
||||
}
|
||||
long result = MathUtils.countTrueBoolean(l.stream());
|
||||
|
||||
long result = MathUtils.countTrueBoolean(booleans.stream());
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumInt() {
|
||||
List<Serializable> l = new ArrayList<>();
|
||||
List<Serializable> serializable = Arrays.asList(0, 20, 5, 15);
|
||||
|
||||
double exp = 40;
|
||||
l.add(0);
|
||||
l.add(20);
|
||||
l.add(5);
|
||||
l.add(15);
|
||||
double result = MathUtils.sumInt(l.stream());
|
||||
double result = MathUtils.sumInt(serializable.stream());
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumLong() {
|
||||
List<Serializable> l = new ArrayList<>();
|
||||
List<Serializable> serializable = Arrays.asList(0L, 20L, 5L, 15L);
|
||||
|
||||
long exp = 40;
|
||||
l.add(0L);
|
||||
l.add(20L);
|
||||
l.add(5L);
|
||||
l.add(15L);
|
||||
long result = MathUtils.sumLong(l.stream());
|
||||
long result = MathUtils.sumLong(serializable.stream());
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumDouble() {
|
||||
List<Serializable> l = new ArrayList<>();
|
||||
List<Serializable> serializable = Arrays.asList(0.0, 50.4, 45.0, 5.0531541);
|
||||
|
||||
double exp = 100.4531541;
|
||||
l.add(0.0);
|
||||
l.add(50.4);
|
||||
l.add(45.0);
|
||||
l.add(5.0531541);
|
||||
double result = MathUtils.sumDouble(l.stream());
|
||||
double result = MathUtils.sumDouble(serializable.stream());
|
||||
|
||||
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundDouble() {
|
||||
double exp = 412.5123125123;
|
||||
double roundedExp = MathUtils.round(exp);
|
||||
double result = MathUtils.round(exp);
|
||||
|
||||
assertTrue("", Double.compare(412.51, roundedExp) == 0);
|
||||
assertTrue(result + "/" + exp, Double.compare(412.51, result) == 0);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.utilities.comparators;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
@ -20,101 +21,117 @@ public class ComparatorTest {
|
||||
|
||||
@Test
|
||||
public void testPointComparator() {
|
||||
List<Point> test = RandomData.randomPoints();
|
||||
List<Point> points = RandomData.randomPoints();
|
||||
|
||||
List<Long> longValues = test.stream().map(Point::getX).map(i -> (long) (double) i).collect(Collectors.toList());
|
||||
List<Long> longValues = points.stream().map(Point::getX).map(i -> (long) (double) i).collect(Collectors.toList());
|
||||
longValues.sort(Long::compare);
|
||||
test.sort(new PointComparator());
|
||||
List<Long> afterSort = test.stream().map(Point::getX).map(i -> (long) (double) i).collect(Collectors.toList());
|
||||
|
||||
points.sort(new PointComparator());
|
||||
|
||||
List<Long> afterSort = points.stream().map(Point::getX).map(i -> (long) (double) i).collect(Collectors.toList());
|
||||
assertEquals(longValues, afterSort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionDataComparator() {
|
||||
List<Session> test = RandomData.randomSessions();
|
||||
List<Long> longValues = test.stream().map(Session::getSessionStart).collect(Collectors.toList());
|
||||
List<Session> sessions = RandomData.randomSessions();
|
||||
|
||||
List<Long> longValues = sessions.stream().map(Session::getSessionStart).collect(Collectors.toList());
|
||||
longValues.sort(Long::compare);
|
||||
|
||||
Collections.reverse(longValues);
|
||||
test.sort(new SessionStartComparator());
|
||||
List<Long> afterSort = test.stream().map(Session::getSessionStart).collect(Collectors.toList());
|
||||
sessions.sort(new SessionStartComparator());
|
||||
List<Long> afterSort = sessions.stream().map(Session::getSessionStart).collect(Collectors.toList());
|
||||
|
||||
assertEquals(longValues, afterSort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTPSComparator() {
|
||||
List<TPS> test = RandomData.randomTPS();
|
||||
List<Long> longValues = test.stream().map(TPS::getDate).collect(Collectors.toList());
|
||||
List<TPS> tpsList = RandomData.randomTPS();
|
||||
|
||||
List<Long> longValues = tpsList.stream().map(TPS::getDate).collect(Collectors.toList());
|
||||
longValues.sort(Long::compare);
|
||||
test.sort(new TPSComparator());
|
||||
List<Long> afterSort = test.stream().map(TPS::getDate).collect(Collectors.toList());
|
||||
|
||||
tpsList.sort(new TPSComparator());
|
||||
List<Long> afterSort = tpsList.stream().map(TPS::getDate).collect(Collectors.toList());
|
||||
|
||||
assertEquals(longValues, afterSort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDataLastPlayedComparator() {
|
||||
List<UserInfo> test = RandomData.randomUserData();
|
||||
List<Long> longValues = test.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
List<UserInfo> userInfo = RandomData.randomUserData();
|
||||
|
||||
List<Long> longValues = userInfo.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
longValues.sort(Long::compare);
|
||||
|
||||
Collections.reverse(longValues);
|
||||
test.sort(new UserInfoLastPlayedComparator());
|
||||
List<Long> afterSort = test.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
userInfo.sort(new UserInfoLastPlayedComparator());
|
||||
List<Long> afterSort = userInfo.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
|
||||
assertEquals(longValues, afterSort);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUserDataNameComparator() {
|
||||
List<UserInfo> test = RandomData.randomUserData();
|
||||
List<String> stringValues = test.stream().map(UserInfo::getName).collect(Collectors.toList());
|
||||
List<UserInfo> userInfo = RandomData.randomUserData();
|
||||
|
||||
List<String> stringValues = userInfo.stream().map(UserInfo::getName).collect(Collectors.toList());
|
||||
Collections.sort(stringValues);
|
||||
test.sort(new UserDataNameComparator());
|
||||
List<String> afterSort = test.stream().map(UserInfo::getName).collect(Collectors.toList());
|
||||
|
||||
userInfo.sort(new UserDataNameComparator());
|
||||
List<String> afterSort = userInfo.stream().map(UserInfo::getName).collect(Collectors.toList());
|
||||
|
||||
assertEquals(stringValues, afterSort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
||||
List<WebUser> test = RandomData.randomWebUsers();
|
||||
List<Integer> intValues = test.stream().map(WebUser::getPermLevel).collect(Collectors.toList());
|
||||
List<WebUser> webUsers = RandomData.randomWebUsers();
|
||||
|
||||
List<Integer> intValues = webUsers.stream().map(WebUser::getPermLevel).collect(Collectors.toList());
|
||||
intValues.sort(Integer::compare);
|
||||
Collections.reverse(intValues);
|
||||
test.sort(new WebUserComparator());
|
||||
List<Integer> afterSort = test.stream().map(WebUser::getPermLevel).collect(Collectors.toList());
|
||||
|
||||
webUsers.sort(new WebUserComparator());
|
||||
List<Integer> afterSort = webUsers.stream().map(WebUser::getPermLevel).collect(Collectors.toList());
|
||||
|
||||
assertEquals(intValues, afterSort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringLengthComparator() {
|
||||
List<String> test = new ArrayList<>();
|
||||
test.add(RandomData.randomString(10));
|
||||
test.add(RandomData.randomString(3));
|
||||
test.add(RandomData.randomString(20));
|
||||
test.add(RandomData.randomString(7));
|
||||
test.add(RandomData.randomString(4));
|
||||
test.add(RandomData.randomString(86));
|
||||
test.add(RandomData.randomString(6));
|
||||
List<String> strings = Ordering.from(new StringLengthComparator())
|
||||
.sortedCopy(Arrays.asList(
|
||||
RandomData.randomString(10),
|
||||
RandomData.randomString(3),
|
||||
RandomData.randomString(20),
|
||||
RandomData.randomString(7),
|
||||
RandomData.randomString(4),
|
||||
RandomData.randomString(86),
|
||||
RandomData.randomString(6)));
|
||||
|
||||
test.sort(new StringLengthComparator());
|
||||
|
||||
assertEquals(86, test.get(0).length());
|
||||
assertEquals(20, test.get(1).length());
|
||||
assertEquals(3, test.get(test.size() - 1).length());
|
||||
assertEquals(86, strings.get(0).length());
|
||||
assertEquals(20, strings.get(1).length());
|
||||
assertEquals(3, strings.get(strings.size() - 1).length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocaleEntryComparator() {
|
||||
Map<Msg, Message> test = new HashMap<>();
|
||||
test.put(Msg.CMD_CONSTANT_FOOTER, new Message(""));
|
||||
test.put(Msg.ANALYSIS_3RD_PARTY, new Message(""));
|
||||
test.put(Msg.MANAGE_FAIL_NO_PLAYERS, new Message(""));
|
||||
Map<Msg, Message> messageMap = new HashMap<>();
|
||||
messageMap.put(Msg.CMD_CONSTANT_FOOTER, new Message(RandomData.randomString(10)));
|
||||
messageMap.put(Msg.ANALYSIS_3RD_PARTY, new Message(RandomData.randomString(10)));
|
||||
messageMap.put(Msg.MANAGE_FAIL_NO_PLAYERS, new Message(RandomData.randomString(10)));
|
||||
|
||||
List<String> sorted = test.entrySet().stream()
|
||||
List<String> sorted = messageMap.entrySet().stream()
|
||||
.sorted(new LocaleEntryComparator())
|
||||
.map(entry -> entry.getKey().name())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals("ANALYSIS_3RD_PARTY", sorted.get(0));
|
||||
assertEquals("CMD_CONSTANT_FOOTER", sorted.get(1));
|
||||
assertEquals("MANAGE_FAIL_NO_PLAYERS", sorted.get(2));
|
||||
assertEquals(Msg.ANALYSIS_3RD_PARTY.name(), sorted.get(0));
|
||||
assertEquals(Msg.CMD_CONSTANT_FOOTER.name(), sorted.get(1));
|
||||
assertEquals(Msg.MANAGE_FAIL_NO_PLAYERS.name(), sorted.get(2));
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import test.java.utils.RandomData;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
@ -28,25 +28,26 @@ import static junit.framework.TestCase.assertNotNull;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class HastebinTest {
|
||||
|
||||
private final AtomicReference<String> testLink = new AtomicReference<>(null);
|
||||
private final AtomicBoolean testLink = new AtomicBoolean(false);
|
||||
|
||||
@Before
|
||||
public void checkAvailability() throws Exception {
|
||||
TestInit.init();
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
String link = null;
|
||||
try {
|
||||
link = Hastebin.upload(RandomData.randomString(10));
|
||||
Hastebin.upload(RandomData.randomString(10));
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage().contains("503")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.toLog("checkAvailability()", e);
|
||||
} catch (ParseException e) {
|
||||
/* Ignored */
|
||||
}
|
||||
|
||||
testLink.set(link);
|
||||
testLink.set(true);
|
||||
});
|
||||
|
||||
thread.start();
|
||||
@ -57,7 +58,7 @@ public class HastebinTest {
|
||||
Log.info("Hastebin timed out");
|
||||
}
|
||||
|
||||
Log.info("Hastebin Availability Test Link: " + testLink.get());
|
||||
Log.info("Hastebin Available: " + testLink.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -72,7 +73,7 @@ public class HastebinTest {
|
||||
|
||||
@Test
|
||||
public void testUpload() throws Exception {
|
||||
if (testLink.get() == null) {
|
||||
if (!testLink.get()) {
|
||||
Log.info("Hastebin not available, skipping testUpload()");
|
||||
return;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.utilities.html;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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;
|
||||
@ -29,7 +30,8 @@ public class HtmlStructureTest {
|
||||
|
||||
private Map<String, List<Session>> sessions = new HashMap<>();
|
||||
|
||||
public HtmlStructureTest() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
|
||||
for (int i = 0; i < RandomData.randomInt(0, 5); i++) {
|
||||
|
@ -26,6 +26,8 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -129,49 +131,69 @@ public class TestInit {
|
||||
@Override
|
||||
public IRunnable createNew(String name, final AbsRunnable runnable) {
|
||||
return new IRunnable() {
|
||||
Timer timer = new Timer();
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getTaskName() {
|
||||
return "Test";
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
timer.cancel();
|
||||
task.cancel();
|
||||
runnable.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTaskId() {
|
||||
return 0;
|
||||
return runnable.getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITask runTask() {
|
||||
new Thread(runnable::run).start();
|
||||
task.run();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITask runTaskAsynchronously() {
|
||||
return runTask();
|
||||
new Thread(this::runTask).start();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITask runTaskLater(long l) {
|
||||
return runTask();
|
||||
timer.schedule(task, convertTicksToMillis(l));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITask runTaskLaterAsynchronously(long l) {
|
||||
return runTask();
|
||||
new Thread(() -> timer.schedule(task, convertTicksToMillis(l))).start();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITask runTaskTimer(long l, long l1) {
|
||||
return runTask();
|
||||
timer.scheduleAtFixedRate(task, convertTicksToMillis(l), convertTicksToMillis(l1));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITask runTaskTimerAsynchronously(long l, long l1) {
|
||||
return runTask();
|
||||
new Thread(() -> timer.scheduleAtFixedRate(task, convertTicksToMillis(l), convertTicksToMillis(l1)));
|
||||
return null;
|
||||
}
|
||||
|
||||
private long convertTicksToMillis(long ticks) {
|
||||
return ticks * 50;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user