RenderKitUtils { public static String toScriptArgs(Object... objects) { if (objects == null) { return ""; } int lastNonNullIdx = objects.length - 1; for (; 0 <= lastNonNullIdx; lastNonNullIdx--) { if (!isEmpty(objects[lastNonNullIdx])) { break; } } if (lastNonNullIdx < 0) { return ""; } if (lastNonNullIdx == 0) { return ScriptUtils.toScript(objects[lastNonNullIdx]); } StringBuilder sb = new StringBuilder(); for (int i = 0; i <= lastNonNullIdx; i++) { if (sb.length() > 0) { sb.append(","); } sb.append(ScriptUtils.toScript(objects[i])); } return sb.toString(); } private  RenderKitUtils(); static boolean shouldRenderAttribute(Object attributeValue); static String prefixAttributeName(String attributeName, boolean isXhtmlMode); static String prefixAttributeName(String attributeName, ResponseWriter responseWriter); static void renderAttribute(FacesContext facesContext, String attributeName, Object attributeValue); static Object getAttributeAndBehaviorsValue(FacesContext facesContext, UIComponent component,
            ComponentAttribute componentAttribute); static void renderAttributeAndBehaviors(FacesContext facesContext, UIComponent component,
            ComponentAttribute componentAttribute); static void renderPassThroughAttributesOptimized(FacesContext context, UIComponent component,
            Map<String, ComponentAttribute> knownAttributesMap); static void renderPassThroughAttributes(FacesContext context, UIComponent component,
            Map<String, ComponentAttribute> knownAttributesMap); static void renderPassThroughAttributes(FacesContext context, UIComponent component,
            Collection<ComponentAttribute> attributes); static String decodeBehaviors(FacesContext context, UIComponent component); static Attributes attributes(); static Attributes attributes(Enum<?>... attrs); static Attributes attributes(String... attrs); static void addToScriptHash(Map<String, Object> hash, String name, Object value); static void addToScriptHash(Map<String, Object> hash, String name, Object value, Object defaultValue); static void addToScriptHash(Map<String, Object> hash, String name, Object value, Object defaultValue,
            ScriptHashVariableWrapper wrapper); static void addToScriptHash(Map<String, Object> hash, FacesContext facesContext, UIComponent component,
            Attributes attributes, ScriptHashVariableWrapper wrapper); static String toScriptArgs(Object... objects); static String getResourcePath(FacesContext context, String library, String resourceName); static String getResourceURL(String url, FacesContext context); static Object getFirstNonEmptyAttribute(String attributeName, UIComponent component); static Object getFirstNonEmptyAttribute(String attributeName, UIComponent componentA, UIComponent componentB); static Object getFirstNonEmptyAttribute(String attributeName, UIComponent... components); static String getBehaviorSourceId(FacesContext facesContext); static boolean hasFacet(UIComponent component, String facetName); @SuppressWarnings("unchecked") static T evaluateAttribute(String attribute, UIComponent component, FacesContext context);  }
@Test public void testToScriptArgs() throws Exception { assertEquals("", toScriptArgs()); assertEquals("", toScriptArgs((Object) null)); assertEquals("", toScriptArgs((Object[]) null)); assertEquals("\"test\"", toScriptArgs("test")); assertEquals("[5,8]", dehydrate(toScriptArgs(Arrays.asList(5, 8)))); assertEquals("{\"a\":true}", dehydrate(toScriptArgs(Collections.singletonMap("a", true)))); assertEquals("\"test\"", toScriptArgs("test", null)); assertEquals("null,\"test\"", toScriptArgs(null, "test")); assertEquals("\"test\"", toScriptArgs("test", Collections.emptyList())); assertEquals("[],\"test\"", dehydrate(toScriptArgs(Collections.emptyList(), "test"))); assertEquals("\"test\"", toScriptArgs("test", Collections.emptyMap())); assertEquals("{},\"test\"", dehydrate(toScriptArgs(Collections.emptyMap(), "test"))); assertEquals("\"test\"", toScriptArgs("test", "")); assertEquals("\"\",\"test\"", dehydrate(toScriptArgs("", "test"))); assertEquals("1,2,3", toScriptArgs(1, 2, 3, null)); assertEquals("1,2,null,3", toScriptArgs(1, 2, null, 3)); }