@Test public void preventValidationSpam() { final ValidationAction validationAction = new ValidationAction(editorSessionCommands, () -> { }, () -> { }, s -> { }); validationAction.validate(); validationAction.validate(); validationAction.validate(); verify(validateSessionCommand).execute(violationsArgumentCapture.capture()); violationsArgumentCapture.getValue().onSuccess(); validationAction.validate(); validationAction.validate(); validationAction.validate(); verify(validateSessionCommand, times(2)).execute(violationsArgumentCapture.capture()); violationsArgumentCapture.getValue().onError(new HashSet<>()); validationAction.validate(); validationAction.validate(); validationAction.validate(); verify(validateSessionCommand, times(3)).execute(violationsArgumentCapture.capture()); }
public void validate() { if (!isValidationRunning && onBeforeValidate()) { isValidationRunning = true; loadingStarts.execute(); sessionCommands.getValidateSessionCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() { @Override public void onSuccess() { loadingCompleted.execute(); onAfterValidation(); } @Override public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) { loadingCompleted.execute(); onError.accept(violations.toString()); onAfterValidation(); } }); } }
ValidationAction { public void validate() { if (!isValidationRunning && onBeforeValidate()) { isValidationRunning = true; loadingStarts.execute(); sessionCommands.getValidateSessionCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() { @Override public void onSuccess() { loadingCompleted.execute(); onAfterValidation(); } @Override public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) { loadingCompleted.execute(); onError.accept(violations.toString()); onAfterValidation(); } }); } } }
ValidationAction { public void validate() { if (!isValidationRunning && onBeforeValidate()) { isValidationRunning = true; loadingStarts.execute(); sessionCommands.getValidateSessionCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() { @Override public void onSuccess() { loadingCompleted.execute(); onAfterValidation(); } @Override public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) { loadingCompleted.execute(); onError.accept(violations.toString()); onAfterValidation(); } }); } } ValidationAction(final EditorSessionCommands sessionCommands,
                            final Command loadingStarts,
                            final Command loadingCompleted,
                            final Consumer<String> onError); }
ValidationAction { public void validate() { if (!isValidationRunning && onBeforeValidate()) { isValidationRunning = true; loadingStarts.execute(); sessionCommands.getValidateSessionCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() { @Override public void onSuccess() { loadingCompleted.execute(); onAfterValidation(); } @Override public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) { loadingCompleted.execute(); onError.accept(violations.toString()); onAfterValidation(); } }); } } ValidationAction(final EditorSessionCommands sessionCommands,
                            final Command loadingStarts,
                            final Command loadingCompleted,
                            final Consumer<String> onError); void validate(); void setBeforeValidation(final BooleanSupplier onBeforeValidation); void setAfterValidation(final Command onAfterValidation); }
ValidationAction { public void validate() { if (!isValidationRunning && onBeforeValidate()) { isValidationRunning = true; loadingStarts.execute(); sessionCommands.getValidateSessionCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() { @Override public void onSuccess() { loadingCompleted.execute(); onAfterValidation(); } @Override public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) { loadingCompleted.execute(); onError.accept(violations.toString()); onAfterValidation(); } }); } } ValidationAction(final EditorSessionCommands sessionCommands,
                            final Command loadingStarts,
                            final Command loadingCompleted,
                            final Consumer<String> onError); void validate(); void setBeforeValidation(final BooleanSupplier onBeforeValidation); void setAfterValidation(final Command onAfterValidation);  }