### Question:
DoubleValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { rval = new DoubleWritable(Double.parseDouble(value.toString())); } } catch (NumberFormatException e) { log.severe(String.format("Failed to convert value {%s} to Double", value)); } return rval; } DoubleValueMapper(String fieldName); @Override Writable getValue(BSONWritable entity);  }### Answer:
@Test public void testGetValue() { BSONObject field = new BasicBSONObject("field", 1.312D); BSONObject entry = new BasicBSONObject("double", field); BSONWritable entity = new BSONWritable(entry); DoubleValueMapper mapper = new DoubleValueMapper("double.field"); Writable value = mapper.getValue(entity); assertFalse(value instanceof NullWritable); assertTrue(value instanceof DoubleWritable); assertEquals(((DoubleWritable) value).get(), 1.312D, 0.05); }
@Test public void testValueNotFound() { BSONObject field = new BasicBSONObject("field", 1.312D); BSONObject entry = new BasicBSONObject("double", field); BSONWritable entity = new BSONWritable(entry); DoubleValueMapper mapper = new DoubleValueMapper("double.missing_field"); Writable value = mapper.getValue(entity); assertTrue(value instanceof NullWritable); }
@Test public void testGetValueNotDouble() { BSONObject field = new BasicBSONObject("field", "Bob"); BSONObject entry = new BasicBSONObject("double", field); BSONWritable entity = new BSONWritable(entry); DoubleValueMapper mapper = new DoubleValueMapper("double.field"); Writable value = mapper.getValue(entity); assertTrue(value instanceof NullWritable); }