diff --git a/Plan/.idea/sonarIssues.xml b/Plan/.idea/sonarIssues.xml index 4563ecc35..405f4b5a3 100644 --- a/Plan/.idea/sonarIssues.xml +++ b/Plan/.idea/sonarIssues.xml @@ -263,6 +263,21 @@ + + + + + + + + + + + + + + + @@ -273,6 +288,11 @@ + + + + + diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java index fdea1bb63..75042f01f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java @@ -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; } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index 1be5a247a..d1cb99162 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -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 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)); diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java index 7497f10f4..6663fea02 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java @@ -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()); } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java index 749e437ef..7e4c33f97 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java @@ -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); diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java index 7289e4289..b8ed1fad1 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java @@ -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 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))); + } } /** diff --git a/Plan/src/test/java/utils/MockUtils.java b/Plan/src/test/java/utils/MockUtils.java index 111334dab..3bff73764 100644 --- a/Plan/src/test/java/utils/MockUtils.java +++ b/Plan/src/test/java/utils/MockUtils.java @@ -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 getUUIDs() { + Set uuids = new HashSet<>(); + uuids.add(getPlayerUUID()); + uuids.add(getPlayer2UUID()); + return uuids; + } + /** * @return */