/** * Returns the current {@code Specification} instance. * * @return the current {@code Specification} instance */ public Object getInstance() { return invocation.getInstance(); }
@Override public void intercept(final IMethodInvocation invocation) throws Throwable { DefaultGroovyMethods.use(null, categories, new Closure<Void>(invocation.getInstance(), invocation.getInstance()) { public Void doCall(Object[] args) throws Throwable { invocation.proceed(); return null; } }); } }
@Override public void interceptInitializerMethod(IMethodInvocation invocation) throws Throwable { injectValues(invocation.getInstance(), false, (Specification)invocation.getInstance()); invocation.proceed(); }
@Override public void intercept(IMethodInvocation invocation) throws Throwable { Object value = field.readValue(invocation.getInstance()); value = getUltimateTargetObject(value); if (value != null) { field.writeValue(invocation.getInstance(), value); } invocation.proceed(); } }
@Override public void interceptInitializerMethod(IMethodInvocation invocation) throws Throwable { injectServices(invocation.getInstance(), false); invocation.proceed(); }
@Override public void interceptInitializerMethod(IMethodInvocation invocation) throws Throwable { invocation.proceed(); // needs to run before so that mocks are already initialized manager.prepareTestInstance(invocation.getInstance()); }
@Override public void intercept(final IMethodInvocation invocation) throws Throwable { Statement statement = createBaseStatement(invocation); FrameworkMethod method = createFrameworkMethod(invocation); for (FieldInfo field : ruleFields) { MethodRule rule = (MethodRule) getRuleInstance(field, invocation.getInstance()); statement = rule.apply(statement, method, invocation.getInstance()); } statement.evaluate(); }
@Override public void interceptSetupMethod(IMethodInvocation invocation) throws Throwable { listener.afterCreateTestObject(invocation.getInstance()); listener.beforeTestSetUp(invocation.getInstance(), currentFeature.getFeatureMethod().getReflection()); invocation.proceed(); }
@Override public void intercept(IMethodInvocation invocation) throws Throwable { Object mock = field.readValue(invocation.getInstance()); MOCK_UTIL.detachMock(mock); invocation.proceed(); } }
@Override public void interceptFeatureMethod(IMethodInvocation invocation) throws Throwable { Throwable throwable = null; listener.beforeTestMethod(invocation.getInstance(), invocation.getMethod().getReflection()); try { invocation.proceed(); } catch (Throwable t) { throwable = t; throw t; } finally { listener.afterTestMethod(invocation.getInstance(), invocation.getMethod().getReflection(), throwable); } }
@Override public void interceptCleanupMethod(IMethodInvocation invocation) throws Throwable { try { invocation.proceed(); } finally { listener.afterTestTearDown(invocation.getInstance(), currentFeature.getFeatureMethod().getReflection()); } }
@Override public void interceptSharedInitializerMethod(IMethodInvocation invocation) throws Throwable { createInjector(); injectValues(invocation.getSharedInstance(), true, (Specification)invocation.getInstance()); invocation.proceed(); }
@Override public void intercept(IMethodInvocation invocation) throws Throwable { Object mock = field.readValue(invocation.getInstance()); if (mock == null) { throw new SpockException(String.format("Cannot AutoAttach 'null' for field %s:%s", field.getName(), field.getLine())); } if (!MOCK_UTIL.isMock(mock)) { throw new SpockException(String.format("AutoAttach failed '%s' is not a mock for field %s:%s", mock, field.getName(), field.getLine())); } MOCK_UTIL.attachMock(mock, (Specification) invocation.getInstance()); invocation.proceed(); } }
@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); } }
@Override public void interceptSetupMethod(IMethodInvocation invocation) throws Throwable { exception = null; beforeTestMethodInvoked = true; manager.beforeTestMethod(invocation.getInstance(), invocation.getFeature().getFeatureMethod().getReflection()); invocation.proceed(); }
@Override public void intercept(final IMethodInvocation invocation) throws Throwable { Statement stat = createBaseStatement(invocation); for (FieldInfo field : ruleFields) { TestRule rule = (TestRule) getRuleInstance(field, invocation.getInstance()); stat = rule.apply(stat, invocation.getIteration().getDescription()); } stat.evaluate(); } }
@Override public void interceptCleanupMethod(IMethodInvocation invocation) throws Throwable { if (!beforeTestMethodInvoked) { invocation.proceed(); return; } beforeTestMethodInvoked = false; invocation.proceed(); Throwable afterTestMethodEx = null; try { manager.afterTestMethod(invocation.getInstance(), invocation.getFeature().getFeatureMethod().getReflection(), exception); } catch (Throwable t) { afterTestMethodEx = t; } if (afterTestMethodEx != null) { if (exception == null) { throw afterTestMethodEx; } else { exception.addSuppressed(afterTestMethodEx); } } }
@Override public void intercept(final IMethodInvocation invocation) throws Throwable { Statement stat = createBaseStatement(invocation); for (FieldInfo field : ruleFields) { TestRule rule = (TestRule) getRuleInstance(field, field.isShared() ? invocation.getSharedInstance() : invocation.getInstance()); stat = rule.apply(stat, invocation.getSpec().getDescription()); } stat.evaluate(); } }
@Override public void interceptInitializerMethod(IMethodInvocation invocation) throws Throwable { injectValues(invocation.getInstance(), false, (Specification)invocation.getInstance()); invocation.proceed(); }
@Override public void interceptInitializerMethod(IMethodInvocation invocation) throws Throwable { injectServices(invocation.getInstance(), false); invocation.proceed(); }