MBeanValueConverter { public Object convertParameterValue(String parameterName, String type) throws NumberFormatException, UnhandledParameterTypeException { String[] valueList = parameterMap.get(parameterName); if (valueList == null || valueList.length == 0) return null; String value = valueList[0]; if (value.equals("<null>")) return null; if (type.equals("java.lang.String")) return value; if (type.equals("boolean")) return Boolean.parseBoolean(value); if (type.equals("int")) return Integer.parseInt(value); if (type.equals("long")) return Long.parseLong(value); if (type.equals("float")) return Float.parseFloat(value); if (type.equals("double")) return Double.parseDouble(value); throw new UnhandledParameterTypeException("Cannot convert " + value + " into type " + type + " for parameter " + parameterName); } MBeanValueConverter(Map<String, String[]> parameterMap); Object convertParameterValue(String parameterName, String type);  }
@Test public void testNonProvidedValue() throws Exception { assertEquals(null, converter.convertParameterValue("not_in_the_map", "")); }
@Test public void testNullString() throws Exception { assertEquals(null, converter.convertParameterValue("nullString", "any_type_will_do")); }
@Test public void testStringValue() throws Exception { assertEquals("some_string", converter.convertParameterValue("stringValue", "java.lang.String")); }
@Test public void testBooleanValue() throws Exception { assertEquals(true, converter.convertParameterValue("booleanValue", "boolean")); }
@Test public void testIntValue() throws Exception { assertEquals(123, converter.convertParameterValue("intValue", "int")); }
@Test public void testLongValue() throws Exception { assertEquals((long)456, converter.convertParameterValue("longValue", "long")); }
@Test public void testFloatValue() throws Exception { assertEquals((float)123.45, converter.convertParameterValue("floatValue", "float")); }
@Test public void testDoubleValue() throws Exception { assertEquals(456.78, converter.convertParameterValue("doubleValue", "double")); }
@Test(expected=UnhandledParameterTypeException.class) public void testUnhandledType() throws Exception { converter.convertParameterValue("stringValue", "unknown_type"); }