CodecAssert class lets you verify that your codecs correctly round-trip data and gracefully handle malformed input.
CodecAssert Methods
| Method | Description |
|---|---|
assertRoundTrip(codec, value) | Encode then decode; assert result equals original |
assertRoundTrip(codec, value, equalityCheck) | Round-trip with custom equality predicate |
assertDecodeEquals(codec, bsonValue, expected) | Decode and assert result equals expected |
assertDecodeThrows(codec, malformedBson) | Assert decoding throws an exception |
Round-Trip Testing
The most common codec test: encode a value, decode it back, and verify the result matches the original.assertRoundTrip calls codec.encode(value) and then codec.decode(encoded), comparing the results with Objects.equals().
Custom equality
If your type does not implementequals() correctly (or you want partial comparison), provide a custom BiPredicate:
Decode Verification
Test that decoding a specific BSON value produces the expected result:Malformed Input
Verify that your codec rejects invalid data instead of silently producing garbage:Complete Example Suite
How It Works Internally
CodecAssert uses reflection to find and invoke encode() and decode() methods on the codec object. This means it works with any codec that follows the standard Hytale pattern — no compile-time coupling required.
The codec parameter is typed as
Object in the API to avoid depending on HytaleServer.jar classes. At runtime, it should be a Hytale Codec<T> instance.Next Steps
- Networking — packet round-trip testing
- ECS Testing — test component serialization in context
- Benchmarks — measure codec performance