### Question:
AddRequestProtocolOp extends ProtocolOp { @Override public void toString(StringBuilder buffer) { buffer.append("AddRequest(dn="); buffer.append(dn); buffer.append(", attrs={"); if (! attributes.isEmpty()) { Iterator<RawAttribute> iterator = attributes.iterator(); iterator.next().toString(buffer); while (iterator.hasNext()) { buffer.append(", "); iterator.next().toString(buffer); } } buffer.append("})"); } AddRequestProtocolOp(ByteString dn);  AddRequestProtocolOp(ByteString dn, List<RawAttribute> attributes); ByteString getDN(); List<RawAttribute> getAttributes(); @Override byte getType(); @Override String getProtocolOpName(); @Override void write(ASN1Writer stream); @Override void toString(StringBuilder buffer); @Override void toString(StringBuilder buffer, int indent); void toLDIF(StringBuilder buffer, int wrapColumn);  }### Answer:
@Test public void TestToStringSingleLine() throws Exception { StringBuilder buffer = new StringBuilder(); int numAttributes = 10; int numValues = 5; List<RawAttribute> attributes = generateAttributes(numAttributes, numValues, "test"); AddRequestProtocolOp addRequest = new AddRequestProtocolOp(dn, attributes); addRequest.toString(buffer); StringBuilder key = new StringBuilder(); key.append("AddRequest(dn=").append(dn).append(", attrs={"); for (int i = 0; i < numAttributes; i++) { attributes.get(i).toString(key); if(i < numAttributes - 1) { key.append(", "); } } key.append("})"); assertEquals(buffer.toString(), key.toString()); }
@Test public void TestToStringMultiLine() throws Exception { StringBuilder buffer = new StringBuilder(); int numAttributes = 10; int numValues = 5; int indent = 5; List<RawAttribute> attributes = generateAttributes(numAttributes, numValues, "test"); AddRequestProtocolOp addRequest = new AddRequestProtocolOp(dn, attributes); addRequest.toString(buffer, indent); StringBuilder indentBuf = new StringBuilder(indent); for (int i = 0; i < indent; i++) { indentBuf.append(' '); } StringBuilder key = new StringBuilder(); key.append(indentBuf).append("Add Request").append(EOL); key.append(indentBuf).append(" DN: ").append(dn).append(EOL); key.append(" Attributes:").append(EOL); for (RawAttribute attribute : attributes) { attribute.toString(key, indent+4); } assertEquals(buffer.toString(), key.toString()); }