ScriptUtils { public static String buildEventHandlerScript(String id, String eventName, String eventScript) { if (StringUtils.isBlank(eventScript)) { return ""; } Assert.hasLength(id, "Id is required for building event handler script"); Assert.hasLength(eventName, "Event name is required for building event handler script"); StringBuffer sb = new StringBuffer(); sb.append("jQuery('#" + id + "').on('"); sb.append(eventName); sb.append("', function(e) {"); sb.append(eventScript); sb.append("}); "); return sb.toString(); }  static String translateValue(Object value); static String toJSON(Map<String, String> map); static String escapeJSONString(String jsonString); static String convertToJsValue(Map<String, String> stringMap); static String convertToJsValue(String value); static String escapeName(String name); static String convertStringListToJsArray(List<String> list); static String escapeHtml(String string); static List<String> escapeHtml(List<String> strings); static String appendScript(String script, String appendScript); static String buildFunctionCall(String functionName, Object... arguments); static String buildEventHandlerScript(String id, String eventName, String eventScript);  }
@Test public void testBuildEventHandlerScript() { String onClickScript = "alert('A click happened');"; String onClickHandler = ScriptUtils.buildEventHandlerScript("u09", "click", onClickScript); String expectedHandler = "jQuery('#u09').on('click', function(e) {" + onClickScript + "}); "; assertEquals("generate event script is not correct", expectedHandler, onClickHandler); }