@Test
public void testGetKeyValue() throws Exception
{

    // Create a JSON object with one key value pair.
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(String.format("{\"%s\" : \"%s\"}", KEY, VALUE));
    // Get and validate the key value.
    assertEquals(VALUE, jsonHelper.getKeyValue(jsonObject, KEY, String.class));
    // Try to get a value for a non-existing key.
    try
    {
        jsonHelper.getKeyValue(jsonObject, I_DO_NOT_EXIST, String.class);
        fail();
    }
    catch (IllegalArgumentException e)
    {
        assertEquals(String.format("Failed to get \"%s\" key value from JSON object.", I_DO_NOT_EXIST), e.getMessage());
    }
    // Try to get a value that cannot be cast to the specified class type.
    try
    {
        jsonHelper.getKeyValue(jsonObject, KEY, BigDecimal.class);
        fail();
    }
    catch (IllegalArgumentException e)
    {
        assertEquals(String.format("Failed to cast \"%s\" key value to %s.", VALUE, BigDecimal.class.getName()), e.getMessage());
    }
}