public static BsonDocument extractQuery(Repositories.Criteria criteria) {
    Preconditions.checkNotNull(criteria, "criteria");

    try {
      final Field field = criteria.getClass().getDeclaredField("constraint");
      field.setAccessible(true);
      Constraints.Constraint constraint = (Constraints.Constraint) field.get(criteria);
      return Support.convertToBson(constraint)
              .toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry());
    } catch (NoSuchFieldException e) {
      throw new RuntimeException("private field 'constraint' not found in " + criteria, e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
Convert criteria to mongo query (for testing). Currently using reflection (since exposed
only in tests).

@return Query (as {@link BsonDocument}) which will be sent to mongo.
mongo/test/org/immutables/mongo/fixture/MongoAsserts.java