/**
   * Write a modify request using an exclusion filter attribute.
   *
   * @throws Exception
   */
  @Test
  public void testWriteModifyRequestFilterAttributesExcluded() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    // @formatter:off
    final ModifyRequest changeRequest =
        (ModifyRequest)
            Requests.newChangeRecord(
                "version: 1",
                "",
                "dn: cn=scarter,dc=example,dc=com",
                "changetype: modify",
                "replace: work-phone",
                "work-phone: 555-555-1155");
    // @formatter:on

    writer.setExcludeAttribute(AttributeDescription.valueOf("work-phone"));
    writer.writeChangeRecord(changeRequest);
    writer.close();

    assertThat(actual.size()).isEqualTo(3);
    assertThat(actual.get(0)).isEqualTo("dn: cn=scarter,dc=example,dc=com");
    assertThat(actual.get(1)).isEqualTo("changetype: modify");
    assertThat(actual.get(2)).isEqualTo("");
  }
  /**
   * Test setExcludeAttribute method of LDIFChangeRecordWriter Throws a NullPointerException if the
   * attributeDescription is null.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test(expectedExceptions = NullPointerException.class)
  public void testSetExcludeAttributeDoesntAllowNull() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    try {
      writer.setExcludeAttribute(null);
    } finally {
      writer.close();
    }
  }
  /**
   * Test to write an LDIFChangeRecordWriter with attribute exclusions. In this case, vip attribute
   * is not present in the example. All lines must be written.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test
  public void testSetExcludeAttributeWithNoMatch() throws Exception {
    final AttributeDescription attribute = AttributeDescription.valueOf("vip");
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    final AddRequest changeRequest = Requests.newAddRequest(getAddLDIFChangeRecord());
    writer.setExcludeAttribute(attribute);
    writer.writeChangeRecord(changeRequest);
    writer.close();

    assertThat(actual.get(0)).isEqualTo("dn: uid=scarter,ou=People,dc=example,dc=com");
    assertThat(actual.size()).isEqualTo(14);
    for (String line : actual) {
      // we have excluded this attribute especially.
      assertThat(line).doesNotContain("vip");
    }
  }