#1265 Limbo: fallback to old "group" during deserialization, favor old limbo's groups over new limbo's
This commit is contained in:
@@ -9,6 +9,7 @@ import org.hamcrest.TypeSafeMatcher;
|
||||
import java.util.Collection;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
||||
|
||||
/**
|
||||
* Contains matchers for LimboPlayer.
|
||||
@@ -19,17 +20,20 @@ public final class LimboPlayerMatchers {
|
||||
}
|
||||
|
||||
public static Matcher<LimboPlayer> isLimbo(LimboPlayer limbo) {
|
||||
return isLimbo(limbo.isOperator(), limbo.getGroups(), limbo.isCanFly(),
|
||||
limbo.getWalkSpeed(), limbo.getFlySpeed());
|
||||
String[] groups = limbo.getGroups().toArray(new String[limbo.getGroups().size()]);
|
||||
return isLimbo(limbo.isOperator(), limbo.isCanFly(), limbo.getWalkSpeed(), limbo.getFlySpeed(), groups);
|
||||
}
|
||||
|
||||
public static Matcher<LimboPlayer> isLimbo(boolean isOp, Collection<String> groups, boolean canFly,
|
||||
float walkSpeed, float flySpeed) {
|
||||
public static Matcher<LimboPlayer> isLimbo(boolean isOp, boolean canFly, float walkSpeed, float flySpeed,
|
||||
String... groups) {
|
||||
return new TypeSafeMatcher<LimboPlayer>() {
|
||||
@Override
|
||||
protected boolean matchesSafely(LimboPlayer item) {
|
||||
return item.isOperator() == isOp && item.getGroups().equals(groups) && item.isCanFly() == canFly
|
||||
&& walkSpeed == item.getWalkSpeed() && flySpeed == item.getFlySpeed();
|
||||
return item.isOperator() == isOp
|
||||
&& collectionContains(item.getGroups(), groups)
|
||||
&& item.isCanFly() == canFly
|
||||
&& walkSpeed == item.getWalkSpeed()
|
||||
&& flySpeed == item.getFlySpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,4 +115,12 @@ public final class LimboPlayerMatchers {
|
||||
return hasLocation(location.getWorld().getName(), location.getX(), location.getY(), location.getZ(),
|
||||
location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
// Hamcrest's contains() doesn't like it when there are no items, so we need to check for the empty case explicitly
|
||||
private static boolean collectionContains(Collection<String> givenItems, String... expectedItems) {
|
||||
if (expectedItems.length == 0) {
|
||||
return givenItems.isEmpty();
|
||||
}
|
||||
return contains(expectedItems).matches(givenItems);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -39,7 +40,7 @@ public class LimboServiceHelperTest {
|
||||
// then
|
||||
assertThat(result.getLocation(), equalTo(oldLocation));
|
||||
assertThat(result.isOperator(), equalTo(true));
|
||||
assertThat(result.getGroups(), equalTo(Collections.singletonList("grp-new")));
|
||||
assertThat(result.getGroups(), contains("grp-old"));
|
||||
assertThat(result.isCanFly(), equalTo(true));
|
||||
assertThat(result.getWalkSpeed(), equalTo(0.1f));
|
||||
assertThat(result.getFlySpeed(), equalTo(0.8f));
|
||||
@@ -58,7 +59,7 @@ public class LimboServiceHelperTest {
|
||||
// then
|
||||
assertThat(result.getLocation(), equalTo(newLocation));
|
||||
assertThat(result.isOperator(), equalTo(false));
|
||||
assertThat(result.getGroups(), equalTo(Collections.singletonList("grp-new")));
|
||||
assertThat(result.getGroups(), contains("grp-new"));
|
||||
assertThat(result.isCanFly(), equalTo(true));
|
||||
assertThat(result.getWalkSpeed(), equalTo(0.3f));
|
||||
assertThat(result.getFlySpeed(), equalTo(0.1f));
|
||||
|
||||
+4
-4
@@ -46,22 +46,22 @@ public class DistributedFilesPersistenceHandlerTest {
|
||||
/** Player is in seg32-10110 and should be migrated into seg16-f. */
|
||||
private static final UUID MIGRATED_UUID = fromString("f6a97c88-7c8f-c12e-4931-6206d4ca067d");
|
||||
private static final Matcher<LimboPlayer> MIGRATED_LIMBO_MATCHER =
|
||||
isLimbo(false, Collections.singletonList("noob"), true, 0.2f, 0.1f);
|
||||
isLimbo(false, true, 0.2f, 0.1f, "noob");
|
||||
|
||||
/** Existing player in seg16-f. */
|
||||
private static final UUID UUID_FAB69 = fromString("fab69c88-2cd0-1fed-f00d-dead14ca067d");
|
||||
private static final Matcher<LimboPlayer> FAB69_MATCHER =
|
||||
isLimbo(false, Collections.emptyList(), false, 0.2f, 0.1f);
|
||||
isLimbo(false, false, 0.2f, 0.1f, "");
|
||||
|
||||
/** Player in seg16-8. */
|
||||
private static final UUID UUID_STAFF = fromString("88897c88-7c8f-c12e-4931-6206d4ca067d");
|
||||
private static final Matcher<LimboPlayer> STAFF_MATCHER =
|
||||
isLimbo(true, Collections.singletonList("staff"), false, 0.3f, 0.1f);
|
||||
isLimbo(true, false, 0.3f, 0.1f, "staff", "mod");
|
||||
|
||||
/** Player in seg16-8. */
|
||||
private static final UUID UUID_8C679 = fromString("8c679491-1234-abcd-9102-1fa6e0cc3f81");
|
||||
private static final Matcher<LimboPlayer> SC679_MATCHER =
|
||||
isLimbo(false, Collections.singletonList("primary"), true, 0.1f, 0.0f);
|
||||
isLimbo(false, true, 0.1f, 0.0f, "primary");
|
||||
|
||||
/** UUID for which no data is stored (belongs to a segment file that does not exist, seg16-4). */
|
||||
private static final UUID UNKNOWN_UUID = fromString("42d1cc0b-8f12-d04a-e7ba-a067d05cdc39");
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import java.nio.file.Files;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
@@ -79,7 +80,7 @@ public class IndividualFilesPersistenceHandlerTest {
|
||||
assertThat(data.isCanFly(), equalTo(true));
|
||||
assertThat(data.getWalkSpeed(), equalTo(0.2f));
|
||||
assertThat(data.getFlySpeed(), equalTo(0.1f));
|
||||
assertThat(data.getGroups(), equalTo(Collections.singletonList("players")));
|
||||
assertThat(data.getGroups(), contains("players"));
|
||||
Location location = data.getLocation();
|
||||
assertThat(location.getX(), equalTo(-113.219));
|
||||
assertThat(location.getY(), equalTo(72.0));
|
||||
|
||||
Reference in New Issue
Block a user