/**
  * Test SetIncludeBranch method of LDIFChangeRecordWriter Throws a NullPointerException if the
  * includeBranch is null.
  *
  * @throws Exception If the test failed unexpectedly.
  */
 @Test(expectedExceptions = NullPointerException.class)
 public void testSetIncludeBranchDoesntAllowNull() throws Exception {
   final List<String> actual = new ArrayList<>();
   final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
   try {
     writer.setIncludeBranch(null);
   } finally {
     writer.close();
   }
 }
  /**
   * Test SetIncludeBranch method of LDIFChangeRecordWriter DN included is "dc=example,dc=com",
   * which is not the one from the record. Record must not be written.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test
  public void testSetIncludeBranchWithNoMatch() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    final DN dn = DN.valueOf("dc=example,dc=org");

    final AddRequest changeRequest = Requests.newAddRequest(getAddLDIFChangeRecord());
    writer.setIncludeBranch(dn);
    writer.writeChangeRecord(changeRequest);
    writer.close();

    // No result expected
    assertThat(actual.size()).isEqualTo(0);
  }
  /**
   * Test SetIncludeBranch method of LDIFChangeRecordWriter verifying right data are present.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test
  public void testSetIncludeBranchWithMatch() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    final DN dn = DN.valueOf("dc=example,dc=com");

    final AddRequest changeRequest = Requests.newAddRequest(getAddLDIFChangeRecord());
    writer.setIncludeBranch(dn);
    writer.writeChangeRecord(changeRequest);
    writer.close();

    // Must contains all the attributes
    assertThat(actual.get(0)).contains("dn: uid=scarter,ou=People,dc=example,dc=com");
    assertThat(actual.size()).isEqualTo(14);
  }