mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Made fetchUserInformationOfUser return a Set instead of List
Fixes tests where there was some order-dependent stuff.
This commit is contained in:
parent
477c547c51
commit
7906126b5e
@ -33,6 +33,7 @@ import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +95,7 @@ public class PerServerContainerQuery implements Query<PerServerContainer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void userInformation(SQLDB db, PerServerContainer container) {
|
private void userInformation(SQLDB db, PerServerContainer container) {
|
||||||
List<UserInfo> userInformation = db.query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> userInformation = db.query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
container.putUserInfo(userInformation);
|
container.putUserInfo(userInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class UserInfoQueries {
|
|||||||
* @param playerUUID UUID of the player.
|
* @param playerUUID UUID of the player.
|
||||||
* @return List of UserInfo objects, one for each server where the player has played.
|
* @return List of UserInfo objects, one for each server where the player has played.
|
||||||
*/
|
*/
|
||||||
public static Query<List<UserInfo>> fetchUserInformationOfUser(UUID playerUUID) {
|
public static Query<Set<UserInfo>> fetchUserInformationOfUser(UUID playerUUID) {
|
||||||
String sql = SELECT +
|
String sql = SELECT +
|
||||||
UserInfoTable.TABLE_NAME + '.' + UserInfoTable.REGISTERED + ',' +
|
UserInfoTable.TABLE_NAME + '.' + UserInfoTable.REGISTERED + ',' +
|
||||||
UserInfoTable.BANNED + ',' +
|
UserInfoTable.BANNED + ',' +
|
||||||
@ -97,15 +97,15 @@ public class UserInfoQueries {
|
|||||||
FROM + UserInfoTable.TABLE_NAME +
|
FROM + UserInfoTable.TABLE_NAME +
|
||||||
WHERE + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + "=?";
|
WHERE + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + "=?";
|
||||||
|
|
||||||
return new QueryStatement<List<UserInfo>>(sql) {
|
return new QueryStatement<Set<UserInfo>>(sql) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setString(1, playerUUID.toString());
|
statement.setString(1, playerUUID.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserInfo> processResults(ResultSet set) throws SQLException {
|
public Set<UserInfo> processResults(ResultSet set) throws SQLException {
|
||||||
List<UserInfo> userInformation = new ArrayList<>();
|
Set<UserInfo> userInformation = new HashSet<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
long registered = set.getLong(UserInfoTable.REGISTERED);
|
long registered = set.getLong(UserInfoTable.REGISTERED);
|
||||||
boolean op = set.getBoolean(UserInfoTable.OP);
|
boolean op = set.getBoolean(UserInfoTable.OP);
|
||||||
|
@ -46,8 +46,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
|
|||||||
assertFalse(db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).isPresent());
|
assertFalse(db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).isPresent());
|
||||||
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
|
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
|
||||||
|
|
||||||
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
|
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
|
||||||
|
|
||||||
assertEquals(expected, userInfo);
|
assertEquals(expected, userInfo);
|
||||||
}
|
}
|
||||||
@ -57,8 +57,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
|
|||||||
assertFalse(db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).isPresent());
|
assertFalse(db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).isPresent());
|
||||||
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> null));
|
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> null));
|
||||||
|
|
||||||
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, null, false));
|
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, null, false));
|
||||||
|
|
||||||
assertEquals(expected, userInfo);
|
assertEquals(expected, userInfo);
|
||||||
}
|
}
|
||||||
@ -69,8 +69,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
|
|||||||
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> null));
|
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> null));
|
||||||
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
|
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
|
||||||
|
|
||||||
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
|
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
|
||||||
|
|
||||||
assertEquals(expected, userInfo);
|
assertEquals(expected, userInfo);
|
||||||
}
|
}
|
||||||
@ -83,11 +83,11 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
|
|||||||
db().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_TWO_UUID, TestConstants.SERVER_TWO_NAME, "")));
|
db().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_TWO_UUID, TestConstants.SERVER_TWO_NAME, "")));
|
||||||
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, TestConstants.SERVER_TWO_UUID, () -> "example.join.address"));
|
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, TestConstants.SERVER_TWO_UUID, () -> "example.join.address"));
|
||||||
|
|
||||||
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
List<UserInfo> expected = Arrays.asList(
|
Set<UserInfo> expected = new HashSet<>(Arrays.asList(
|
||||||
new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false),
|
new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false),
|
||||||
new UserInfo(playerUUID, TestConstants.SERVER_TWO_UUID, TestConstants.REGISTER_TIME, false, "example.join.address", false)
|
new UserInfo(playerUUID, TestConstants.SERVER_TWO_UUID, TestConstants.REGISTER_TIME, false, "example.join.address", false)
|
||||||
);
|
));
|
||||||
|
|
||||||
assertEquals(expected, userInfo);
|
assertEquals(expected, userInfo);
|
||||||
}
|
}
|
||||||
@ -99,8 +99,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
|
|||||||
|
|
||||||
db().executeTransaction(new BanStatusTransaction(playerUUID, () -> true));
|
db().executeTransaction(new BanStatusTransaction(playerUUID, () -> true));
|
||||||
|
|
||||||
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), true));
|
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), true));
|
||||||
|
|
||||||
assertEquals(expected, userInfo);
|
assertEquals(expected, userInfo);
|
||||||
}
|
}
|
||||||
@ -112,8 +112,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
|
|||||||
|
|
||||||
db().executeTransaction(new OperatorStatusTransaction(playerUUID, true));
|
db().executeTransaction(new OperatorStatusTransaction(playerUUID, true));
|
||||||
|
|
||||||
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, true, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
|
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, true, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
|
||||||
|
|
||||||
assertEquals(expected, userInfo);
|
assertEquals(expected, userInfo);
|
||||||
}
|
}
|
||||||
@ -232,15 +232,15 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
|
|||||||
|
|
||||||
db().executeTransaction(new RemoveDuplicateUserInfoTransaction());
|
db().executeTransaction(new RemoveDuplicateUserInfoTransaction());
|
||||||
|
|
||||||
List<UserInfo> found = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
Set<UserInfo> found = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Collections.singletonList(new UserInfo(playerUUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)),
|
Collections.singleton(new UserInfo(playerUUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)),
|
||||||
found
|
found
|
||||||
);
|
);
|
||||||
|
|
||||||
List<UserInfo> found2 = db().query(UserInfoQueries.fetchUserInformationOfUser(player2UUID));
|
Set<UserInfo> found2 = db().query(UserInfoQueries.fetchUserInformationOfUser(player2UUID));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Collections.singletonList(new UserInfo(player2UUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)),
|
Collections.singleton(new UserInfo(player2UUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)),
|
||||||
found2
|
found2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user