MarkupWriterImpl implements MarkupWriter { public void attributes(Object... namesAndValues) { ensureCurrentElement(); int i = 0; int length = namesAndValues.length; if (length % 2 != 0) throw new IllegalArgumentException(String.format("Writing attributes of the element '%s' failed. An attribute name or value is omitted [%s]. Please provide an even number of values, alternating names and values.", current.getName(), InternalUtils.join(Arrays .asList(namesAndValues)))); while (i < length) { String name = namesAndValues[i++].toString(); Object value = namesAndValues[i++]; if (value == null) continue; current.attribute(name, value.toString()); } } MarkupWriterImpl();  MarkupWriterImpl(MarkupModel model);  MarkupWriterImpl(MarkupModel model, String encoding, String mimeType); void toMarkup(PrintWriter writer); @Override String toString(); Document getDocument(); Element getElement(); void cdata(String content); void write(String text); void writef(String format, Object... args); void attributes(Object... namesAndValues); Element element(String name, Object... namesAndValues); void writeRaw(String text); Element end(); void comment(String text); Element attributeNS(String namespace, String attributeName, String attributeValue); Element defineNamespace(String namespace, String namespacePrefix); Element elementNS(String namespace, String elementName); void addListener(MarkupWriterListener listener); void removeListener(MarkupWriterListener listener);  }
@Test(expectedExceptions = IllegalStateException.class) public void attributes_with_no_current_element() { MarkupWriter w = new MarkupWriterImpl(); w.attributes("fail", "now"); }
@Test public void attributes() { MarkupWriter w = new MarkupWriterImpl(); w.element("root"); w.attributes("foo", "bar", "gnip", "gnop"); assertEquals(w.toString(), "<root gnip=\"gnop\" foo=\"bar\"></root>"); }