### Question:
DisableAccountFailureStrategy implements AuthenticationFailureStrategy, EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument updatedDocument = (XWikiDocument) source; BaseObject updatedUserObject = updatedDocument.getXObject(USER_CLASS_REFERENCE); XWikiDocument originalDocument = updatedDocument.getOriginalDocument(); BaseObject originalUserObject = originalDocument.getXObject(USER_CLASS_REFERENCE); if (originalUserObject != null && updatedUserObject != null && (propertyValueChanged(originalUserObject, updatedUserObject, XWikiUser.ACTIVE_PROPERTY, 1))) { this.authenticationFailureManager.get() .resetAuthenticationFailureCounter(updatedDocument.getDocumentReference()); } }  @Override String getErrorMessage(String username); @Override String getForm(String username); @Override boolean validateForm(String username, SecurityRequestWrapper request); @Override void notify(String username); @Override List<Event> getEvents(); @Override String getName(); @Override void onEvent(Event event, Object source, Object data); static final String NAME; }### Answer:
@Test public void resetAuthenticationFailureCounterWhenAccountIsActivated() { when(this.updatedDocument.getOriginalDocument().getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE) .getIntValue("active")).thenReturn(0); when(this.updatedDocument.getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE).getIntValue("active")) .thenReturn(1); disableStrategy.onEvent(new DocumentUpdatedEvent(), this.updatedDocument, null); verify(this.authenticationFailureManagerProvider.get()) .resetAuthenticationFailureCounter(this.updatedDocument.getDocumentReference()); }
@Test public void dontResetAuthenticationFailureCounterWhenAccountRemainsInactive() { when(this.updatedDocument.getOriginalDocument().getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE) .getIntValue("active")).thenReturn(0); when(this.updatedDocument.getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE).getIntValue("active")) .thenReturn(0); disableStrategy.onEvent(new DocumentUpdatedEvent(), this.updatedDocument, null); verify(this.authenticationFailureManagerProvider.get(), never()) .resetAuthenticationFailureCounter(this.updatedDocument.getDocumentReference()); }
@Test public void dontResetAuthenticationFailureCounterWhenAccountRemainsActive() { when(this.updatedDocument.getOriginalDocument().getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE) .getIntValue("active")).thenReturn(1); when(this.updatedDocument.getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE).getIntValue("active")) .thenReturn(1); disableStrategy.onEvent(new DocumentUpdatedEvent(), this.updatedDocument, null); verify(this.authenticationFailureManagerProvider.get(), never()) .resetAuthenticationFailureCounter(this.updatedDocument.getDocumentReference()); }
@Test public void dontResetAuthenticationFailureCounterWhenAccountIsDeactivated() { when(this.updatedDocument.getOriginalDocument().getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE) .getIntValue("active")).thenReturn(1); when(this.updatedDocument.getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE).getIntValue("active")) .thenReturn(0); disableStrategy.onEvent(new DocumentUpdatedEvent(), this.updatedDocument, null); verify(this.authenticationFailureManagerProvider.get(), never()) .resetAuthenticationFailureCounter(this.updatedDocument.getDocumentReference()); }
@Test public void onDocumentUpdatedNoUserAccount() { when(this.updatedDocument.getXObject(DisableAccountFailureStrategy.USER_CLASS_REFERENCE)).thenReturn(null); disableStrategy.onEvent(new DocumentUpdatedEvent(), updatedDocument, null); verify(this.authenticationFailureManagerProvider, never()).get(); }
@Test public void onDocumentUpdatedNoUserAccountStateChange() { disableStrategy.onEvent(new DocumentUpdatedEvent(), updatedDocument, null); verify(this.authenticationFailureManagerProvider, never()).get(); }