### Question:
TypedSettings { public int getInt(String key, int defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Integer) { return (Integer) value; } else if (value instanceof String) { return Integer.parseInt((String) value); } else { throw new ClassCastException(errorMessage(key, value, "integer")); } } TypedSettings(Map<String, Object> map); String getString(String key, String defaultValue); boolean getBoolean(String key, boolean defaultValue); int getInt(String key, int defaultValue); long getLong(String key, int defaultValue); double getDouble(String key, double defaultValue); float getFloat(String key, float defaultValue); Object getObject(String key, Object defaultValue); static final String DRY_RUN_SETTING_NAME; static final String TASK_CONTEXT_SETTING_NAME; }### Answer:
@Test public void getInt() throws Exception { String key = "myKey"; assertEquals(1, settings.getInt(key, 1)); assertEquals(2, settings.getInt(key, 2)); map.put(key, 3); assertEquals(3, settings.getInt(key, 2)); map.put(key, "4"); assertEquals(4, settings.getInt(key, 2)); map.put(key, new Object()); try { settings.getInt(key, 9); fail(); } catch (ClassCastException e) { ; } }