### Question:
AttributesImpl implements Attributes { public void setAttributes(final Attributes atts) { clear(); length = atts.getLength(); if (length > 0) { data = new String[length * 5]; for (int i = 0; i < length; i++) { data[i * 5] = atts.getURI(i); data[i * 5 + 1] = atts.getLocalName(i); data[i * 5 + 2] = atts.getQName(i); data[i * 5 + 3] = atts.getType(i); data[i * 5 + 4] = atts.getValue(i); qNameIndex.putIfAbsent(atts.getQName(i), i); } } } AttributesImpl();  AttributesImpl(final Attributes atts); @Override int getLength(); @Override String getURI(final int index); @Override String getLocalName(final int index); @Override String getQName(final int index); @Override String getType(final int index); @Override String getValue(final int index); @Override int getIndex(final String uri, final String localName); @Override int getIndex(final String qName); @Override String getType(final String uri, final String localName); @Override String getType(final String qName); @Override String getValue(final String uri, final String localName); @Override String getValue(final String qName); void clear(); void setAttributes(final Attributes atts); void addAttribute(final String uri, final String localName, final String qName, final String type, final String value); void setAttribute(final int index, final String uri, final String localName, final String qName, final String type, final String value); void removeAttribute(final int index); void setURI(final int index, final String uri); void setLocalName(final int index, final String localName); void setQName(final int index, final String qName); void setType(final int index, final String type); void setValue(final int index, final String value);  }### Answer:
@Test public void testSetAttributes() { AttributesImpl attributes = new AttributesImpl(); String uri = "xmlns=\"http: String localName = "localname"; String qname = "qname"; String type = "type"; String value = "value"; for (int i = 0; i < 10; i++) { if (i % 2 == 0) { attributes.addAttribute(uri, localName, qname + String.valueOf(i), type, value); } else { attributes.addAttribute(uri, localName, qname, type, value); } } Assert.assertEquals(attributes.getLength(), 10, "Expect length to be 0 before setAttributes"); AttributesImpl newAttributes = new AttributesImpl(); newAttributes.setAttributes(attributes); Assert.assertEquals(newAttributes.getLength(), attributes.getLength(), "After setAttribute both length should be equal"); for (int i = 0; i < 10; i++) { if (i % 2 == 0) { Assert.assertEquals(newAttributes.getIndex(qname + String.valueOf(i)), i); } else { Assert.assertEquals(newAttributes.getIndex(qname), 1, "Odd number attributes will always point for first attributes since qname is same"); } } }