### Question:
AddRequestProtocolOp extends ProtocolOp { public void toLDIF(StringBuilder buffer, int wrapColumn) { String dnString; int colsRemaining; if (needsBase64Encoding(dn)) { dnString = Base64.encode(dn); buffer.append("dn:: "); colsRemaining = wrapColumn - 5; } else { dnString = dn.toString(); buffer.append("dn: "); colsRemaining = wrapColumn - 4; } int dnLength = dnString.length(); if (dnLength <= colsRemaining || colsRemaining <= 0) { buffer.append(dnString); buffer.append(EOL); } else { buffer.append(dnString, 0, colsRemaining); buffer.append(EOL); int startPos = colsRemaining; while (dnLength - startPos > wrapColumn - 1) { buffer.append(" "); buffer.append(dnString, startPos, startPos+wrapColumn-1); buffer.append(EOL); startPos += wrapColumn-1; } if (startPos < dnLength) { buffer.append(" "); buffer.append(dnString.substring(startPos)); buffer.append(EOL); } } for (RawAttribute a : attributes) { String name = a.getAttributeType(); int nameLength = name.length(); for (ByteString v : a.getValues()) { String valueString; if (needsBase64Encoding(v)) { valueString = Base64.encode(v); buffer.append(name); buffer.append(":: "); colsRemaining = wrapColumn - nameLength - 3; } else { valueString = v.toString(); buffer.append(name); buffer.append(": "); colsRemaining = wrapColumn - nameLength - 2; } int valueLength = valueString.length(); if (valueLength <= colsRemaining || colsRemaining <= 0) { buffer.append(valueString); buffer.append(EOL); } else { buffer.append(valueString, 0, colsRemaining); buffer.append(EOL); int startPos = colsRemaining; while (valueLength - startPos > wrapColumn - 1) { buffer.append(" "); buffer.append(valueString, startPos, startPos+wrapColumn-1); buffer.append(EOL); startPos += wrapColumn-1; } if (startPos < valueLength) { buffer.append(" "); buffer.append(valueString.substring(startPos)); buffer.append(EOL); } } } } buffer.append(EOL); } 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 testToLDIF() 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.toLDIF(buffer, 80); BufferedReader reader = new BufferedReader(new StringReader(buffer.toString())); String line = reader.readLine(); assertEquals(line, "dn: "+dn); for (int i = 0; i < numAttributes; i++) { for (int j = 0; j < numValues; j++) { line = reader.readLine(); assertEquals(line, "testAttribute"+i+": "+"testValue"+i+"."+j); } } }