@Test
public void testRecordOperation() {

    final ModificationItem incomingItem = new ModificationItem(
            DirContext.ADD_ATTRIBUTE, new BasicAttribute("attribute1"));
    ModificationItem[] incomingMods = new ModificationItem[]{incomingItem};
    final ModificationItem compensatingItem = new ModificationItem(
            DirContext.ADD_ATTRIBUTE, new BasicAttribute("attribute2"));
    final Attributes expectedAttributes = new BasicAttributes();
    tested = new ModifyAttributesOperationRecorder(ldapOperationsMock) {
        IncrementalAttributesMapper getAttributesMapper(String[] attributeNames) {
            return attributesMapperMock;
        }
        protected ModificationItem getCompensatingModificationItem(
                Attributes originalAttributes,
                ModificationItem modificationItem) {
            assertThat(originalAttributes).isSameAs(expectedAttributes);
            assertThat(modificationItem).isSameAs(incomingItem);
            return compensatingItem;
        }
    };
    LdapName expectedName = LdapUtils.newLdapName("cn=john doe");
    when(attributesMapperMock.hasMore()).thenReturn(true, false);
    when(attributesMapperMock.getAttributesForLookup())
            .thenReturn(new String[]{"attribute1"});
    when(ldapOperationsMock.lookup(expectedName, new String[]{"attribute1"}, attributesMapperMock))
            .thenReturn(expectedAttributes);
    when(attributesMapperMock.getCollectedAttributes())
            .thenReturn(expectedAttributes);
    // Perform test
    CompensatingTransactionOperationExecutor operation = tested
            .recordOperation(new Object[]{expectedName, incomingMods});
    // Verify outcome
    assertThat(operation instanceof ModifyAttributesOperationExecutor).isTrue();
    ModifyAttributesOperationExecutor rollbackOperation = (ModifyAttributesOperationExecutor) operation;
    assertThat(rollbackOperation.getDn()).isSameAs(expectedName);
    assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
    ModificationItem[] actualModifications = rollbackOperation.getActualModifications();
    assertThat(actualModifications.length).isEqualTo(incomingMods.length);
    assertThat(actualModifications[0]).isEqualTo(incomingMods[0]);
    assertThat(rollbackOperation.getCompensatingModifications().length).isEqualTo(1);
    assertThat(rollbackOperation.getCompensatingModifications()[0]).isSameAs(compensatingItem);
}