@Test public void returnsDefaultValueWhenMalformedIntParamAndDefaultValueGiven() throws Exception { Map<String, String> params = newHashMap(); params.put("key1", "12s3"); params.put("key2", "value2"); ParamReader paramReader = new ParamReader(params, "object"); Integer result = paramReader.getIntValue("key1", 1000); assertThat(result, equalTo(1000)); }
public Integer getIntValue(String paramName) { String value = params.get(paramName); if (value == null) { return null; } try { return Integer.parseInt(value); } catch (NumberFormatException e) { String message = getNumberFormatErrorMessage(paramName, value); LOG.error(message); return null; } }
ParamReader { public Integer getIntValue(String paramName) { String value = params.get(paramName); if (value == null) { return null; } try { return Integer.parseInt(value); } catch (NumberFormatException e) { String message = getNumberFormatErrorMessage(paramName, value); LOG.error(message); return null; } } }
ParamReader { public Integer getIntValue(String paramName) { String value = params.get(paramName); if (value == null) { return null; } try { return Integer.parseInt(value); } catch (NumberFormatException e) { String message = getNumberFormatErrorMessage(paramName, value); LOG.error(message); return null; } } ParamReader(Map<String, String> params, String parametrizedObjectLabel); }
ParamReader { public Integer getIntValue(String paramName) { String value = params.get(paramName); if (value == null) { return null; } try { return Integer.parseInt(value); } catch (NumberFormatException e) { String message = getNumberFormatErrorMessage(paramName, value); LOG.error(message); return null; } } ParamReader(Map<String, String> params, String parametrizedObjectLabel); String getLabel(); String getRequiredStringValue(String paramName); String getStringValue(String paramName); String getStringValue(String paramName, String defaultValue); Integer getRequiredIntValue(String paramName); Integer getIntValue(String paramName); int getIntValue(String paramName, int defaultValue); Long getRequiredLongValue(String paramName); Long getLongValue(String paramName); long getLongValue(String paramName, long defaultValue); }
ParamReader { public Integer getIntValue(String paramName) { String value = params.get(paramName); if (value == null) { return null; } try { return Integer.parseInt(value); } catch (NumberFormatException e) { String message = getNumberFormatErrorMessage(paramName, value); LOG.error(message); return null; } } ParamReader(Map<String, String> params, String parametrizedObjectLabel); String getLabel(); String getRequiredStringValue(String paramName); String getStringValue(String paramName); String getStringValue(String paramName, String defaultValue); Integer getRequiredIntValue(String paramName); Integer getIntValue(String paramName); int getIntValue(String paramName, int defaultValue); Long getRequiredLongValue(String paramName); Long getLongValue(String paramName); long getLongValue(String paramName, long defaultValue);  }