### Question:
TypeCoercer { Object coerce(String string, Class<?> cls) { try { if(cls == String.class) { return string; } final Constructor<?> stringConstructor = cls.getConstructor(String.class); if(stringConstructor != null) { return stringConstructor.newInstance(string); } throw new RuntimeException("Unable to coerce '"+string+"' to class "+cls.getName()); } catch (Exception ex) { throw new RuntimeException("Unable to coerce '"+string+"' to class "+cls.getName(), ex); } }    }### Answer:
@Test public void testIntFail() { expectedException.expectMessage("Unable to coerce 'asf' to class java.lang.Integer"); typeCoercer.coerce("asf", "int"); }