### Question:
DoubleSchema extends PrimitiveNumericSchema<Double> { @Override public Object convert(Object value) { if (value instanceof Integer) { return ((Integer) value).doubleValue(); } else if (value instanceof Long) { return ((Long) value).doubleValue(); } else if (value instanceof Float) { return ((Float) value).doubleValue(); } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException nfe) { throw (IllegalArgumentException) new IllegalArgumentException(value + " cannot be parsed to a double").initCause(nfe); } } throw new IllegalArgumentException(value + " is not a double"); } DoubleSchema(); @Override Object convert(Object value);  }### Answer:
@Test public void testConvert() throws Exception { double value = 1.2; Object convertedValue = this.schema.convert("" + value); assertTrue(convertedValue instanceof Double); Double convertedInput = (Double) convertedValue; assertTrue(convertedInput.doubleValue() == value); }
@Test(expected = IllegalArgumentException.class) public void testBadConvert() { this.schema.convert("INVALID INPUT"); }
@Test public void testNonConvert() { Object convertedValue = this.schema.convert(12.345); assertTrue(convertedValue instanceof Double); }
@Test public void testDoubleConverter() { double data = 12.0; float floatData = (float) data; int intData = (int) data; long longData = (long) data; assertTrue("Failure returning same object", this.schema.convert(data).equals(data)); assertTrue("Failure parsing double from long", this.schema.convert(longData).equals(data)); assertTrue("Failure parsing double from integer", this.schema.convert(intData).equals(data)); assertTrue("Failure parsing double from float", this.schema.convert(floatData).equals(data)); assertTrue("Failure parsing double data", this.schema.convert("" + data).equals(data)); }
@Test(expected = IllegalArgumentException.class) public void testInvalidStringThrowsException() throws IllegalArgumentException { this.schema.convert("INVALID INPUT"); }
@Test(expected = IllegalArgumentException.class) public void testUnsupportedObjectTypeThrowsException() throws IllegalArgumentException { this.schema.convert(new Object()); }