### Question:
MongoUtils { public static void ensureIndex(DBCollection collection, String fieldName, boolean unique, boolean sparse) { BasicDBObject indexKey = new BasicDBObject(); indexKey.put(fieldName, 1); BasicDBObject option = new BasicDBObject(); if (sparse) { option.put("sparse", true); } if (unique) { option.put("unique", true); } collection.ensureIndex(indexKey, option); }  static void ensureIndex(DBCollection collection, String fieldName, boolean unique, boolean sparse); static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update);  }### Answer:
@Test public void testEnsureIndex() { MongoDataSource ds = getDataSource(); Mongo mongo = ds.getMongoInstance(); mongo.dropDatabase(DB); DBCollection coll = mongo.getDB(DB).getCollection(COLL); MongoUtils.ensureIndex(coll, "fieldName", false, false); MongoUtils.ensureIndex(coll, "fieldName", true, false); MongoUtils.ensureIndex(coll, "fieldName", true, true); MongoUtils.ensureIndex(coll, "fieldName", false, true); }