mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 22:01:00 +01:00
Add testFormatTimeStampSecond()
Add Check Tests
This commit is contained in:
parent
ae40605251
commit
b1c5b69d42
@ -147,7 +147,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
|||||||
|
|
||||||
Benchmark.start("Init Database");
|
Benchmark.start("Init Database");
|
||||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||||
if (Check.ErrorIfFalse(initDatabase(), Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString())) {
|
if (Check.errorIfFalse(initDatabase(), Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString())) {
|
||||||
Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName()));
|
Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName()));
|
||||||
} else {
|
} else {
|
||||||
disablePlugin();
|
disablePlugin();
|
||||||
@ -316,7 +316,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Check.ErrorIfFalse(db.init(), Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString());
|
return Check.errorIfFalse(db.init(), Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startAnalysisRefreshTask(int everyXMinutes) throws IllegalStateException {
|
private void startAnalysisRefreshTask(int everyXMinutes) throws IllegalStateException {
|
||||||
|
@ -54,7 +54,7 @@ public class Check {
|
|||||||
* @param message Message to send if Condition is false
|
* @param message Message to send if Condition is false
|
||||||
* @return Condition
|
* @return Condition
|
||||||
*/
|
*/
|
||||||
public static boolean ErrorIfFalse(boolean condition, String message) {
|
public static boolean errorIfFalse(boolean condition, String message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
Log.error(message);
|
Log.error(message);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package test.java.main.java.com.djrapitops.plan.utilities;
|
||||||
|
|
||||||
|
import com.djrapitops.plugin.command.ISender;
|
||||||
|
import main.java.com.djrapitops.plan.utilities.Check;
|
||||||
|
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.MockUtils;
|
||||||
|
import test.java.utils.RandomData;
|
||||||
|
import test.java.utils.TestInit;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertFalse;
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Fuzzlemann
|
||||||
|
*/
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest(JavaPlugin.class)
|
||||||
|
public class CheckTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
TestInit.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTrueCheck() {
|
||||||
|
String message = RandomData.randomString(10);
|
||||||
|
|
||||||
|
assertTrue(Check.isTrue(true, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTrueAtISenderCheck() {
|
||||||
|
String message = RandomData.randomString(10);
|
||||||
|
ISender sender = MockUtils.mockIPlayer();
|
||||||
|
|
||||||
|
assertTrue(Check.isTrue(true, message, sender));
|
||||||
|
assertFalse(Check.isTrue(false, message, sender));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testErrorCheck() {
|
||||||
|
String message = RandomData.randomString(10);
|
||||||
|
|
||||||
|
assertTrue(Check.errorIfFalse(true, message));
|
||||||
|
assertFalse(Check.errorIfFalse(false, message));
|
||||||
|
}
|
||||||
|
}
|
@ -9,11 +9,10 @@ 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.TestInit;
|
|
||||||
import test.java.utils.MockUtils;
|
import test.java.utils.MockUtils;
|
||||||
|
import test.java.utils.TestInit;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -26,40 +25,24 @@ import static org.junit.Assert.*;
|
|||||||
@PrepareForTest(JavaPlugin.class)
|
@PrepareForTest(JavaPlugin.class)
|
||||||
public class FormatUtilsTest {
|
public class FormatUtilsTest {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public FormatUtilsTest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
TestInit.init();
|
TestInit.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatTimeAmount() throws Exception {
|
public void testFormatTimeAmount() {
|
||||||
TestInit.init();
|
long ms = 1000L;
|
||||||
long second = 1000L;
|
|
||||||
String expResult = "1s";
|
String expResult = "1s";
|
||||||
String result = FormatUtils.formatTimeAmount(second);
|
String result = FormatUtils.formatTimeAmount(ms);
|
||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatTimeAmountSinceDate() throws Exception {
|
public void testFormatTimeAmountSinceDate() {
|
||||||
TestInit.init();
|
|
||||||
Date before = new Date(300000L);
|
Date before = new Date(300000L);
|
||||||
Date now = new Date(310000L);
|
Date now = new Date(310000L);
|
||||||
|
|
||||||
String expResult = "10s";
|
String expResult = "10s";
|
||||||
String result = FormatUtils.formatTimeAmountDifference(before.getTime(), now.getTime());
|
String result = FormatUtils.formatTimeAmountDifference(before.getTime(), now.getTime());
|
||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
@ -67,8 +50,7 @@ public class FormatUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatTimeStamp() {
|
public void testFormatTimeStamp() {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd',' HH':'mm");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd, HH:mm", Locale.ENGLISH);
|
||||||
dateFormat.setCalendar(Calendar.getInstance(Locale.ENGLISH));
|
|
||||||
|
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
date.setTime(0);
|
date.setTime(0);
|
||||||
@ -82,8 +64,7 @@ public class FormatUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatTimeStampYear() {
|
public void testFormatTimeStampYear() {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd YYYY',' HH':'mm");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd YYYY, HH:mm", Locale.ENGLISH);
|
||||||
dateFormat.setCalendar(Calendar.getInstance(Locale.ENGLISH));
|
|
||||||
|
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
date.setTime(0);
|
date.setTime(0);
|
||||||
@ -95,9 +76,20 @@ public class FormatUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Test
|
||||||
*
|
public void testFormatTimeStampSecond() {
|
||||||
*/
|
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd, HH:mm:ss", Locale.ENGLISH);
|
||||||
|
|
||||||
|
Date date = new Date();
|
||||||
|
date.setTime(0);
|
||||||
|
|
||||||
|
String expResult = dateFormat.format(date);
|
||||||
|
|
||||||
|
long epochZero = 0L;
|
||||||
|
String result = FormatUtils.formatTimeStampSecond(epochZero);
|
||||||
|
assertEquals(expResult, result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveLetters() {
|
public void testRemoveLetters() {
|
||||||
String dataPoint = "435729847jirggu.eiwb¤#¤%¤#";
|
String dataPoint = "435729847jirggu.eiwb¤#¤%¤#";
|
||||||
@ -106,9 +98,6 @@ public class FormatUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveNumbers() {
|
public void testRemoveNumbers() {
|
||||||
String dataPoint = "34532453.5 $";
|
String dataPoint = "34532453.5 $";
|
||||||
@ -117,9 +106,6 @@ public class FormatUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveNumbers2() {
|
public void testRemoveNumbers2() {
|
||||||
String dataPoint = "l43r4545tl43 4.5";
|
String dataPoint = "l43r4545tl43 4.5";
|
||||||
@ -128,9 +114,6 @@ public class FormatUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseVersionNumber() {
|
public void testParseVersionNumber() {
|
||||||
String versionString = "2.10.2";
|
String versionString = "2.10.2";
|
||||||
@ -139,9 +122,6 @@ public class FormatUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testVersionNumber() {
|
public void testVersionNumber() {
|
||||||
String versionString = "2.10.2";
|
String versionString = "2.10.2";
|
||||||
@ -151,9 +131,6 @@ public class FormatUtilsTest {
|
|||||||
assertTrue("Higher version not higher", result > result2);
|
assertTrue("Higher version not higher", result > result2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testMergeArrays() {
|
public void testMergeArrays() {
|
||||||
String[][] arrays = new String[][]{new String[]{"Test", "One"}, new String[]{"Test", "Two"}};
|
String[][] arrays = new String[][]{new String[]{"Test", "One"}, new String[]{"Test", "Two"}};
|
||||||
@ -162,9 +139,6 @@ public class FormatUtilsTest {
|
|||||||
assertArrayEquals(expResult, result);
|
assertArrayEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatLocation() {
|
public void testFormatLocation() {
|
||||||
World mockWorld = MockUtils.mockWorld();
|
World mockWorld = MockUtils.mockWorld();
|
||||||
@ -174,24 +148,16 @@ public class FormatUtilsTest {
|
|||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testCutDecimals() throws Exception {
|
public void testCutDecimals() throws Exception {
|
||||||
TestInit.init();
|
|
||||||
double d = 0.05234;
|
double d = 0.05234;
|
||||||
String expResult = "0,05";
|
String expResult = "0,05";
|
||||||
String result = FormatUtils.cutDecimals(d);
|
String result = FormatUtils.cutDecimals(d);
|
||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testCutDecimals2() throws Exception {
|
public void testCutDecimals2() throws Exception {
|
||||||
TestInit.init();
|
|
||||||
double d = 0.05634;
|
double d = 0.05634;
|
||||||
String expResult = "0,06";
|
String expResult = "0,06";
|
||||||
String result = FormatUtils.cutDecimals(d);
|
String result = FormatUtils.cutDecimals(d);
|
||||||
|
@ -10,7 +10,6 @@ import com.djrapitops.plugin.command.bukkit.BukkitCMDSender;
|
|||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -30,19 +29,6 @@ import static org.junit.Assert.assertEquals;
|
|||||||
@PrepareForTest({JavaPlugin.class, Bukkit.class})
|
@PrepareForTest({JavaPlugin.class, Bukkit.class})
|
||||||
public class MiscUtilsTest {
|
public class MiscUtilsTest {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public MiscUtilsTest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
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"};
|
||||||
|
@ -19,21 +19,21 @@ import static org.junit.Assert.assertTrue;
|
|||||||
*/
|
*/
|
||||||
public class PassEncryptTest {
|
public class PassEncryptTest {
|
||||||
|
|
||||||
private final List<String> passwords = new ArrayList<>();
|
private final List<String> PASSWORDS = new ArrayList<>();
|
||||||
private final Map<String, String> passwordMap = new HashMap<>();
|
private final Map<String, String> PASSWORD_MAP = new HashMap<>();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
IntStream.range(0, 50).forEach(i -> passwords.add(RandomData.randomString(RandomData.randomInt(1, 100))));
|
IntStream.range(0, 50).forEach(i -> PASSWORDS.add(RandomData.randomString(RandomData.randomInt(1, 100))));
|
||||||
|
|
||||||
for (String password : passwords) {
|
for (String password : PASSWORDS) {
|
||||||
passwordMap.put(password, PassEncryptUtil.createHash(password));
|
PASSWORD_MAP.put(password, PassEncryptUtil.createHash(password));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerification() throws Exception {
|
public void testVerification() throws Exception {
|
||||||
for (Map.Entry<String, String> entry : passwordMap.entrySet()) {
|
for (Map.Entry<String, String> entry : PASSWORD_MAP.entrySet()) {
|
||||||
String password = entry.getKey();
|
String password = entry.getKey();
|
||||||
String hash = entry.getValue();
|
String hash = entry.getValue();
|
||||||
|
|
||||||
|
@ -109,10 +109,12 @@ public class TestInit {
|
|||||||
|
|
||||||
private Server mockServer() {
|
private Server mockServer() {
|
||||||
Server mockServer = PowerMockito.mock(Server.class);
|
Server mockServer = PowerMockito.mock(Server.class);
|
||||||
|
|
||||||
|
OfflinePlayer[] ops = new OfflinePlayer[]{MockUtils.mockPlayer(), MockUtils.mockPlayer2()};
|
||||||
|
|
||||||
when(mockServer.getIp()).thenReturn("0.0.0.0");
|
when(mockServer.getIp()).thenReturn("0.0.0.0");
|
||||||
when(mockServer.getMaxPlayers()).thenReturn(20);
|
when(mockServer.getMaxPlayers()).thenReturn(20);
|
||||||
when(mockServer.getName()).thenReturn("Bukkit");
|
when(mockServer.getName()).thenReturn("Bukkit");
|
||||||
OfflinePlayer[] ops = new OfflinePlayer[]{MockUtils.mockPlayer(), MockUtils.mockPlayer2()};
|
|
||||||
when(mockServer.getOfflinePlayers()).thenReturn(ops);
|
when(mockServer.getOfflinePlayers()).thenReturn(ops);
|
||||||
return mockServer;
|
return mockServer;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user