protected SpecificationContext getSpecificationContext() { return (SpecificationContext) currentInstance.getSpecificationContext(); } }
type, target.getClass().getName())); with(target, closure);
/** * A combination of {@link #with(Object, Class, Closure)} and {@link #verifyAll(Closure)}. * * @since 1.2 * @param target an implicit target for conditions and/or interactions * @param type the expected type of the target * @param closure a code block containing top-level conditions and/or interactions * @param <U> type of target */ @Beta public <U> void verifyAll( Object target, @DelegatesTo.Target Class<U> type, @DelegatesTo(genericTypeIndex = 0, strategy = Closure.DELEGATE_FIRST) @ClosureParams(SecondParam.FirstGenericType.class) Closure closure) { if (target != null && !type.isInstance(target)) { throw new SpockAssertionError(String.format("Expected target of 'verifyAll' block to have type '%s', but got '%s'", type, target.getClass().getName())); } verifyAll(target, closure); } }
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); } }
/** * 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); }
IMockInvocation invocation = new MockInvocation(mockObject, mockMethod, Arrays.asList(normalizedArgs), realMethodInvoker); IMockController mockController = specification == null ? getFallbackMockController() : specification.getSpecificationContext().getMockController();
IMockController controller = specification.getSpecificationContext().getMockController(); return controller.handle(invocation);
specification.getSpecificationContext().getCurrentIteration().addCleanup(new Runnable() { @Override public void run() {
IMockController controller = specification.getSpecificationContext().getMockController();