RenderKitUtils { static String[] asArray(Object object) { if (object == null) { return null; } Class<?> componentType = object.getClass().getComponentType(); if (String.class.equals(componentType)) { return (String[]) object; } else if (componentType != null) { Object[] objects = (Object[]) object; String[] result = new String[objects.length]; for (int i = 0; i < objects.length; i++) { Object o = objects[i]; if (o == null) { continue; } result[i] = o.toString(); } return result; } else if (object instanceof Collection) { Collection<?> collection = (Collection<?>) object; String[] result = new String[collection.size()]; Iterator<?> iterator = collection.iterator(); for (int i = 0; i < result.length; i++) { Object next = iterator.next(); if (next == null) { continue; } result[i] = next.toString(); } return result; } else { String string = object.toString().trim(); String[] split = string.split("\\s*,\\s*"); return split; } } 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 testAsArray() { assertNull(RenderKitUtils.asArray(null)); }
@Test public void testAsArray1() { String[] strings = new String[] { "a", "b" }; String[] array = RenderKitUtils.asArray(strings); assertSame(strings, array); }
@Test public void testAsArray2() { Object[] objects = new Object[] { Integer.valueOf(12), null, Integer.valueOf(22), Integer.valueOf(42) }; String[] array = RenderKitUtils.asArray(objects); String[] etalon = new String[] { "12", null, "22", "42" }; assertTrue(Arrays.equals(etalon, array)); }
@Test public void testAsArray3() { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(new Integer(12)); list.add(null); list.add(new Integer(22)); list.add(new Integer(42)); String[] array = RenderKitUtils.asArray(list); String[] etalon = new String[] { "12", null, "22", "42" }; assertTrue(Arrays.equals(etalon, array)); }
@Test public void testAsArray31() { Set<Integer> set = new TreeSet<Integer>(); set.add(new Integer(12)); set.add(new Integer(22)); set.add(new Integer(42)); String[] array = RenderKitUtils.asArray(set); String[] etalon = new String[] { "12", "22", "42" }; assertTrue(Arrays.equals(etalon, array)); }
@Test public void testAsArray4() { String string = " a , \t\n b \n , c "; String[] strings = RenderKitUtils.asArray(string); String[] etalon = new String[] { "a", "b", "c" }; assertTrue(Arrays.equals(etalon, strings)); }