Made fetchUserInformationOfUser return a Set instead of List

Fixes tests where there was some order-dependent stuff.
This commit is contained in:
Risto Lahtela 2021-03-18 10:15:39 +02:00
parent 477c547c51
commit 7906126b5e
3 changed files with 23 additions and 22 deletions

View File

@ -33,6 +33,7 @@ import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
@ -94,7 +95,7 @@ public class PerServerContainerQuery implements Query<PerServerContainer> {
}
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);
}

View File

@ -87,7 +87,7 @@ public class UserInfoQueries {
* @param playerUUID UUID of the player.
* @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 +
UserInfoTable.TABLE_NAME + '.' + UserInfoTable.REGISTERED + ',' +
UserInfoTable.BANNED + ',' +
@ -97,15 +97,15 @@ public class UserInfoQueries {
FROM + UserInfoTable.TABLE_NAME +
WHERE + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + "=?";
return new QueryStatement<List<UserInfo>>(sql) {
return new QueryStatement<Set<UserInfo>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, playerUUID.toString());
}
@Override
public List<UserInfo> processResults(ResultSet set) throws SQLException {
List<UserInfo> userInformation = new ArrayList<>();
public Set<UserInfo> processResults(ResultSet set) throws SQLException {
Set<UserInfo> userInformation = new HashSet<>();
while (set.next()) {
long registered = set.getLong(UserInfoTable.REGISTERED);
boolean op = set.getBoolean(UserInfoTable.OP);

View File

@ -46,8 +46,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
assertFalse(db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).isPresent());
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));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
assertEquals(expected, userInfo);
}
@ -57,8 +57,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
assertFalse(db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).isPresent());
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> null));
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, null, false));
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, null, false));
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(), TestConstants.GET_PLAYER_HOSTNAME));
List<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> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
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 PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, TestConstants.SERVER_TWO_UUID, () -> "example.join.address"));
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
List<UserInfo> expected = Arrays.asList(
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
Set<UserInfo> expected = new HashSet<>(Arrays.asList(
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)
);
));
assertEquals(expected, userInfo);
}
@ -99,8 +99,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
db().executeTransaction(new BanStatusTransaction(playerUUID, () -> true));
List<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> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), true));
assertEquals(expected, userInfo);
}
@ -112,8 +112,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
db().executeTransaction(new OperatorStatusTransaction(playerUUID, true));
List<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> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
Set<UserInfo> expected = Collections.singleton(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, true, TestConstants.GET_PLAYER_HOSTNAME.get(), false));
assertEquals(expected, userInfo);
}
@ -232,15 +232,15 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
db().executeTransaction(new RemoveDuplicateUserInfoTransaction());
List<UserInfo> found = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
Set<UserInfo> found = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
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
);
List<UserInfo> found2 = db().query(UserInfoQueries.fetchUserInformationOfUser(player2UUID));
Set<UserInfo> found2 = db().query(UserInfoQueries.fetchUserInformationOfUser(player2UUID));
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
);
}