EntityCodec implements CollectibleCodec<T> { @Override public boolean documentHasId(T document) { return idHandler.get(document) != null; } EntityCodec(Class<T> entityClass, EntityIdHandler<T> idHandler, EntityEncoder<T> encoder, EntityDecoder<T> decoder); @Override T generateIdIfAbsentFromDocument(T document); @Override boolean documentHasId(T document); @Override BsonValue getDocumentId(T document); @Override void encode(BsonWriter writer, T value, EncoderContext encoderContext); @Override T decode(BsonReader reader, DecoderContext decoderContext); @Override Class<T> getEncoderClass();  }
@Test void documentHasId() { assertFalse(entityCodec.documentHasId(new TestEntity())); TestEntity entity = new TestEntity(); entity.id = new ObjectId(); assertTrue(entityCodec.documentHasId(entity)); }