### Question:
NewFormDefinitionlHandler extends DefaultNewResourceHandler { @Override public void validate(String baseFileName, ValidatorWithReasonCallback callback) { boolean isValid = formModelsPresenter.isValid(); if (!isValid) { callback.onFailure(); } else { super.validate(baseFileName, callback); } } @Inject  NewFormDefinitionlHandler(final Caller<FormEditorService> modelerService,
                                     final FormDefinitionResourceType resourceType,
                                     final TranslationService translationService,
                                     final FormModelsPresenter formModelsPresenter,
                                     final WorkspaceProjectContext context,
                                     final Caller<KieModuleService> moduleService,
                                     final Caller<ValidationService> validationService,
                                     final PlaceManager placeManager,
                                     final Event<NotificationEvent> notificationEvent,
                                     final Event<NewResourceSuccessEvent> newResourceSuccessEvent,
                                     final BusyIndicatorView busyIndicatorView); @Override String getDescription(); @Override IsWidget getIcon(); @Override ResourceTypeDefinition getResourceType(); @Override List<Pair<String, ? extends IsWidget>> getExtensions(); @Override void validate(String baseFileName,
                         ValidatorWithReasonCallback callback); @Override void create(final org.guvnor.common.services.project.model.Package pkg,
                       final String baseFileName,
                       final NewResourcePresenter presenter); @Override List<Profile> getProfiles();  }### Answer:
@Test public void testAssetNameValidationWithFormModelPresenterFailure() { when(formModelsPresenter.isValid()).thenReturn(false); handler.validate(NEW_FORM_NAME, validatorCallback); verify(formModelsPresenter, times(1)).isValid(); verify(validatorCallback, times(1)).onFailure(); }
@Test public void testAssetNameValidationWithValidationServiceFailure() { when(formModelsPresenter.isValid()).thenReturn(true); when(validationService.isFileNameValid(anyString())).thenReturn(false); handler.validate(NEW_FORM_NAME, validatorCallback); verify(formModelsPresenter, times(1)).isValid(); verify(validatorCallback, times(1)).onFailure(anyString()); }
@Test public void testAssetNameValidationSuccessful() { when(formModelsPresenter.isValid()).thenReturn(true); when(validationService.isFileNameValid(anyString())).thenReturn(true); handler.validate(NEW_FORM_NAME, validatorCallback); verify(formModelsPresenter, times(1)).isValid(); verify(validatorCallback, times(1)).onSuccess(); }