@Test
public void testLoop() throws ScriptException
{

    Map<String,Object> jsonObj = new HashMap<>(4);
    jsonObj.put("a",1);
    jsonObj.put("b",2);
    jsonObj.put("c",3);
    jsonObj.put("x", jsonObj);
    JSONConfig cfg = new JSONConfig();
    try{
        JSONUtil.toJSON(jsonObj, cfg);
        fail("Expected a DataStructureLoopException to be thrown");
    }catch ( DataStructureLoopException e ){
        assertThat(e.getMessage(), containsString("java.util.HashMap includes itself which would cause infinite recursion."));
    }
}