NewPluginPopUp implements NewPluginPopUpView.Presenter { @Override public void onOK(final String name, final PluginType type) { pluginNameValidator.validate(name + ".plugin", new ValidatorWithReasonCallback() { @Override public void onFailure(final String reason) { if (ValidationErrorReason.EMPTY_NAME.name().equals(reason)) { view.handleNameValidationError(view.emptyName()); } else if (ValidationErrorReason.DUPLICATED_NAME.name().equals(reason)) { view.handleNameValidationError(view.duplicatedName()); } else { view.handleNameValidationError(view.invalidName()); } } @Override public void onSuccess() { pluginServices.call(new RemoteCallback<Plugin>() { @Override public void callback(final Plugin response) { placeManager.goTo(getPathPlaceRequest(response)); hide(); } }, new ErrorCallback<Object>() { @Override public boolean error(final Object message, final Throwable throwable) { if (throwable instanceof PluginAlreadyExists) { view.handleNameValidationError(view.duplicatedName()); } else { view.handleNameValidationError(view.invalidName()); } return false; } }).createNewPlugin(name, type); } @Override public void onFailure() { view.handleNameValidationError(view.invalidName()); } }); } protected  NewPluginPopUp(); @Inject  NewPluginPopUp(final NewPluginPopUpView view); @Override RuleValidator getNameValidator(); @Override void onOK(final String name,
                     final PluginType type); @Override void onCancel(); void show(final PluginType type);  }
@Test public void testSuccessfulValidation() { presenter.pluginNameValidator = successValidator; presenter.onOK("newPlugin", PluginType.PERSPECTIVE); verify(successValidator).validate(eq("newPlugin.plugin"), any(ValidatorCallback.class)); verify(pluginServices).createNewPlugin("newPlugin", PluginType.PERSPECTIVE); }
@Test public void testFailedValidation() { presenter.pluginNameValidator = failureValidator; presenter.onOK("invalid*", PluginType.PERSPECTIVE); verify(failureValidator).validate(eq("invalid*.plugin"), any(ValidatorCallback.class)); verify(view).handleNameValidationError(anyString()); verify(view).invalidName(); verify(pluginServices, never()).createNewPlugin(anyString(), any(PluginType.class)); }