CodecTestKit

io.github.mbannour.mongo.codecs.CodecTestKit
object CodecTestKit

Testing utilities for BSON codecs.

Provides helper methods for testing codec symmetry and round-trip encoding/decoding.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def assertBsonStructure[T](value: T, expectedBson: BsonDocument)(using codec: Codec[T]): Unit

Test that encoding and decoding produces the expected BSON structure.

Test that encoding and decoding produces the expected BSON structure.

Value parameters

codec

The codec to use

expectedBson

The expected BSON document structure

value

The value to encode

Attributes

Throws
AssertionError

if the encoded value doesn't match expectations

def assertCodecSymmetry[T](value: T)(using codec: Codec[T]): Unit

Assert that a codec maintains symmetry (encode then decode yields original value).

Assert that a codec maintains symmetry (encode then decode yields original value).

This is useful in property-based testing to verify codec correctness.

Value parameters

codec

The codec to test

value

The value to test

Attributes

Throws
AssertionError

if the round-trip does not preserve the value

def fromBsonDocument[T](doc: BsonDocument)(using codec: Codec[T]): T

Decode a BsonDocument to a value using the given codec.

Decode a BsonDocument to a value using the given codec.

Value parameters

codec

The codec to use for decoding

doc

The BsonDocument to decode

Attributes

Returns

The decoded value

def roundTrip[T](value: T)(using codec: Codec[T]): T

Perform a round-trip encode/decode operation.

Perform a round-trip encode/decode operation.

Encodes the value to BSON and then decodes it back, verifying that the codec can correctly serialize and deserialize the data.

Value parameters

codec

The codec to use

value

The value to round-trip

Attributes

Returns

The decoded value after round-tripping

def testRegistry(codecs: Codec[_]*): CodecRegistry

Create a minimal CodecRegistry for testing with only the given codecs.

Create a minimal CodecRegistry for testing with only the given codecs.

Value parameters

codecs

The codecs to include in the registry

Attributes

Returns

A CodecRegistry containing only the specified codecs

def toBsonDocument[T](value: T)(using codec: Codec[T]): BsonDocument

Convert a value to a BsonDocument using the given codec.

Convert a value to a BsonDocument using the given codec.

Value parameters

codec

The codec to use for encoding

value

The value to encode

Attributes

Returns

The encoded BsonDocument