### Question:
ScriptUtils { public static String escapeCSSMetachars(String s) { if (s == null || s.length() == 0) { return s; } StringBuilder builder = new StringBuilder(); int start = 0; int idx = 0; int length = s.length(); for (; idx < length; idx++) { char c = s.charAt(idx); int searchIdx = Arrays.binarySearch(CSS_SELECTOR_CHARS_TO_ESCAPE, c); if (searchIdx >= 0) { builder.append(s.substring(start, idx)); builder.append("\\"); builder.append(c); start = idx + 1; } } builder.append(s.substring(start, idx)); return builder.toString(); } private  ScriptUtils(); static void writeToStream(final ResponseWriter responseWriter, Object obj); static String toScript(Object obj); static void appendScript(Appendable appendable, Object obj); static void appendEncodedString(Appendable appendable, Object obj); static void appendEncoded(Appendable appendable, Object obj); static String getValidJavascriptName(String script); static String getMD5scriptHash(String script); static boolean shouldRenderAttribute(Object attributeVal); static boolean shouldRenderAttribute(String attributeName, Object attributeVal); static boolean isValidProperty(Object property); static String escapeCSSMetachars(String s);  }### Answer:
@Test public void testEscapeStringForCSSSelector() throws Exception { assertNull(ScriptUtils.escapeCSSMetachars(null)); assertEquals("", ScriptUtils.escapeCSSMetachars("")); assertEquals("test", ScriptUtils.escapeCSSMetachars("test")); assertEquals("test\\.string", ScriptUtils.escapeCSSMetachars("test.string")); assertEquals("test\\.\\=string", ScriptUtils.escapeCSSMetachars("test.=string")); assertEquals("some\\.test\\=string", ScriptUtils.escapeCSSMetachars("some.test=string")); assertEquals("\\#test", ScriptUtils.escapeCSSMetachars("#test")); assertEquals("\\#\\=test", ScriptUtils.escapeCSSMetachars("#=test")); assertEquals("test\\#", ScriptUtils.escapeCSSMetachars("test#")); assertEquals("test\\#\\=", ScriptUtils.escapeCSSMetachars("test#=")); }