class TypeUtils {

    public static short castToShort(@Nonnull Object value) {
        requireNonNull(value, ERROR_VALUE_NULL);
        if (value instanceof Number) {
            return ((Number) value).shortValue();
        }
        return Short.valueOf(String.valueOf(value));
    }

}

class TypeUtilsTest {

    @Test
    public void castToShort() {

        assertEquals((short) 10, TypeUtils.castToShort(Short.valueOf("10")));
        assertEquals((short) 10, TypeUtils.castToShort(Integer.valueOf("10")));
        assertEquals((short) 10, TypeUtils.castToShort("10"));
        assertEquals((short) 10, TypeUtils.castToShort("10", (short) 10));
        assertEquals((short) 10, TypeUtils.castToShort(null, (short) 10));
    }

}