feat(02-01): add GravityFlipRegion POJO + BuilderCodec with round-trip tests
- GravityFlipRegion holds Name (String) + Box (Hytale AABB) + Enabled (boolean), serialised through a BuilderCodec keyed on "Name"/"Box"/"Enabled". - Validators.nonNull() applied to Name and Box (correct package is com.hypixel.hytale.codec.validation.Validators, not codec.builder). - Server jar 2026.03.26 uses com.hypixel.hytale.math.vector.Vector3d for Box.min/max (NOT org.joml.Vector3d, which only appeared in newer builds). - 3 JUnit 5 round-trip tests cover name/box/enabled, enabled=false, and empty name. - testImplementation added for the Server artifact so codec encode/decode is reachable from unit tests.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.mythlane.gravityflip.region;
|
||||
|
||||
import com.hypixel.hytale.codec.ExtraInfo;
|
||||
import com.hypixel.hytale.math.shape.Box;
|
||||
import org.bson.BsonValue;
|
||||
import com.hypixel.hytale.math.vector.Vector3d;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Round-trip tests for {@link GravityFlipRegion#CODEC}. Verifies the codec preserves
|
||||
* Name + Box + Enabled fields across encode -> decode cycles via the BSON intermediate
|
||||
* representation that all Hytale codecs share.
|
||||
*/
|
||||
class GravityFlipRegionCodecTest {
|
||||
|
||||
@Test
|
||||
void roundTripPreservesNameBoxEnabled() {
|
||||
GravityFlipRegion src = new GravityFlipRegion(
|
||||
"zone1",
|
||||
new Box(new Vector3d(1, 2, 3), new Vector3d(4, 5, 6)),
|
||||
true);
|
||||
|
||||
GravityFlipRegion decoded = roundTrip(src);
|
||||
|
||||
assertEquals("zone1", decoded.getName());
|
||||
assertNotNull(decoded.getBox());
|
||||
assertEquals(1.0, decoded.getMin().x);
|
||||
assertEquals(2.0, decoded.getMin().y);
|
||||
assertEquals(3.0, decoded.getMin().z);
|
||||
assertEquals(4.0, decoded.getMax().x);
|
||||
assertEquals(5.0, decoded.getMax().y);
|
||||
assertEquals(6.0, decoded.getMax().z);
|
||||
assertTrue(decoded.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void roundTripPreservesEnabledFalse() {
|
||||
GravityFlipRegion src = new GravityFlipRegion(
|
||||
"off-zone",
|
||||
new Box(new Vector3d(0, 0, 0), new Vector3d(1, 1, 1)),
|
||||
false);
|
||||
|
||||
GravityFlipRegion decoded = roundTrip(src);
|
||||
|
||||
assertEquals("off-zone", decoded.getName());
|
||||
assertFalse(decoded.isEnabled(), "default-true field must not clobber loaded false");
|
||||
}
|
||||
|
||||
@Test
|
||||
void roundTripPreservesEmptyName() {
|
||||
GravityFlipRegion src = new GravityFlipRegion(
|
||||
"",
|
||||
new Box(new Vector3d(0, 0, 0), new Vector3d(1, 1, 1)),
|
||||
true);
|
||||
|
||||
GravityFlipRegion decoded = roundTrip(src);
|
||||
|
||||
assertNotNull(decoded.getName());
|
||||
assertEquals("", decoded.getName(), "empty name must survive round-trip without substitution");
|
||||
}
|
||||
|
||||
private static GravityFlipRegion roundTrip(GravityFlipRegion src) {
|
||||
ExtraInfo info = new ExtraInfo();
|
||||
BsonValue encoded = GravityFlipRegion.CODEC.encode(src, info);
|
||||
return GravityFlipRegion.CODEC.decode(encoded, info);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user