@Test public void intercept_notPerformed() throws Exception { Replacement replacement = new Replacement(StringLiteral.of("foo"), StringLiteral.of("bar")); MediaType contentType = MediaType.PNG; Charset charset = StandardCharsets.UTF_8; byte[] body = "This is a foo document".getBytes(charset); byte[] expected = "This is a bar document".getBytes(charset); HttpRespondable actual = doIntercept(replacement, body, contentType); WritingActionResult<MediaType> writeResult = ReplacingInterceptor.writeByteArray(actual::writeBody, expected.length); assertArrayEquals("actual bytes", body, writeResult.byteArray); assertEquals("content type", contentType, writeResult.actionReturnValue); }
protected static <T> WritingActionResult<T> writeByteArray(WritingAction<T> action, int expectedOutputLength) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(expectedOutputLength); T returnValue = action.write(baos); baos.flush(); byte[] data = baos.toByteArray(); return new WritingActionResult<>(returnValue, data); }
ReplacingInterceptor implements ResponseInterceptor { protected static <T> WritingActionResult<T> writeByteArray(WritingAction<T> action, int expectedOutputLength) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(expectedOutputLength); T returnValue = action.write(baos); baos.flush(); byte[] data = baos.toByteArray(); return new WritingActionResult<>(returnValue, data); } }
ReplacingInterceptor implements ResponseInterceptor { protected static <T> WritingActionResult<T> writeByteArray(WritingAction<T> action, int expectedOutputLength) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(expectedOutputLength); T returnValue = action.write(baos); baos.flush(); byte[] data = baos.toByteArray(); return new WritingActionResult<>(returnValue, data); } ReplacingInterceptor(VhsReplayManagerConfig config, Replacement replacement); }
ReplacingInterceptor implements ResponseInterceptor { protected static <T> WritingActionResult<T> writeByteArray(WritingAction<T> action, int expectedOutputLength) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(expectedOutputLength); T returnValue = action.write(baos); baos.flush(); byte[] data = baos.toByteArray(); return new WritingActionResult<>(returnValue, data); } ReplacingInterceptor(VhsReplayManagerConfig config, Replacement replacement); @Override HttpRespondable intercept(ParsedRequest parsedRequest, HttpRespondable httpRespondable); }
ReplacingInterceptor implements ResponseInterceptor { protected static <T> WritingActionResult<T> writeByteArray(WritingAction<T> action, int expectedOutputLength) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(expectedOutputLength); T returnValue = action.write(baos); baos.flush(); byte[] data = baos.toByteArray(); return new WritingActionResult<>(returnValue, data); } ReplacingInterceptor(VhsReplayManagerConfig config, Replacement replacement); @Override HttpRespondable intercept(ParsedRequest parsedRequest, HttpRespondable httpRespondable);  }