protected SpecificationContext getSpecificationContext() { return (SpecificationContext) currentInstance.getSpecificationContext(); } }
private boolean hasExpectedClass(Throwable failure) { for (Class<? extends Throwable> exception : retry.exceptions()) { if (exception.isInstance(failure)) { return true; } } return false; }
@Override public void visitFeatureAnnotation(PendingFeature annotation, FeatureInfo feature) { if (feature.isParameterized()) { feature.addInterceptor(new PendingFeatureIterationInterceptor(annotation.exceptions(), annotation.reason())); } else { feature.getFeatureMethod().addInterceptor( new PendingFeatureInterceptor(annotation.exceptions(), annotation.reason())); } } }
protected void handleInvocation(IMethodInvocation invocation) throws Throwable { List<Throwable> throwables = new ArrayList<>(retry.count() + 1); for (int i = 0; i <= retry.count(); i++) { try { invocation.proceed(); return; } catch (Throwable e) { if (isExpected(invocation, e)) { throwables.add(e); if (retry.delay() > 0) { Thread.sleep(retry.delay()); } continue; } else { throw e; } } } throw new MultipleFailureException(throwables); } }
@Override public void intercept(IMethodInvocation invocation) throws Throwable { List<Throwable> exceptions = new ArrayList<>(); try { invocation.proceed(); } catch (Throwable t) { exceptions.add(t); } for (FieldInfo field : fields) { AutoCleanup annotation = field.getAnnotation(AutoCleanup.class); try { Object value = field.readValue(invocation.getInstance()); if (value == null) continue; GroovyRuntimeUtil.invokeMethod(value, annotation.value()); } catch (Throwable t) { if (!annotation.quiet()) exceptions.add(t); } } ExtensionUtil.throwAll(exceptions); } }
public RetryBaseInterceptor(Retry retry) { this(retry, createCondition(retry.condition())); }
@Override public void visitSpecAnnotation(Title title, SpecInfo spec) { spec.setName(title.value().trim()); } }
@Override public void visitSpecAnnotation(Narrative narrative, SpecInfo spec) { spec.setNarrative(narrative.value().trim()); } }
private void addAttachments(See see, SpecElementInfo specElement) { for (String url : see.value()) { specElement.addAttachment(new Attachment(url, url)); } } }
private NameProvider<IterationInfo> chooseNameProvider(Unroll unroll, FeatureInfo feature) { if (unroll.value().length() > 0) { return new UnrollNameProvider(feature, unroll.value()); } if (feature.getName().contains("#")) { return new UnrollNameProvider(feature, feature.getName()); } return null; } }
private void addTags(Issue issue, SpecElementInfo specElement) { for (String value : issue.value()) { if (value.startsWith("http")) { int index = value.lastIndexOf('/'); String name = value.substring(index + 1); specElement.addTag(new Tag(configuration.issueNamePrefix + name, "issue", name, value)); } else { specElement.addTag(new Tag(configuration.issueNamePrefix + value, "issue", value, configuration.issueUrlPrefix + value)); } } } }
private void doVisit(IgnoreIf annotation, ISkippable skippable) { Closure condition = createCondition(annotation.value()); Object result = evaluateCondition(condition); if (GroovyRuntimeUtil.isTruthy(result)) { skippable.setSkipped(true); } }
private void doVisit(Requires annotation, ISkippable skippable) { Closure condition = createCondition(annotation.value()); Object result = evaluateCondition(condition); if (!GroovyRuntimeUtil.isTruthy(result)) { skippable.setSkipped(true); } }
private Object createDummy(IMockInvocation invocation) { Class<?> type = invocation.getMethod().getReturnType(); Type genericType = invocation.getMethod().getExactReturnType(); Specification spec = invocation.getMockObject().getSpecification(); return spec.createMock("dummy", genericType, MockNature.STUB, GroovyObject.class.isAssignableFrom(type) ? MockImplementation.GROOVY : MockImplementation.JAVA, Collections.<String, Object>emptyMap(), null); } }
@Override public void visitFeatureAnnotation(Retry annotation, FeatureInfo feature) { if (feature.isParameterized() && (annotation.mode() == Retry.Mode.FEATURE)) { feature.addInterceptor(new RetryIterationInterceptor(annotation)); } else if (annotation.mode() == Retry.Mode.SETUP_FEATURE_CLEANUP) { feature.addIterationInterceptor(new RetryIterationInterceptor(annotation)); } else { feature.getFeatureMethod().addInterceptor(new RetryFeatureInterceptor(annotation)); } } }
/** * Specifies that no exception should be thrown, failing with a * {@link UnallowedExceptionThrownError} otherwise. */ public void noExceptionThrown() { Throwable thrown = getSpecificationContext().getThrownException(); if (thrown == null) return; throw new UnallowedExceptionThrownError(null, thrown); }
/** * Specifies that no exception of the given type should be * thrown, failing with a {@link UnallowedExceptionThrownError} otherwise. * * @param type the exception type that should not be thrown */ public void notThrown(Class<? extends Throwable> type) { Throwable thrown = getSpecificationContext().getThrownException(); if (thrown == null) return; if (type.isAssignableFrom(thrown.getClass())) { throw new UnallowedExceptionThrownError(type, thrown); } ExceptionUtil.sneakyThrow(thrown); }