### Question:
CompareResponseProtocolOp extends ProtocolOp { @Override public void toString(StringBuilder buffer) { buffer.append("CompareResponse(resultCode="); buffer.append(resultCode); if (errorMessage != null && errorMessage.length() > 0) { buffer.append(", errorMessage="); buffer.append(errorMessage); } if (matchedDN != null) { buffer.append(", matchedDN="); buffer.append(matchedDN); } if (referralURLs != null && !referralURLs.isEmpty()) { buffer.append(", referralURLs={"); Utils.joinAsString(buffer, ", ", referralURLs); buffer.append("}"); } buffer.append(")"); } CompareResponseProtocolOp(int resultCode);  CompareResponseProtocolOp(int resultCode, LocalizableMessage errorMessage);  CompareResponseProtocolOp(int resultCode, LocalizableMessage errorMessage,
                                   DN matchedDN, List<String> referralURLs); int getResultCode(); LocalizableMessage getErrorMessage(); DN getMatchedDN(); List<String> getReferralURLs(); @Override byte getType(); @Override String getProtocolOpName(); @Override void write(ASN1Writer stream); @Override void toString(StringBuilder buffer); @Override void toString(StringBuilder buffer, int indent);  }### Answer:
@Test public void testDecodeInvalidResultMsg() throws Exception { ByteStringBuilder builder = new ByteStringBuilder(); ASN1Writer writer = ASN1.getWriter(builder); writer.writeStartSequence(OP_TYPE_COMPARE_RESPONSE); writer.writeInteger(resultCode); writer.writeOctetString(dn.toString()); writer.writeNull(); writer.writeEndSequence(); ASN1Reader reader = ASN1.getReader(builder.toByteString()); LDAPReader.readProtocolOp(reader); }
@Test public void testDecodeInvalidReferralURLs() throws Exception { ByteStringBuilder builder = new ByteStringBuilder(); ASN1Writer writer = ASN1.getWriter(builder); writer.writeStartSequence(OP_TYPE_COMPARE_RESPONSE); writer.writeInteger(resultCode); writer.writeOctetString(dn.toString()); writer.writeOctetString(resultMsg.toString()); writer.writeNull(); writer.writeEndSequence(); ASN1Reader reader = ASN1.getReader(builder.toByteString()); LDAPReader.readProtocolOp(reader); }
@Test public void TestToStringSingleLine() throws Exception { List<String> referralURLs = Arrays.asList( "ds1.example.com", "ds2.example.com", "ds3.example.com"); CompareResponseProtocolOp compareResponse = new CompareResponseProtocolOp( resultCode, resultMsg, dn, referralURLs); StringBuilder buffer = new StringBuilder(); compareResponse.toString(buffer); String key = "CompareResponse(resultCode=" + resultCode + ", errorMessage=" + resultMsg + ", matchedDN=" + dn + ", referralURLs={" + joinAsString(", ", referralURLs) + "})"; assertEquals(buffer.toString(), key); }
@Test public void TestToStringMultiLine() throws Exception { CompareResponseProtocolOp compareResponse; StringBuilder buffer = new StringBuilder(); StringBuilder key = new StringBuilder(); ArrayList<String> referralURLs = new ArrayList<>(); referralURLs.add("ds1.example.com"); referralURLs.add("ds2.example.com"); referralURLs.add("ds3.example.com"); int indent = 5; int i; compareResponse = new CompareResponseProtocolOp(resultCode, resultMsg, dn, referralURLs); compareResponse.toString(buffer, indent); StringBuilder indentBuf = new StringBuilder(indent); for (i=0 ; i < indent; i++) { indentBuf.append(' '); } key.append(indentBuf).append("Compare Response").append(EOL); key.append(indentBuf).append(" Result Code: ").append(resultCode).append(EOL); key.append(indentBuf).append(" Error LocalizableMessage: ").append(resultMsg).append(EOL); key.append(indentBuf).append(" Matched DN: ").append(dn).append(EOL); key.append(indentBuf).append(" Referral URLs: ").append(EOL); for (String url : referralURLs) { key.append(indentBuf).append(" ").append(url).append(EOL); } assertEquals(buffer.toString(), key.toString()); }