### Question:
CompareRequestProtocolOp extends ProtocolOp { public void toString(StringBuilder buffer) { buffer.append("CompareRequest(dn="); buffer.append(dn); buffer.append(", attribute="); buffer.append(attributeType); buffer.append(", value="); buffer.append(assertionValue); buffer.append(")"); } CompareRequestProtocolOp(ByteString dn, String attributeType,
                                  ByteString assertionValue); ByteString getDN(); String getAttributeType(); ByteString getAssertionValue(); byte getType(); String getProtocolOpName(); void write(ASN1Writer stream); void toString(StringBuilder buffer); void toString(StringBuilder buffer, int indent);  }### Answer:
@Test public void TestToStringSingleLine() throws Exception { CompareRequestProtocolOp compareRequest = new CompareRequestProtocolOp( dn, attributeType, assertionValue); StringBuilder buffer = new StringBuilder(); compareRequest.toString(buffer); String key = "CompareRequest(dn=" + dn + ", attribute=" + attributeType + ", value=" + assertionValue + ")"; assertEquals(buffer.toString(), key); }
@Test public void TestToStringMultiLine() throws Exception { int indent = 5; CompareRequestProtocolOp compareRequest = new CompareRequestProtocolOp(dn, attributeType, assertionValue); StringBuilder buffer = new StringBuilder(); compareRequest.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("Compare Request").append(EOL); key.append(indentBuf).append(" Target DN: ").append(dn).append(EOL); key.append(indentBuf).append(" Attribute Type: ").append(attributeType).append(EOL); key.append(indentBuf).append(" Assertion Value:").append(EOL); key.append(assertionValue.toHexPlusAsciiString(indent+4)); assertEquals(buffer.toString(), key.toString()); }