### Question:
DefaultNewResourceHandler implements NewResourceHandler { @Override public void validate(final String baseFileName, final ValidatorWithReasonCallback callback) { final String fileName = buildFileName(baseFileName, getResourceType()); validationService.call(new RemoteCallback<Boolean>() { @Override public void callback(final Boolean response) { if (Boolean.TRUE.equals(response)) { callback.onSuccess(); } else { callback.onFailure(CommonConstants.INSTANCE.InvalidFileName0(baseFileName)); } } }).isFileNameValid(fileName); } DefaultNewResourceHandler(final WorkspaceProjectContext context,
                              final Caller<KieModuleService> moduleService,
                              final Caller<ValidationService> validationService,
                              final PlaceManager placeManager,
                              final Event<NotificationEvent> notificationEvent,
                              final BusyIndicatorView busyIndicatorView);  DefaultNewResourceHandler(); @Override List<Pair<String, ? extends IsWidget>> getExtensions(); @Override void validate(final String baseFileName,
                         final ValidatorWithReasonCallback callback); @Override void acceptContext(final Callback<Boolean, Void> callback); @Override Command getCommand(final NewResourcePresenter newResourcePresenter); @Override boolean canCreate();  }### Answer:
@Test public void testValidateValidFileName() { final org.guvnor.common.services.project.model.Package pkg = mock(Package.class); final ValidatorWithReasonCallback callback = mock(ValidatorWithReasonCallback.class); when(validationService.isFileNameValid("filename.suffix")).thenReturn(true); handler.validate("filename", callback); verify(callback, times(1)).onSuccess(); verify(callback, never()).onFailure(); verify(callback, never()).onFailure(any(String.class)); }
@Test public void testValidateInvalidFileName() { final org.guvnor.common.services.project.model.Package pkg = mock(Package.class); final ValidatorWithReasonCallback callback = mock(ValidatorWithReasonCallback.class); when(validationService.isFileNameValid("filename.suffix")).thenReturn(false); handler.validate("filename", callback); verify(callback, times(1)).onFailure(any(String.class)); verify(callback, never()).onFailure(); verify(callback, never()).onSuccess(); }