mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-12 15:56:00 +08:00
Improved a database test
Fixed a bug with database getMultiple method not setting the last nickname at all.
This commit is contained in:
parent
e888864ab0
commit
681bfa2b9b
@ -263,6 +263,21 @@
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ChatInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/DeathInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
@ -273,6 +288,11 @@
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
|
@ -42,7 +42,7 @@ public class KillHandling {
|
||||
int victimID;
|
||||
try {
|
||||
UUID victimUUID = deadPlayer.getUniqueId();
|
||||
victimID = plugin.getDB().getUsersTable().getUserId(victimUUID + "");
|
||||
victimID = plugin.getDB().getUsersTable().getUserId(victimUUID);
|
||||
if (victimID == -1) {
|
||||
return;
|
||||
}
|
||||
|
@ -394,7 +394,9 @@ public abstract class SQLDB extends Database {
|
||||
UUID uuid = uData.getUuid();
|
||||
Integer id = userIds.get(uuid);
|
||||
uData.addIpAddresses(ipList.get(id));
|
||||
uData.addNicknames(nicknames.get(id));
|
||||
List<String> nickNames = nicknames.get(id);
|
||||
uData.addNicknames(nickNames);
|
||||
uData.setLastNick(nickNames.get(nickNames.size()-1));
|
||||
uData.addSessions(sessionData.get(id));
|
||||
uData.setPlayerKills(playerKills.get(id));
|
||||
uData.getGmTimes().setTimes(gmTimes.get(id));
|
||||
|
@ -12,6 +12,7 @@ import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.KillHandling;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -26,6 +27,7 @@ import test.java.utils.TestInit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -63,6 +65,19 @@ public class KillHandlingTest {
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsersTable getUsersTable() {
|
||||
return new UsersTable(null, false) {
|
||||
@Override
|
||||
public int getUserId(UUID uuid) {
|
||||
if (uuid.equals(MockUtils.getPlayerUUID())) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
}
|
||||
@ -82,8 +97,6 @@ public class KillHandlingTest {
|
||||
public void testProcessKillInfoPlayer() throws SQLException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
IPlayer dead = MockUtils.mockIPlayer2();
|
||||
db.init();
|
||||
db.saveUserData(new UserData(dead));
|
||||
KillHandling.processKillInfo(data, 10L, (Player) dead.getWrappedPlayerClass(), "TestWeapon");
|
||||
KillData expected = new KillData(dead.getUuid(), 1, "TestWeapon", 10L);
|
||||
assertTrue("Didn't add the kill", data.getPlayerKills().size() == 1);
|
||||
@ -100,9 +113,8 @@ public class KillHandlingTest {
|
||||
*/
|
||||
@Test
|
||||
public void testProcessKillInfoException() throws SQLException, IOException {
|
||||
db.init();
|
||||
UserData data = MockUtils.mockUser();
|
||||
Player dead = (Player) MockUtils.mockIPlayer2().getWrappedPlayerClass();
|
||||
UserData data = MockUtils.mockUser2();
|
||||
Player dead = (Player) MockUtils.mockIPlayer().getWrappedPlayerClass();
|
||||
KillHandling.processKillInfo(data, 10L, dead, "TestWeapon");
|
||||
assertTrue("Added the kill", data.getPlayerKills().isEmpty());
|
||||
}
|
||||
|
@ -5,17 +5,16 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import com.djrapitops.plugin.utilities.player.Fetch;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -25,6 +24,7 @@ import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -62,18 +62,23 @@ public class KillInfoTest {
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsersTable getUsersTable() {
|
||||
return new UsersTable(null, false) {
|
||||
@Override
|
||||
public int getUserId(UUID uuid) {
|
||||
if (uuid.equals(MockUtils.getPlayerUUID())) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws SQLException {
|
||||
db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@ -81,8 +86,6 @@ public class KillInfoTest {
|
||||
public void testProcess() throws SQLException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
Player dead = MockUtils.mockPlayer2();
|
||||
db.init();
|
||||
db.saveUserData(new UserData(Fetch.wrapBukkit(dead)));
|
||||
KillInfo i = new KillInfo(data.getUuid(), 10L, dead, "TestWeapon");
|
||||
assertTrue(i.process(data));
|
||||
KillData expected = new KillData(dead.getUniqueId(), 1, "TestWeapon", 10L);
|
||||
|
@ -242,7 +242,7 @@ public class DatabaseTest {
|
||||
@Override
|
||||
public void process(UserData d) {
|
||||
System.out.println("\nOriginal: " + data);
|
||||
System.out.println("Database: "+d);
|
||||
System.out.println("Database: " + d);
|
||||
assertTrue("Not Equals", data.equals(d));
|
||||
}
|
||||
};
|
||||
@ -294,24 +294,14 @@ public class DatabaseTest {
|
||||
list.add(data2);
|
||||
db.saveMultipleUserData(list);
|
||||
data.addPlayerKill(new KillData(MockUtils.getPlayer2UUID(), 2, "DiamondSword", 75843759L));
|
||||
DBCallableProcessor process = new DBCallableProcessor() {
|
||||
@Override
|
||||
public void process(UserData d) {
|
||||
System.out.println("\n" + data.toString());
|
||||
System.out.println(d.toString());
|
||||
assertTrue("Not Equals", data.equals(d));
|
||||
}
|
||||
};
|
||||
db.giveUserDataToProcessors(data.getUuid(), process);
|
||||
DBCallableProcessor process2 = new DBCallableProcessor() {
|
||||
@Override
|
||||
public void process(UserData d) {
|
||||
System.out.println("\n" + data2.toString());
|
||||
System.out.println(d.toString());
|
||||
assertTrue("Not Equals", data2.equals(d));
|
||||
}
|
||||
};
|
||||
db.giveUserDataToProcessors(data2.getUuid(), process2);
|
||||
List<UserData> userDataForUUIDS = db.getUserDataForUUIDS(MockUtils.getUUIDs());
|
||||
|
||||
System.out.println("\nData1:" + data.toString());
|
||||
System.out.println("Data2:" + data2.toString() + "\n");
|
||||
for (UserData uData : userDataForUUIDS) {
|
||||
System.out.println("uData:" + uData.toString());
|
||||
assertTrue("Not Equals", (data.equals(uData) || data2.equals(uData)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,8 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
@ -121,6 +123,13 @@ public class MockUtils {
|
||||
return UUID.fromString("ec94a954-1fa1-445b-b09b-9b698519af80");
|
||||
}
|
||||
|
||||
public static Set<UUID> getUUIDs() {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
uuids.add(getPlayerUUID());
|
||||
uuids.add(getPlayer2UUID());
|
||||
return uuids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user