### Question:
NewPackageHandler extends DefaultNewResourceHandler { @Override public void validate(final String packageName, final ValidatorWithReasonCallback callback) { validationService.call(new RemoteCallback<Boolean>() { @Override public void callback(final Boolean response) { if (Boolean.TRUE.equals(response)) { callback.onSuccess(); } else { callback.onFailure(ProjectEditorResources.CONSTANTS.InvalidPackageName(packageName)); } } }).isPackageNameValid(packageName); } NewPackageHandler(); @Inject  NewPackageHandler(Caller<KieModuleService> moduleService,
                             Caller<ValidationService> validationService,
                             AnyResourceTypeDefinition resourceType); @Override String getDescription(); @Override IsWidget getIcon(); @Override ResourceTypeDefinition getResourceType(); @Override void validate(final String packageName,
                         final ValidatorWithReasonCallback callback); @Override void create(final Package pkg,
                       final String baseFileName,
                       final NewResourcePresenter presenter);  }### Answer:
@Test public void validate_noPackageSelected() { mockpkg = null; handler.validate("mockpkg", callback); verify(callback, never()).onFailure(); verify(callback ).onFailure(anyString()); verify(callback, never()).onSuccess(); }
@Test public void validate_invalidPackageName() { mockpkg = mock(org.guvnor.common.services.project.model.Package.class); when(validationService.isPackageNameValid(anyString())).thenReturn(false); handler.validate("mockpkg", callback); verify(callback, never()).onFailure(); verify(callback).onFailure(anyString()); verify(callback, never()).onSuccess(); }
@Test public void validate_validPackageName() { mockpkg = mock(org.guvnor.common.services.project.model.Package.class); when(validationService.isPackageNameValid(anyString())).thenReturn(true); handler.validate("mockpkg", callback); verify(callback, never()).onFailure(); verify(callback, never()).onFailure(anyString()); verify(callback).onSuccess(); }