### Question:
MathUtils { public static <D extends Number> D cast(Number num, Class<D> type) { D rv; if (num == null || type.isInstance(num)) { rv = type.cast(num); } else if (type.equals(Byte.class)) { rv = type.cast(num.byteValue()); } else if (type.equals(Double.class)) { rv = type.cast(num.doubleValue()); } else if (type.equals(Float.class)) { rv = type.cast(num.floatValue()); } else if (type.equals(Integer.class)) { rv = type.cast(num.intValue()); } else if (type.equals(Long.class)) { rv = type.cast(num.longValue()); } else if (type.equals(Short.class)) { rv = type.cast(num.shortValue()); } else if (type.equals(BigDecimal.class)) { rv = type.cast(new BigDecimal(num.toString())); } else if (type.equals(BigInteger.class)) { if (num instanceof BigDecimal) { rv = type.cast(((BigDecimal) num).toBigInteger()); } else { rv = type.cast(new BigInteger(num.toString())); } } else { throw new IllegalArgumentException(String.format("Unsupported target type : %s", type.getSimpleName())); } return rv; } private  MathUtils(); @SuppressWarnings("unchecked") static D result(D num1, Number num2, Operator operator); @SuppressWarnings("unchecked") static D sum(D num1, Number num2); @SuppressWarnings("unchecked") static D difference(D num1, Number num2); static D cast(Number num, Class<D> type);  }### Answer:
@Test public void cast_returns_null_when_input_is_null() { Integer result = MathUtils.cast(null, Integer.class); assertNull(result); }