@Override
  public void addInteraction(final IMockInteraction interaction) {
    interactions.add(new MockInteractionDecorator(interaction) {
      final int myRegistrationZone = currentRegistrationZone;

      @Override
      public Supplier<Object> accept(IMockInvocation invocation) {
        WrongInvocationOrderError wrongInvocationOrderError;
        if (currentExecutionZone > myRegistrationZone) {
          wrongInvocationOrderError = new WrongInvocationOrderError(decorated, invocation, previousInvocationsInReverseOrder);
        } else {
          wrongInvocationOrderError = null;
        }
        currentExecutionZone = myRegistrationZone;
        if (previousInvocationsInReverseOrder.size() == MAX_PREVIOUS_INVOCATIONS) {
          previousInvocationsInReverseOrder.removeLast();
        }
        previousInvocationsInReverseOrder.addFirst(invocation);

        Supplier<Object> supplierFromDecorated = super.accept(invocation);
        return () -> {
          Object result = null;
          Throwable invocationException = null;
          try {
            result = supplierFromDecorated.get();
          } catch (AssertionError | Exception e) {
            invocationException = e;
          }
          ExceptionUtil.throwWithSuppressed(invocationException, wrongInvocationOrderError);
          return result;
        };
      }

      @Override
      public String describeMismatch(IMockInvocation invocation) {
        return interaction.describeMismatch(invocation);
      }
    });
  }
A scope for interactions defined outside a then-block

@author Peter Niederwieser
spock-core/src/main/java/org/spockframework/mock/runtime/InteractionScope.java