@Override public Object run() { GroovyRuntimeUtil.invokeClosure(closure); return null; }
@Override public void evaluate() { GroovyRuntimeUtil.invokeClosure(closure, subject); } }
@Override public boolean isSatisfiedBy(Object argument) { try { GroovyRuntimeUtil.invokeClosure(code, argument); return true; } catch (AssertionError ignore) { return false; } catch (Exception e) { // MFE can't be catched directly as it thrown by sneakyThrows and not declared as a checked exception if (e instanceof MultipleFailureException) { return false; } throw e; } }
/** * All assertions in this block are executed and the errors recorded and reported at the end. * * <p>Example: * * <pre> * expect: * verifyAll { * 1 == 2 * 2 == 3 * } * </pre> * * This will report two errors, instead of just the first. * * @param closure a code block containing top-level conditions and/or interactions */ @Beta public void verifyAll(Closure closure){ GroovyRuntimeUtil.invokeClosure(closure); }
@Override public String describeMismatch(Object argument) { try { GroovyRuntimeUtil.invokeClosure(code, argument); } catch (AssertionError ae) { return ae.getMessage(); } catch (Exception e) { if (e instanceof MultipleFailureException) { return e.getMessage(); } throw e; } return "<Code argument did not match>"; } }
GroovyRuntimeUtil.invokeClosure(block);
@Beta public Object createMock(@Nullable String name, Object instance, Type type, MockNature nature, MockImplementation implementation, Map<String, Object> options, @Nullable Closure closure) { Object mock = CompositeMockFactory.INSTANCE.create( new MockConfiguration(name, type, instance, nature, implementation, options), (Specification) this); if (closure != null) { GroovyRuntimeUtil.invokeClosure(closure, mock); } return mock; }
private Object invokeClosure(IMockInvocation invocation) { Class<?>[] paramTypes = code.getParameterTypes(); if (paramTypes.length == 1 && paramTypes[0] == IMockInvocation.class) { return GroovyRuntimeUtil.invokeClosure(code, invocation); } code.setDelegate(invocation); code.setResolveStrategy(Closure.DELEGATE_FIRST); return GroovyRuntimeUtil.invokeClosure(code, invocation.getArguments()); } }
attempts++; lastAttempt = System.currentTimeMillis(); GroovyRuntimeUtil.invokeClosure(conditions); return; } catch (Throwable e) {
/** * A combination of {@link #with(Object, Closure)} and {@link #verifyAll(Closure)}. * * @since 1.2 * @param target an implicit target for conditions and/or interactions * @param closure a code block containing top-level conditions and/or interactions * @param <U> type of target */ @Beta public <U> void verifyAll( @DelegatesTo.Target U target, @DelegatesTo(strategy = Closure.DELEGATE_FIRST) @ClosureParams(FirstParam.class) Closure<?> closure ){ if (target == null) { throw new SpockAssertionError("Target of 'verifyAll' block must not be null"); } closure.setDelegate(target); // for conditions closure.setResolveStrategy(Closure.DELEGATE_FIRST); GroovyRuntimeUtil.invokeClosure(closure, target); }
GroovyRuntimeUtil.invokeClosure(closure, target);