@Override public Response play(final Request request) { if (!mode.isReadable()) { throw new IllegalStateException("the tape is not readable"); } if (mode.isSequential()) { Integer nextIndex = orderedIndex.getAndIncrement(); RecordedInteraction nextInteraction = interactions.get(nextIndex).toImmutable(); if (nextInteraction == null) { throw new IllegalStateException(String.format("No recording found at position %s", nextIndex)); } if (!matchRule.isMatch(request, nextInteraction.request())) { throw new IllegalStateException(String.format("Request %s does not match recorded " + "request" + " %s", stringify(request), stringify(nextInteraction.request()))); } return nextInteraction.response(); } else { int position = findMatch(request); if (position < 0) { throw new IllegalStateException("no matching recording found"); } else { return interactions.get(position).toImmutable().response(); } } }
@Override public Response play(final Request request) { if (!mode.isReadable()) { throw new IllegalStateException("the tape is not readable"); } if (mode.isSequential()) { Integer nextIndex = orderedIndex.getAndIncrement(); RecordedInteraction nextInteraction = interactions.get(nextIndex).toImmutable(); if (nextInteraction == null) { throw new IllegalStateException(String.format("No recording found at position %s", nextIndex)); } if (!matchRule.isMatch(request, nextInteraction.request())) { throw new IllegalStateException(String.format("Request %s does not match recorded " + "request" + " %s", stringify(request), stringify(nextInteraction.request()))); } return nextInteraction.response(); } else { int position = findMatch(request); if (position < 0) { throw new IllegalStateException("no matching recording found"); } else { return interactions.get(position).toImmutable().response(); } } }