@Test
public void testExceptionUndefined()
{

    JSONConfig cfg = new JSONConfig().setUseECMA6(false).setBadCharacterPolicy(JSONConfig.EXCEPTION);
    Random rand = new Random();
    for ( int i = 0; i <= BAD_CHARS; i++ ){
        int cp = getRandomUndefined(rand);
        try{
            JSONUtil.toJSON(undefinedTestMap(cp), cfg);
            fail("Expected a UndefinedCodePointException to be thrown.");
        }catch ( UndefinedCodePointException e ){
            assertThat(e.getMessage(), containsString(String.format("Undefined code point U+%04X at position", cp)));
        }
    }
}