### Question:
UtilMongoDB { public static Cells getCellFromBson(BSONObject bsonObject, String tableName) { Cells cells = tableName != null ? new Cells(tableName) : new Cells(); Map<String, Object> map = bsonObject.toMap(); Set<Map.Entry<String, Object>> entryBson = map.entrySet(); for (Map.Entry<String, Object> entry : entryBson) { try { if (List.class.isAssignableFrom(entry.getValue().getClass())) { List innerCell = new ArrayList<>(); for (Object innerBson : (List)entry.getValue()) { if(innerBson instanceof DBObject){ innerCell.add(getCellFromBson((DBObject)innerBson, null)); }else{ innerCell.add(innerBson); } } cells.add(Cell.create(entry.getKey(), innerCell)); } else if (BSONObject.class.isAssignableFrom(entry.getValue().getClass())) { Cells innerCells = getCellFromBson((BSONObject) entry.getValue(), null); cells.add(Cell.create(entry.getKey(), innerCells)); } else { cells.add(Cell.create(entry.getKey(), entry.getValue())); } } catch (IllegalArgumentException e) { LOG.error("impossible to create a java cell from Bson field:" + entry.getKey() + ", type:" + entry .getValue().getClass() + ", value:" + entry.getValue()); } } return cells; } private  UtilMongoDB(); static T getObjectFromBson(Class<T> classEntity, BSONObject bsonObject); static DBObject getBsonFromObject(T t); static Object getId(T t); static Cells getCellFromBson(BSONObject bsonObject, String tableName); static DBObject getDBObjectFromCell(Cells cells); static final String MONGO_DEFAULT_ID; }### Answer:
@Test public void testGetCellFromBson() throws UnknownHostException, NoSuchFieldException, IllegalAccessException, InvocationTargetException, InstantiationException { DBObject bson = createBsonTest(); Cells cells = UtilMongoDB.getCellFromBson(bson, "book"); Map<String, Object> mapMetadata = (Map<String, Object>) bson.get("metadata"); assertEquals(mapMetadata.get("author"), ((Cells) cells.getCellByName("metadata").getCellValue()).getCellByName("author").getCellValue()); assertEquals(mapMetadata.get("title"), ((Cells) cells.getCellByName("metadata").getCellValue()).getCellByName("title").getCellValue()); assertEquals(mapMetadata.get("source"), ((Cells) cells.getCellByName("metadata").getCellValue()).getCellByName("source").getCellValue()); List<Cells> list = (List<Cells>) cells.getCellByName("cantos").getCellValue(); List<Map<String, Object>> mapCantos = (List<Map<String, Object>>) bson.get("cantos"); assertEquals(mapCantos.get(0).get("canto"), list.get(0).getCellByName("canto").getCellValue()); assertEquals(mapCantos.get(0).get("text"), list.get(0).getCellByName("text").getCellValue()); assertEquals(mapCantos.get(1).get("canto"), list.get(1).getCellByName("canto").getCellValue()); assertEquals(mapCantos.get(1).get("text"), list.get(1).getCellByName("text").getCellValue()); }