### Question:
ValueUtil { public static Integer getInt(Object obj) { if(obj == null) { return null; } else if(obj instanceof String) { return Integer.valueOf((String) obj); } else { try { Method method = obj.getClass().getMethod("intValue"); return (int) method.invoke(obj); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new RuntimeException("Unable to convert " + obj + " into Interger",e); } } }  static Integer getInt(Object obj);  }### Answer:
@Test public void testGetInt() { Integer result = ValueUtil.getInt(null); Assert.assertNull(result); result = ValueUtil.getInt("100"); Assert.assertEquals(result, new Integer(100)); result = ValueUtil.getInt(new Long(100)); Assert.assertEquals(result, new Integer(100)); try { ValueUtil.getInt(new Object()); } catch (Exception e) { Assert.assertTrue(e.getMessage().contains("Unable to convert")); } }
@Test(expectedExceptions = RuntimeException.class) public void testGetInt() { Integer result = ValueUtil.getInt(null); Assert.assertNull(result); result = ValueUtil.getInt("100"); Assert.assertEquals(result, new Integer(100)); result = ValueUtil.getInt(new Long(100)); Assert.assertEquals(result, new Integer(100)); ValueUtil.getInt(new Object()); }