Skip to content

Instantly share code, notes, and snippets.

@thombergs
Created October 17, 2017 18:53
Show Gist options
  • Select an option

  • Save thombergs/f7e8ea54703776780077b5d913362fe3 to your computer and use it in GitHub Desktop.

Select an option

Save thombergs/f7e8ea54703776780077b5d913362fe3 to your computer and use it in GitHub Desktop.
public class AssumeConnectionCondition implements ExecutionCondition {
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<AssumeConnection> annotation = findAnnotation(context.getElement(), AssumeConnection.class);
if (annotation.isPresent()) {
String uri = annotation.get().uri();
ConnectionChecker checker = new ConnectionChecker(uri);
if (!checker.connect()) {
return ConditionEvaluationResult.disabled(String.format("Could not connect to '%s'. Skipping test!", uri));
} else {
return ConditionEvaluationResult.enabled(String.format("Successfully connected to '%s'. Continuing test!", uri));
}
}
return ConditionEvaluationResult.enabled("No AssumeConnection annotation found. Continuing test.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment