mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-05 10:20:23 +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");
|
||||
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()));
|
||||
} else {
|
||||
disablePlugin();
|
||||
@ -316,7 +316,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
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 {
|
||||
|
@ -54,7 +54,7 @@ public class Check {
|
||||
* @param message Message to send if Condition is false
|
||||
* @return Condition
|
||||
*/
|
||||
public static boolean ErrorIfFalse(boolean condition, String message) {
|
||||
public static boolean errorIfFalse(boolean condition, String message) {
|
||||
if (!condition) {
|
||||
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.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -26,40 +25,24 @@ import static org.junit.Assert.*;
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class FormatUtilsTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public FormatUtilsTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testFormatTimeAmount() throws Exception {
|
||||
TestInit.init();
|
||||
long second = 1000L;
|
||||
public void testFormatTimeAmount() {
|
||||
long ms = 1000L;
|
||||
String expResult = "1s";
|
||||
String result = FormatUtils.formatTimeAmount(second);
|
||||
String result = FormatUtils.formatTimeAmount(ms);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testFormatTimeAmountSinceDate() throws Exception {
|
||||
TestInit.init();
|
||||
public void testFormatTimeAmountSinceDate() {
|
||||
Date before = new Date(300000L);
|
||||
Date now = new Date(310000L);
|
||||
|
||||
String expResult = "10s";
|
||||
String result = FormatUtils.formatTimeAmountDifference(before.getTime(), now.getTime());
|
||||
assertEquals(expResult, result);
|
||||
@ -67,8 +50,7 @@ public class FormatUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFormatTimeStamp() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd',' HH':'mm");
|
||||
dateFormat.setCalendar(Calendar.getInstance(Locale.ENGLISH));
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd, HH:mm", Locale.ENGLISH);
|
||||
|
||||
Date date = new Date();
|
||||
date.setTime(0);
|
||||
@ -82,8 +64,7 @@ public class FormatUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFormatTimeStampYear() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd YYYY',' HH':'mm");
|
||||
dateFormat.setCalendar(Calendar.getInstance(Locale.ENGLISH));
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd YYYY, HH:mm", Locale.ENGLISH);
|
||||
|
||||
Date date = new Date();
|
||||
date.setTime(0);
|
||||
@ -95,9 +76,20 @@ public class FormatUtilsTest {
|
||||
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
|
||||
public void testRemoveLetters() {
|
||||
String dataPoint = "435729847jirggu.eiwb¤#¤%¤#";
|
||||
@ -106,9 +98,6 @@ public class FormatUtilsTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveNumbers() {
|
||||
String dataPoint = "34532453.5 $";
|
||||
@ -117,9 +106,6 @@ public class FormatUtilsTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveNumbers2() {
|
||||
String dataPoint = "l43r4545tl43 4.5";
|
||||
@ -128,9 +114,6 @@ public class FormatUtilsTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testParseVersionNumber() {
|
||||
String versionString = "2.10.2";
|
||||
@ -139,9 +122,6 @@ public class FormatUtilsTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testVersionNumber() {
|
||||
String versionString = "2.10.2";
|
||||
@ -151,9 +131,6 @@ public class FormatUtilsTest {
|
||||
assertTrue("Higher version not higher", result > result2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMergeArrays() {
|
||||
String[][] arrays = new String[][]{new String[]{"Test", "One"}, new String[]{"Test", "Two"}};
|
||||
@ -162,9 +139,6 @@ public class FormatUtilsTest {
|
||||
assertArrayEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testFormatLocation() {
|
||||
World mockWorld = MockUtils.mockWorld();
|
||||
@ -174,24 +148,16 @@ public class FormatUtilsTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCutDecimals() throws Exception {
|
||||
TestInit.init();
|
||||
double d = 0.05234;
|
||||
String expResult = "0,05";
|
||||
String result = FormatUtils.cutDecimals(d);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCutDecimals2() throws Exception {
|
||||
TestInit.init();
|
||||
double d = 0.05634;
|
||||
String expResult = "0,06";
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -30,19 +29,6 @@ import static org.junit.Assert.assertEquals;
|
||||
@PrepareForTest({JavaPlugin.class, Bukkit.class})
|
||||
public class MiscUtilsTest {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public MiscUtilsTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameArgsPerm() {
|
||||
String[] args = new String[]{"Rsl1122", "Test"};
|
||||
|
@ -19,21 +19,21 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
public class PassEncryptTest {
|
||||
|
||||
private final List<String> passwords = new ArrayList<>();
|
||||
private final Map<String, String> passwordMap = new HashMap<>();
|
||||
private final List<String> PASSWORDS = new ArrayList<>();
|
||||
private final Map<String, String> PASSWORD_MAP = new HashMap<>();
|
||||
|
||||
@Before
|
||||
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) {
|
||||
passwordMap.put(password, PassEncryptUtil.createHash(password));
|
||||
for (String password : PASSWORDS) {
|
||||
PASSWORD_MAP.put(password, PassEncryptUtil.createHash(password));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
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 hash = entry.getValue();
|
||||
|
||||
|
@ -109,10 +109,12 @@ public class TestInit {
|
||||
|
||||
private Server mockServer() {
|
||||
Server mockServer = PowerMockito.mock(Server.class);
|
||||
|
||||
OfflinePlayer[] ops = new OfflinePlayer[]{MockUtils.mockPlayer(), MockUtils.mockPlayer2()};
|
||||
|
||||
when(mockServer.getIp()).thenReturn("0.0.0.0");
|
||||
when(mockServer.getMaxPlayers()).thenReturn(20);
|
||||
when(mockServer.getName()).thenReturn("Bukkit");
|
||||
OfflinePlayer[] ops = new OfflinePlayer[]{MockUtils.mockPlayer(), MockUtils.mockPlayer2()};
|
||||
when(mockServer.getOfflinePlayers()).thenReturn(ops);
|
||||
return mockServer;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user