    public void clear(HttpRequest request) {
        HttpRequest requestMatcher = null;
        if (isNotBlank(request.getBodyAsString())) {
            requestMatcher = httpRequestSerializer.deserialize(request.getBodyAsString());
        }
        try {
            ClearType retrieveType = ClearType.valueOf(StringUtils.defaultIfEmpty(request.getFirstQueryStringParameter("type").toUpperCase(), "ALL"));
            switch (retrieveType) {
                case LOG:
                    mockServerLog.clear(requestMatcher);
                    mockServerLogger.logEvent(
                        new LogEntry()
                            .setType(CLEARED)
                            .setLogLevel(Level.INFO)
                            .setHttpRequest(requestMatcher)
                            .setMessageFormat("clearing logs that match:{}")
                            .setArguments((requestMatcher == null ? "{}" : requestMatcher))
                    );
                    break;
                case EXPECTATIONS:
                    mockServerMatcher.clear(requestMatcher);
                    mockServerLogger.logEvent(
                        new LogEntry()
                            .setType(CLEARED)
                            .setLogLevel(Level.INFO)
                            .setHttpRequest(requestMatcher)
                            .setMessageFormat("clearing expectations that match:{}")
                            .setArguments((requestMatcher == null ? "{}" : requestMatcher))
                    );
                    break;
                case ALL:
                    mockServerLog.clear(requestMatcher);
                    mockServerMatcher.clear(requestMatcher);
                    mockServerLogger.logEvent(
                        new LogEntry()
                            .setType(CLEARED)
                            .setLogLevel(Level.INFO)
                            .setHttpRequest(requestMatcher)
                            .setMessageFormat("clearing expectations and logs that match:{}")
                            .setArguments((requestMatcher == null ? "{}" : requestMatcher))
                    );
                    break;
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException("\"" + request.getFirstQueryStringParameter("type") + "\" is not a valid value for \"type\" parameter, only the following values are supported " + Arrays.stream(ClearType.values()).map(input -> input.name().toLowerCase()).collect(Collectors.toList()));
        }
    }

    public void clear(HttpRequest request) {
        HttpRequest requestMatcher = null;
        if (isNotBlank(request.getBodyAsString())) {
            requestMatcher = httpRequestSerializer.deserialize(request.getBodyAsString());
        }
        try {
            ClearType retrieveType = ClearType.valueOf(StringUtils.defaultIfEmpty(request.getFirstQueryStringParameter("type").toUpperCase(), "ALL"));
            switch (retrieveType) {
                case LOG:
                    mockServerLog.clear(requestMatcher);
                    mockServerLogger.logEvent(
                        new LogEntry()
                            .setType(CLEARED)
                            .setLogLevel(Level.INFO)
                            .setHttpRequest(requestMatcher)
                            .setMessageFormat("clearing logs that match:{}")
                            .setArguments((requestMatcher == null ? "{}" : requestMatcher))
                    );
                    break;
                case EXPECTATIONS:
                    mockServerMatcher.clear(requestMatcher);
                    mockServerLogger.logEvent(
                        new LogEntry()
                            .setType(CLEARED)
                            .setLogLevel(Level.INFO)
                            .setHttpRequest(requestMatcher)
                            .setMessageFormat("clearing expectations that match:{}")
                            .setArguments((requestMatcher == null ? "{}" : requestMatcher))
                    );
                    break;
                case ALL:
                    mockServerLog.clear(requestMatcher);
                    mockServerMatcher.clear(requestMatcher);
                    mockServerLogger.logEvent(
                        new LogEntry()
                            .setType(CLEARED)
                            .setLogLevel(Level.INFO)
                            .setHttpRequest(requestMatcher)
                            .setMessageFormat("clearing expectations and logs that match:{}")
                            .setArguments((requestMatcher == null ? "{}" : requestMatcher))
                    );
                    break;
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException("\"" + request.getFirstQueryStringParameter("type") + "\" is not a valid value for \"type\" parameter, only the following values are supported " + Lists.transform(Arrays.asList(ClearType.values()), new Function<ClearType, String>() {
                public String apply(ClearType input) {
                    return input.name().toLowerCase();
                }
            }));
        }
    }

Replace Anonymous With Lambda org.mockserver.mock.HttpStateHandler.clear.new IllegalArgumentException.transform.new Function<ClearType,String> with input -> input.name().toLowerCase() in method public clear(request HttpRequest) : void from class org.mockserver.mock.HttpStateHandler


    private List<Integer> bindPorts(final ServerBootstrap serverBootstrap, List<Integer> requestedPortBindings, List<Future<Channel>> channelFutures) {
        List<Integer> actualPortBindings = new ArrayList<>();
        final String localBoundIP = ConfigurationProperties.localBoundIP();
        for (final Integer portToBind : requestedPortBindings) {
            try {
                final CompletableFuture<Channel> channelOpened = new CompletableFuture<>();
                channelFutures.add(channelOpened);
                new Thread(() -> {
                    try {
                        InetSocketAddress inetSocketAddress;
                        if (isBlank(localBoundIP)) {
                            inetSocketAddress = new InetSocketAddress(portToBind);
                        } else {
                            inetSocketAddress = new InetSocketAddress(localBoundIP, portToBind);
                        }
                        serverBootstrap
                            .bind(inetSocketAddress)
                            .addListener((ChannelFutureListener) future -> {
                                if (future.isSuccess()) {
                                    channelOpened.complete(future.channel());
                                } else {
                                    channelOpened.completeExceptionally(future.cause());
                                }
                            })
                            .channel().closeFuture().syncUninterruptibly();

                    } catch (Exception e) {
                        channelOpened.completeExceptionally(new RuntimeException("Exception while binding MockServer to port " + portToBind, e));
                    }
                }, "MockServer thread for port: " + portToBind).start();

                actualPortBindings.add(((InetSocketAddress) channelOpened.get().localAddress()).getPort());
            } catch (Exception e) {
                throw new RuntimeException("Exception while binding MockServer to port " + portToBind, e.getCause());
            }
        }
        return actualPortBindings;
    }

    private List<Integer> bindPorts(final ServerBootstrap serverBootstrap, List<Integer> requestedPortBindings, List<Future<Channel>> channelFutures) {
        List<Integer> actualPortBindings = new ArrayList<>();
        final String localBoundIP = ConfigurationProperties.localBoundIP();
        for (final Integer portToBind : requestedPortBindings) {
            try {
                final SettableFuture<Channel> channelOpened = SettableFuture.create();
                channelFutures.add(channelOpened);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            InetSocketAddress inetSocketAddress;
                            if (isBlank(localBoundIP)) {
                                inetSocketAddress = new InetSocketAddress(portToBind);
                            } else {
                                inetSocketAddress = new InetSocketAddress(localBoundIP, portToBind);
                            }
                            serverBootstrap
                                .bind(inetSocketAddress)
                                .addListener(new ChannelFutureListener() {
                                    @Override
                                    public void operationComplete(ChannelFuture future) {
                                        if (future.isSuccess()) {
                                            channelOpened.set(future.channel());
                                        } else {
                                            channelOpened.setException(future.cause());
                                        }
                                    }
                                })
                                .channel().closeFuture().syncUninterruptibly();

                        } catch (Exception e) {
                            channelOpened.setException(new RuntimeException("Exception while binding MockServer to port " + portToBind, e));
                        }
                    }
                }, "MockServer thread for port: " + portToBind).start();

                actualPortBindings.add(((InetSocketAddress) channelOpened.get().localAddress()).getPort());
            } catch (Exception e) {
                throw new RuntimeException("Exception while binding MockServer to port " + portToBind, e.getCause());
            }
        }
        return actualPortBindings;
    }

Replace Anonymous With Lambda org.mockserver.lifecycle.LifeCycle.bindPorts.start.new Thread.new Runnable with () -> {tryInetSocketAddress inetSocketAddress; in method private bindPorts(serverBootstrap ServerBootstrap, requestedPortBindings List<Integer>, channelFutures List<Future<Channel>>) : List<Integer> from class org.mockserver.lifecycle.LifeCycle


    public SettableFuture<HttpResponse> sendRequest(final HttpRequest httpRequest, @Nullable InetSocketAddress remoteAddress, Integer connectionTimeoutMillis) throws SocketConnectionException {
        if (!eventLoopGroup.isShuttingDown()) {
            if (proxyConfiguration != null && proxyConfiguration.getType() == ProxyConfiguration.Type.HTTP) {
                remoteAddress = proxyConfiguration.getProxyAddress();
            } else if (remoteAddress == null) {
                remoteAddress = httpRequest.socketAddressFromHostHeader();
            }

            final SettableFuture<HttpResponse> httpResponseSettableFuture = SettableFuture.create();
            new Bootstrap()
                .group(eventLoopGroup)
                .channel(NioSocketChannel.class)
                .option(ChannelOption.AUTO_READ, true)
                .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024))
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutMillis)
                .attr(SECURE, httpRequest.isSecure() != null && httpRequest.isSecure())
                .attr(REMOTE_SOCKET, remoteAddress)
                .attr(RESPONSE_FUTURE, httpResponseSettableFuture)
                .handler(new HttpClientInitializer(proxyConfiguration, mockServerLogger))
                .connect(remoteAddress)
                .addListener((ChannelFutureListener) future -> {
                    if (future.isSuccess()) {
                        // send the HTTP request
                        future.channel().writeAndFlush(httpRequest);
                    } else {
                        httpResponseSettableFuture.setException(future.cause());
                    }
                });

            return httpResponseSettableFuture;
        } else {
            throw new IllegalStateException("Request sent after client has been stopped - the event loop has been shutdown so it is not possible to send a request");
        }
    }

    public SettableFuture<HttpResponse> sendRequest(final HttpRequest httpRequest, @Nullable InetSocketAddress remoteAddress, Integer connectionTimeoutMillis) throws SocketConnectionException {
        if (!eventLoopGroup.isShuttingDown()) {
            if (proxyConfiguration != null && proxyConfiguration.getType() == ProxyConfiguration.Type.HTTP) {
                remoteAddress = proxyConfiguration.getProxyAddress();
            } else if (remoteAddress == null) {
                remoteAddress = httpRequest.socketAddressFromHostHeader();
            }

            final SettableFuture<HttpResponse> httpResponseSettableFuture = SettableFuture.create();
            new Bootstrap()
                .group(eventLoopGroup)
                .channel(NioSocketChannel.class)
                .option(ChannelOption.AUTO_READ, true)
                .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024))
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutMillis)
                .attr(SECURE, httpRequest.isSecure() != null && httpRequest.isSecure())
                .attr(REMOTE_SOCKET, remoteAddress)
                .attr(RESPONSE_FUTURE, httpResponseSettableFuture)
                .handler(new HttpClientInitializer(proxyConfiguration, mockServerLogger))
                .connect(remoteAddress)
                .addListener(new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) {
                        if (future.isSuccess()) {
                            // send the HTTP request
                            future.channel().writeAndFlush(httpRequest);
                        } else {
                            httpResponseSettableFuture.setException(future.cause());
                        }
                    }
                });

            return httpResponseSettableFuture;
        } else {
            throw new IllegalStateException("Request sent after client has been stopped - the event loop has been shutdown so it is not possible to send a request");
        }
    }

Replace Anonymous With Lambda org.mockserver.client.NettyHttpClient.sendRequest.addListener.new ChannelFutureListener with future -> {if(future.isSuccess()){future.channel().writeAndFlush(httpRequest); in method public sendRequest(httpRequest HttpRequest, remoteAddress InetSocketAddress, connectionTimeoutMillis Integer) : SettableFuture<HttpResponse> from class org.mockserver.client.NettyHttpClient


    private Future<String> register(final EventLoopGroup eventLoopGroup, final InetSocketAddress serverAddress, final String contextPath, final boolean isSecure) {
        SettableFuture<String> registrationFuture = SettableFuture.create();
        if (availableWebSocketCallbackRegistrations.tryAcquire()) {
            try {
                new Bootstrap()
                    .group(eventLoopGroup)
                    .channel(NioSocketChannel.class)
                    .attr(REGISTRATION_FUTURE, registrationFuture)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws URISyntaxException {
                            if (isSecure) {
                                try {
                                    ch.pipeline().addLast(
                                        SslContextBuilder
                                            .forClient()
                                            .sslProvider(SslProvider.JDK)
                                            .trustManager(InsecureTrustManagerFactory.INSTANCE)
                                            .build()
                                            .newHandler(ch.alloc(), serverAddress.getHostName(), serverAddress.getPort())
                                    );
                                } catch (SSLException e) {
                                    throw new WebSocketException("Exception when configuring SSL Handler", e);
                                }
                            }

                            ch.pipeline()
                                .addLast(
                                    new HttpClientCodec(),
                                    new HttpObjectAggregator(Integer.MAX_VALUE),
                                    new WebSocketClientHandler(mockServerLogger, serverAddress, contextPath, WebSocketClient.this)
                                );
                        }
                    })
                    .connect(serverAddress)
                    .addListener((ChannelFutureListener) connectChannelFuture -> {
                        channel = connectChannelFuture.channel();
                        channel.closeFuture().addListener((ChannelFutureListener) closeChannelFuture -> {
                            if (!isStopped) {
                                // attempt to re-connect
                                register(eventLoopGroup, serverAddress, contextPath, isSecure);
                            }
                        });
                    });
            } catch (Exception e) {
                registrationFuture.setException(new WebSocketException("Exception while starting web socket client", e));
            } finally {
                availableWebSocketCallbackRegistrations.release();
            }
        } else {
            registrationFuture.setException(new WebSocketException("It is not possible to re-use the same MockServerClient instance to register a new object callback while responding to an object callback, please use a separate instance of the MockServerClient inside a callback"));
        }
        return registrationFuture;
    }

    private Future<String> register(final EventLoopGroup eventLoopGroup, final InetSocketAddress serverAddress, final String contextPath, final boolean isSecure) {
        SettableFuture<String> registrationFuture = SettableFuture.create();
        if (availableWebSocketCallbackRegistrations.tryAcquire()) {
            try {
                new Bootstrap()
                    .group(eventLoopGroup)
                    .channel(NioSocketChannel.class)
                    .attr(REGISTRATION_FUTURE, registrationFuture)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws URISyntaxException {
                            if (isSecure) {
                                try {
                                    ch.pipeline().addLast(
                                        SslContextBuilder
                                            .forClient()
                                            .sslProvider(SslProvider.JDK)
                                            .trustManager(InsecureTrustManagerFactory.INSTANCE)
                                            .build()
                                            .newHandler(ch.alloc(), serverAddress.getHostName(), serverAddress.getPort())
                                    );
                                } catch (SSLException e) {
                                    throw new WebSocketException("Exception when configuring SSL Handler", e);
                                }
                            }

                            ch.pipeline()
                                .addLast(
                                    new HttpClientCodec(),
                                    new HttpObjectAggregator(Integer.MAX_VALUE),
                                    new WebSocketClientHandler(mockServerLogger, serverAddress, contextPath, WebSocketClient.this)
                                );
                        }
                    })
                    .connect(serverAddress)
                    .addListener(new ChannelFutureListener() {
                        @Override
                        public void operationComplete(ChannelFuture channelFuture) {
                            channel = channelFuture.channel();
                            channel.closeFuture().addListener(new ChannelFutureListener() {
                                @Override
                                public void operationComplete(ChannelFuture channelFuture) {

                                }
                            });
                        }
                    });
            } catch (Exception e) {
                registrationFuture.setException(new WebSocketException("Exception while starting web socket client", e));
            } finally {
                availableWebSocketCallbackRegistrations.release();
            }
        } else {
            registrationFuture.setException(new WebSocketException("It is not possible to re-use the same MockServerClient instance to register a new object callback while responding to an object callback, please use a separate instance of the MockServerClient inside a callback"));
        }
        return registrationFuture;
    }

Replace Anonymous With Lambda org.mockserver.websocket.WebSocketClient.register.addListener.new ChannelFutureListener with connectChannelFuture -> {channel=connectChannelFuture.channel(); in method private register(eventLoopGroup EventLoopGroup, serverAddress InetSocketAddress, contextPath String, isSecure boolean) : Future<String> from class org.mockserver.websocket.WebSocketClient


    @Test
    public void shouldNotContainMoreThenMaximumNumberOfEntries() {
        // given
        CircularHashMap<String, String> circularHashMap = new CircularHashMap<>(3);

        // when
        circularHashMap.put("1", "1");
        circularHashMap.put("2", "2");
        circularHashMap.put("3", "3");
        circularHashMap.put("4", "4");

        // then
        assertEquals(3, circularHashMap.size());
        assertFalse(circularHashMap.containsKey("1"));
        assertTrue(circularHashMap.containsKey("2"));
        assertTrue(circularHashMap.containsKey("3"));
        assertTrue(circularHashMap.containsKey("4"));
    }

    @Test
    public void shouldNotContainMoreThenMaximumNumberOfEntries() {
        // given
        CircularHashMap<String, String> circularHashMap = new CircularHashMap<String, String>(3);

        // when
        circularHashMap.put("1", "1");
        circularHashMap.put("2", "2");
        circularHashMap.put("3", "3");
        circularHashMap.put("4", "4");

        // then
        assertEquals(3, circularHashMap.size());
        assertFalse(circularHashMap.containsKey("1"));
        assertTrue(circularHashMap.containsKey("2"));
        assertTrue(circularHashMap.containsKey("3"));
        assertTrue(circularHashMap.containsKey("4"));
    }

Replace Generic With Diamond CircularHashMap<String,String> with CircularHashMap<> in method public shouldNotContainMoreThenMaximumNumberOfEntries() : void from class org.mockserver.collections.CircularHashMapTest


    @Test
    public void shouldFindKeyByObject() {
        // given
        CircularHashMap<String, String> circularHashMap = new CircularHashMap<>(5);

        // when
        circularHashMap.put("0", "a");
        circularHashMap.put("1", "b");
        circularHashMap.put("2", "c");
        circularHashMap.put("3", "d");
        circularHashMap.put("4", "d");
        circularHashMap.put("5", "e");

        // then
        assertThat(circularHashMap.findKey("b"), is("1"));
        assertThat(circularHashMap.findKey("c"), is("2"));
        assertThat(circularHashMap.findKey("x"), nullValue());
        assertThat(circularHashMap.findKey("a"), nullValue());
        assertThat(circularHashMap.findKey("d"), is("3"));
    }

    @Test
    public void shouldFindKeyByObject() {
        // given
        CircularHashMap<String, String> circularHashMap = new CircularHashMap<String, String>(5);

        // when
        circularHashMap.put("0", "a");
        circularHashMap.put("1", "b");
        circularHashMap.put("2", "c");
        circularHashMap.put("3", "d");
        circularHashMap.put("4", "d");
        circularHashMap.put("5", "e");

        // then
        assertThat(circularHashMap.findKey("b"), is("1"));
        assertThat(circularHashMap.findKey("c"), is("2"));
        assertThat(circularHashMap.findKey("x"), nullValue());
        assertThat(circularHashMap.findKey("a"), nullValue());
        assertThat(circularHashMap.findKey("d"), is("3"));
    }

Replace Generic With Diamond CircularHashMap<String,String> with CircularHashMap<> in method public shouldFindKeyByObject() : void from class org.mockserver.collections.CircularHashMapTest


    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketCallbackClientFromRegistryForClientReset() {
        // given
        Metrics.clear();
        final MockServerClient mockServerClient = new MockServerClient("localhost", getServerPort());
        mockServerClient
            .when(
                request()
            )
            .respond(
                httpRequest -> response()
            );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

        // when
        mockServerClient.reset();

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(0));
    }

    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketCallbackClientFromRegistryForClientReset() {
        // given
        Metrics.clear();
        final MockServerClient mockServerClient = new MockServerClient("localhost", getServerPort());
        mockServerClient
            .when(
                request()
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        return response();
                    }
                }
            );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

        // when
        mockServerClient.reset();

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(0));
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest.shouldRemoveWebsocketCallbackClientFromRegistryForClientReset.respond.new ExpectationResponseCallback with httpRequest -> response() in method public shouldRemoveWebsocketCallbackClientFromRegistryForClientReset() : void from class org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest


    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketCallbackClientFromRegistryForClientStop() {
        // given
        Metrics.clear();
        final MockServerClient mockServerClient = new ClientAndServer();
        mockServerClient
            .when(
                request()
            )
            .respond(
                httpRequest -> response()
            );

        try {
            // then
            Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

            // when
            mockServerClient.stop();

            // then
            Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(0));
        } finally {
            mockServerClient.stop();
        }
    }

    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketCallbackClientFromRegistryForClientStop() {
        // given
        Metrics.clear();
        final MockServerClient mockServerClient = new ClientAndServer();
        mockServerClient
            .when(
                request()
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        return response();
                    }
                }
            );

        try {
            // then
            Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

            // when
            mockServerClient.stop();

            // then
            Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(0));
        } finally {
            mockServerClient.stop();
        }
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest.shouldRemoveWebsocketCallbackClientFromRegistryForClientStop.respond.new ExpectationResponseCallback with httpRequest -> response() in method public shouldRemoveWebsocketCallbackClientFromRegistryForClientStop() : void from class org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest


    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketResponseHandlerFromRegistry() {
        // given
        Metrics.clear();
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("websocket_response_handler"))
            )
            .respond(
                httpRequest -> {
                    // then
                    return response()
                        .withBody("websocket_response_handler_count_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT) + "_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT));
                }
            );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

        // when
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody("websocket_response_handler_count_1_0"),
            makeRequest(
                request()
                    .withPath(calculatePath("websocket_response_handler")),
                headersToIgnore)
        );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT), CoreMatchers.is(0));
    }

    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketResponseHandlerFromRegistry() {
        // given
        Metrics.clear();
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("websocket_response_handler"))
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        // then
                        return response()
                            .withBody("websocket_response_handler_count_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT) + "_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT));
                    }
                }
            );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

        // when
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody("websocket_response_handler_count_1_0"),
            makeRequest(
                request()
                    .withPath(calculatePath("websocket_response_handler")),
                headersToIgnore)
        );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT), CoreMatchers.is(0));
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest.shouldRemoveWebsocketResponseHandlerFromRegistry.respond.new ExpectationResponseCallback with httpRequest -> {return response().withBody("websocket_response_handler_count_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT) + "_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT)); in method public shouldRemoveWebsocketResponseHandlerFromRegistry() : void from class org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest


    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketForwardHandlerFromRegistry() {
        // given
        Metrics.clear();
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("websocket_forward_handler"))
            )
            .forward(
                httpRequest -> request()
                    .withHeader("Host", "localhost:" + insecureEchoServer.getPort())
                    .withBody("websocket_forward_handler_count_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT) + "_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT))
            );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

        // when
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody("websocket_forward_handler_count_1_0"),
            makeRequest(
                request()
                    .withPath(calculatePath("websocket_forward_handler")),
                headersToIgnore)
        );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT), CoreMatchers.is(0));
    }

    @Test // same JVM due to dynamic calls to static Metrics class
    public void shouldRemoveWebsocketForwardHandlerFromRegistry() {
        // given
        Metrics.clear();
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("websocket_forward_handler"))
            )
            .forward(
                new ExpectationForwardCallback() {
                    @Override
                    public HttpRequest handle(HttpRequest httpRequest) {
                        return request()
                            .withHeader("Host", "localhost:" + insecureEchoServer.getPort())
                            .withBody("websocket_forward_handler_count_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT) + "_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT));
                    }
                }
            );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_CLIENT_COUNT), CoreMatchers.is(1));

        // when
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody("websocket_forward_handler_count_1_0"),
            makeRequest(
                request()
                    .withPath(calculatePath("websocket_forward_handler")),
                headersToIgnore)
        );

        // then
        Assert.assertThat(Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT), CoreMatchers.is(0));
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest.shouldRemoveWebsocketForwardHandlerFromRegistry.forward.new ExpectationForwardCallback with httpRequest -> request().withHeader("Host","localhost:" + insecureEchoServer.getPort()).withBody("websocket_forward_handler_count_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_FORWARD_HANDLER_COUNT) + "_" + Metrics.get(Metrics.Name.WEBSOCKET_CALLBACK_RESPONSE_HANDLER_COUNT)) in method public shouldRemoveWebsocketForwardHandlerFromRegistry() : void from class org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest


    @Test
    public void shouldNotAllowUseOfWebsocketClientInsideCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration"))
            )
            .respond(
                httpRequest -> {
                    mockServerClient
                        .when(
                            request()
                                .withPath(calculatePath("reentrant_websocketclient_registration"))
                        )
                        .respond(
                            httpRequest1 -> {
                                // then
                                return response()
                                    .withBody("reentrant_websocketclient_registration");
                            }
                        );
                    return response()
                        .withBody("prevent_reentrant_websocketclient_registration");
                }
            );

        // when
        assertEquals(
            response()
                .withStatusCode(NOT_FOUND_404.code())
                .withReasonPhrase(NOT_FOUND_404.reasonPhrase())
                .withBody("It is not possible to re-use the same MockServerClient instance to register a new object callback while responding to an object callback, please use a separate instance of the MockServerClient inside a callback"),
            makeRequest(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration")),
                headersToIgnore)
        );

    }

    @Test
    public void shouldNotAllowUseOfWebsocketClientInsideCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration"))
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        mockServerClient
                            .when(
                                request()
                                    .withPath(calculatePath("reentrant_websocketclient_registration"))
                            )
                            .respond(
                                new ExpectationResponseCallback() {
                                    @Override
                                    public HttpResponse handle(HttpRequest httpRequest) {
                                        // then
                                        return response()
                                            .withBody("reentrant_websocketclient_registration");
                                    }
                                }
                            );
                        return response()
                            .withBody("prevent_reentrant_websocketclient_registration");
                    }
                }
            );

        // when
        assertEquals(
            response()
                .withStatusCode(NOT_FOUND_404.code())
                .withReasonPhrase(NOT_FOUND_404.reasonPhrase())
                .withBody("It is not possible to re-use the same MockServerClient instance to register a new object callback while responding to an object callback, please use a separate instance of the MockServerClient inside a callback"),
            makeRequest(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration")),
                headersToIgnore)
        );

    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest.shouldNotAllowUseOfWebsocketClientInsideCallback.respond.new ExpectationResponseCallback with httpRequest -> {mockServerClient.when(request().withPath(calculatePath("reentrant_websocketclient_registration"))).respond(httpRequest1 -> { in method public shouldNotAllowUseOfWebsocketClientInsideCallback() : void from class org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest


    @Test
    public void shouldAllowUseOfSeparateWebsocketClientInsideCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration"))
            )
            .respond(
                httpRequest -> {
                    new MockServerClient("localhost", getServerPort())
                        .when(
                            request()
                                .withPath(calculatePath("reentrant_websocketclient_registration"))
                        )
                        .respond(
                            httpRequest1 -> {
                                // then
                                return response()
                                    .withBody("reentrant_websocketclient_registration");
                            }
                        );
                    return response()
                        .withBody("prevent_reentrant_websocketclient_registration");
                }
            );

        // when
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody("prevent_reentrant_websocketclient_registration"),
            makeRequest(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration")),
                headersToIgnore)
        );

    }

    @Test
    public void shouldAllowUseOfSeparateWebsocketClientInsideCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration"))
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        new MockServerClient("localhost", getServerPort())
                            .when(
                                request()
                                    .withPath(calculatePath("reentrant_websocketclient_registration"))
                            )
                            .respond(
                                new ExpectationResponseCallback() {
                                    @Override
                                    public HttpResponse handle(HttpRequest httpRequest) {
                                        // then
                                        return response()
                                            .withBody("reentrant_websocketclient_registration");
                                    }
                                }
                            );
                        return response()
                            .withBody("prevent_reentrant_websocketclient_registration");
                    }
                }
            );

        // when
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody("prevent_reentrant_websocketclient_registration"),
            makeRequest(
                request()
                    .withPath(calculatePath("prevent_reentrant_websocketclient_registration")),
                headersToIgnore)
        );

    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest.shouldAllowUseOfSeparateWebsocketClientInsideCallback.respond.new ExpectationResponseCallback with httpRequest -> {new MockServerClient("localhost",getServerPort()).when(request().withPath(calculatePath("reentrant_websocketclient_registration"))).respond(httpRequest1 -> { in method public shouldAllowUseOfSeparateWebsocketClientInsideCallback() : void from class org.mockserver.integration.mocking.WebsocketCallbackRegistryIntegrationTest


    public void responseObjectCallback() {
        new MockServerClient("localhost", 1080)
            .when(
                request()
                    .withPath("/some/path")
            )
            .respond(
                httpRequest -> {
                    if (httpRequest.getMethod().getValue().equals("POST")) {
                        return response()
                            .withStatusCode(ACCEPTED_202.code())
                            .withHeaders(
                                header("x-object-callback", "test_object_callback_header")
                            )
                            .withBody("an_object_callback_response");
                    } else {
                        return notFoundResponse();
                    }
                }
            );

    }

    public void responseObjectCallback() {
        new MockServerClient("localhost", 1080)
            .when(
                request()
                    .withPath("/some/path")
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        if (httpRequest.getMethod().getValue().equals("POST")) {
                            return response()
                                .withStatusCode(ACCEPTED_202.code())
                                .withHeaders(
                                    header("x-object-callback", "test_object_callback_header")
                                )
                                .withBody("an_object_callback_response");
                        } else {
                            return notFoundResponse();
                        }
                    }
                }
            );

    }

Replace Anonymous With Lambda org.mockserver.examples.mockserver.CallbackActionExamples.responseObjectCallback.respond.new ExpectationResponseCallback with httpRequest -> {if(httpRequest.getMethod().getValue().equals("POST")){return response().withStatusCode(ACCEPTED_202.code()).withHeaders(header("x-object-callback","test_object_callback_header")).withBody("an_object_callback_response"); in method public responseObjectCallback() : void from class org.mockserver.examples.mockserver.CallbackActionExamples


    public void forwardObjectCallback() {
        new MockServerClient("localhost", 1080)
            .when(
                request()
                    .withPath("/some/path")
            )
            .forward(
                httpRequest -> request()
                    .withPath(httpRequest.getPath())
                    .withMethod("POST")
                    .withHeaders(
                        header("x-callback", "test_callback_header"),
                        header("Content-Length", "a_callback_request".getBytes(UTF_8).length),
                        header("Connection", "keep-alive")
                    )
                    .withBody("a_callback_request")
            );

    }

    public void forwardObjectCallback() {
new MockServerClient("localhost", 1080)
    .when(
        request()
            .withPath("/some/path")
    )
    .forward(
        new ExpectationForwardCallback() {
            @Override
            public HttpRequest handle(HttpRequest httpRequest) {
                return request()
                    .withPath(httpRequest.getPath())
                    .withMethod("POST")
                    .withHeaders(
                        header("x-callback", "test_callback_header"),
                        header("Content-Length", "a_callback_request".getBytes(UTF_8).length),
                        header("Connection", "keep-alive")
                    )
                    .withBody("a_callback_request");
            }
        }
    );

    }

Replace Anonymous With Lambda org.mockserver.examples.mockserver.CallbackActionExamples.forwardObjectCallback.forward.new ExpectationForwardCallback with httpRequest -> request().withPath(httpRequest.getPath()).withMethod("POST").withHeaders(header("x-callback","test_callback_header"),header("Content-Length","a_callback_request".getBytes(UTF_8).length),header("Connection","keep-alive")).withBody("a_callback_request") in method public forwardObjectCallback() : void from class org.mockserver.examples.mockserver.CallbackActionExamples


    private void upgradeChannel(final ChannelHandlerContext ctx, FullHttpRequest httpRequest) {
        handshaker = new WebSocketServerHandshakerFactory(
            "ws://" + httpRequest.headers().get(HOST) + UPGRADE_CHANNEL_FOR_CALLBACK_WEB_SOCKET_URI,
            null,
            true,
            Integer.MAX_VALUE
        ).newHandshaker(httpRequest);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        } else {
            final String clientId = UUID.randomUUID().toString();
            handshaker
                .handshake(
                    ctx.channel(),
                    httpRequest,
                    new DefaultHttpHeaders().add("X-CLIENT-REGISTRATION-ID", clientId),
                    ctx.channel().newPromise()
                )
                .addListener((ChannelFutureListener) future -> {
                    ctx.pipeline().remove(DashboardWebSocketServerHandler.class);
                    ctx.pipeline().remove(MockServerServerCodec.class);
                    ctx.pipeline().remove(MockServerHandler.class);
                    mockServerLogger.logEvent(
                        new LogEntry()
                            .setType(LogEntry.LogMessageType.TRACE)
                            .setLogLevel(Level.TRACE)
                            .setMessageFormat("Registering client " + clientId)
                    );
                    webSocketClientRegistry.registerClient(clientId, ctx);
                    future.channel().closeFuture().addListener((ChannelFutureListener) future1 -> {
                        mockServerLogger.logEvent(
                            new LogEntry()
                                .setType(LogEntry.LogMessageType.TRACE)
                                .setLogLevel(Level.TRACE)
                                .setMessageFormat("Unregistering callback for client " + clientId)
                        );
                        webSocketClientRegistry.unregisterClient(clientId);
                    });
                });
        }
    }

    private void upgradeChannel(final ChannelHandlerContext ctx, FullHttpRequest httpRequest) {
        handshaker = new WebSocketServerHandshakerFactory(
            "ws://" + httpRequest.headers().get(HOST) + UPGRADE_CHANNEL_FOR_CALLBACK_WEB_SOCKET_URI,
            null,
            true,
            Integer.MAX_VALUE
        ).newHandshaker(httpRequest);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        } else {
            final String clientId = UUID.randomUUID().toString();
            handshaker
                .handshake(
                    ctx.channel(),
                    httpRequest,
                    new DefaultHttpHeaders().add("X-CLIENT-REGISTRATION-ID", clientId),
                    ctx.channel().newPromise()
                )
                .addListener(new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) {
                        ctx.pipeline().remove(DashboardWebSocketServerHandler.class);
                        ctx.pipeline().remove(MockServerServerCodec.class);
                        ctx.pipeline().remove(MockServerHandler.class);
                        webSocketClientRegistry.registerClient(clientId, ctx);
                        future.channel().closeFuture().addListener(new ChannelFutureListener() {
                            @Override
                            public void operationComplete(ChannelFuture future) {
                                webSocketClientRegistry.unregisterClient(clientId);
                            }
                        });
                    }
                });
        }
    }

Replace Anonymous With Lambda org.mockserver.callback.CallbackWebSocketServerHandler.upgradeChannel.addListener.new ChannelFutureListener with future -> {ctx.pipeline().remove(DashboardWebSocketServerHandler.class); in method private upgradeChannel(ctx ChannelHandlerContext, httpRequest FullHttpRequest) : void from class org.mockserver.callback.CallbackWebSocketServerHandler


    private String formatProcessingReport(ProcessingReport validate) {
        List<String> validationErrors = new ArrayList<>();
        for (ProcessingMessage processingMessage : validate) {
            String fieldPointer = "";
            if (processingMessage.asJson().get("instance") != null && processingMessage.asJson().get("instance").get("pointer") != null) {
                fieldPointer = String.valueOf(processingMessage.asJson().get("instance").get("pointer")).replaceAll("\"", "");
            }
            String schemaPointer = "";
            if (processingMessage.asJson().get("schema") != null && processingMessage.asJson().get("schema").get("pointer") != null) {
                schemaPointer = String.valueOf(processingMessage.asJson().get("schema").get("pointer"));
            }
            if (fieldPointer.endsWith("/headers")) {
                validationErrors.add("for field \"" + fieldPointer + "\" only one of the following example formats is allowed: " + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : {" + NEW_LINE +
                    "        \"exampleHeaderName\" : [ \"exampleHeaderValue\" ]" + NEW_LINE +
                    "        \"exampleMultiValuedHeaderName\" : [ \"exampleHeaderValueOne\", \"exampleHeaderValueTwo\" ]" + NEW_LINE +
                    "    }" + NEW_LINE + NEW_LINE +
                    "   or:" + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : [" + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleHeaderName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleHeaderValue\" ]" + NEW_LINE +
                    "        }," + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleMultiValuedHeaderName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleHeaderValueOne\", \"exampleHeaderValueTwo\" ]" + NEW_LINE +
                    "        }" + NEW_LINE +
                    "    ]");
            } else if (fieldPointer.endsWith("/queryStringParameters")) {
                validationErrors.add("for field \"" + fieldPointer + "\" only one of the following example formats is allowed: " + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : {" + NEW_LINE +
                    "        \"exampleParameterName\" : [ \"exampleParameterValue\" ]" + NEW_LINE +
                    "        \"exampleMultiValuedParameterName\" : [ \"exampleParameterValueOne\", \"exampleParameterValueTwo\" ]" + NEW_LINE +
                    "    }" + NEW_LINE + NEW_LINE +
                    "   or:" + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : [" + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleParameterName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleParameterValue\" ]" + NEW_LINE +
                    "        }," + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleMultiValuedParameterName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleParameterValueOne\", \"exampleParameterValueTwo\" ]" + NEW_LINE +
                    "        }" + NEW_LINE +
                    "    ]");
            } else if (fieldPointer.endsWith("/cookies")) {
                validationErrors.add("for field \"" + fieldPointer + "\" only one of the following example formats is allowed: " + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : {" + NEW_LINE +
                    "        \"exampleCookieNameOne\" : \"exampleCookieValueOne\"" + NEW_LINE +
                    "        \"exampleCookieNameTwo\" : \"exampleCookieValueTwo\"" + NEW_LINE +
                    "    }" + NEW_LINE + NEW_LINE +
                    "   or:" + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : [" + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleCookieNameOne\"," + NEW_LINE +
                    "            \"values\" : \"exampleCookieValueOne\"" + NEW_LINE +
                    "        }," + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleCookieNameTwo\"," + NEW_LINE +
                    "            \"values\" : \"exampleCookieValueTwo\"" + NEW_LINE +
                    "        }" + NEW_LINE +
                    "    ]");
            } else if (fieldPointer.endsWith("/body") && !schemaPointer.contains("bodyWithContentType")) {
                validationErrors.add("for field \"" + fieldPointer + "\" a plain string, JSON object or one of the following example bodies must be specified " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"BINARY\"," + NEW_LINE +
                    "     \"base64Bytes\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }, " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"JSON\"," + NEW_LINE +
                    "     \"json\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"," + NEW_LINE +
                    "     \"matchType\": \"ONLY_MATCHING_FIELDS\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"JSON_SCHEMA\"," + NEW_LINE +
                    "     \"jsonSchema\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"JSON_PATH\"," + NEW_LINE +
                    "     \"jsonPath\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"PARAMETERS\"," + NEW_LINE +
                    "     \"parameters\": {\"name\": \"value\"}" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"REGEX\"," + NEW_LINE +
                    "     \"regex\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"STRING\"," + NEW_LINE +
                    "     \"string\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"XML\"," + NEW_LINE +
                    "     \"xml\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"XML_SCHEMA\"," + NEW_LINE +
                    "     \"xmlSchema\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"XPATH\"," + NEW_LINE +
                    "     \"xpath\": \"\"" + NEW_LINE +
                    "   }");
            } else if (fieldPointer.endsWith("/body") && schemaPointer.contains("bodyWithContentType")) {
                validationErrors.add("for field \"" + fieldPointer + "\" a plain string, JSON object or one of the following example bodies must be specified " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"BINARY\"," + NEW_LINE +
                    "     \"base64Bytes\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }, " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"JSON\"," + NEW_LINE +
                    "     \"json\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"PARAMETERS\"," + NEW_LINE +
                    "     \"parameters\": {\"name\": \"value\"}" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"STRING\"," + NEW_LINE +
                    "     \"string\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"XML\"," + NEW_LINE +
                    "     \"xml\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }");
            } else if (String.valueOf(processingMessage.asJson().get("keyword")).equals("\"oneOf\"")) {
                StringBuilder oneOfErrorMessage = new StringBuilder("oneOf of the following must be specified ");
                if (fieldPointer.isEmpty()) {
                    oneOfErrorMessage.append(Arrays.asList(
                        "\"httpResponse\"",
                        "\"httpResponseTemplate\"",
                        "\"httpResponseObjectCallback\"",
                        "\"httpResponseClassCallback\"",
                        "\"httpForward\"",
                        "\"httpForwardTemplate\"",
                        "\"httpForwardObjectCallback\"",
                        "\"httpForwardClassCallback\"",
                        "\"httpOverrideForwardedRequest\"",
                        "\"httpError\""
                    ));
                } else {
                    for (JsonNode jsonNode : processingMessage.asJson().get("reports")) {
                        if (jsonNode.get(0) != null && jsonNode.get(0).get("required") != null && jsonNode.get(0).get("required").get(0) != null) {
                            oneOfErrorMessage.append(jsonNode.get(0).get("required").get(0)).append(" ");
                        }
                    }
                }
                oneOfErrorMessage.append(" but ").append(processingMessage.asJson().get("matched")).append(" found");
                validationErrors.add(oneOfErrorMessage.toString() + (fieldPointer.isEmpty() ? "" : " for field \"" + fieldPointer + "\""));
            } else if (fieldPointer.endsWith("/times") && processingMessage.toString().contains("has properties which are not allowed by the schema") && String.valueOf(processingMessage.asJson().get("schema")).contains("verificationTimes")) {
                validationErrors.add(processingMessage.getMessage() + " for field \"" + fieldPointer + "\", allowed fields are [\"atLeast\", \"atMost\"]");
            } else {
                validationErrors.add(processingMessage.getMessage() + (fieldPointer.isEmpty() ? "" : " for field \"" + fieldPointer + "\""));
            }
        }
        return validationErrors.size() + " error" + (validationErrors.size() > 1 ? "s" : "") + ":" + NEW_LINE + " - " + Joiner.on(NEW_LINE + " - ").join(validationErrors);
    }

    private String formatProcessingReport(ProcessingReport validate) {
        List<String> validationErrors = new ArrayList<String>();
        for (ProcessingMessage processingMessage : validate) {
            String fieldPointer = "";
            if (processingMessage.asJson().get("instance") != null && processingMessage.asJson().get("instance").get("pointer") != null) {
                fieldPointer = String.valueOf(processingMessage.asJson().get("instance").get("pointer")).replaceAll("\"", "");
            }
            String schemaPointer = "";
            if (processingMessage.asJson().get("schema") != null && processingMessage.asJson().get("schema").get("pointer") != null) {
                schemaPointer = String.valueOf(processingMessage.asJson().get("schema").get("pointer"));
            }
            if (fieldPointer.endsWith("/headers")) {
                validationErrors.add("for field \"" + fieldPointer + "\" only one of the following example formats is allowed: " + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : {" + NEW_LINE +
                    "        \"exampleHeaderName\" : [ \"exampleHeaderValue\" ]" + NEW_LINE +
                    "        \"exampleMultiValuedHeaderName\" : [ \"exampleHeaderValueOne\", \"exampleHeaderValueTwo\" ]" + NEW_LINE +
                    "    }" + NEW_LINE + NEW_LINE +
                    "   or:" + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : [" + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleHeaderName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleHeaderValue\" ]" + NEW_LINE +
                    "        }," + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleMultiValuedHeaderName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleHeaderValueOne\", \"exampleHeaderValueTwo\" ]" + NEW_LINE +
                    "        }" + NEW_LINE +
                    "    ]");
            } else if (fieldPointer.endsWith("/queryStringParameters")) {
                validationErrors.add("for field \"" + fieldPointer + "\" only one of the following example formats is allowed: " + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : {" + NEW_LINE +
                    "        \"exampleParameterName\" : [ \"exampleParameterValue\" ]" + NEW_LINE +
                    "        \"exampleMultiValuedParameterName\" : [ \"exampleParameterValueOne\", \"exampleParameterValueTwo\" ]" + NEW_LINE +
                    "    }" + NEW_LINE + NEW_LINE +
                    "   or:" + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : [" + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleParameterName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleParameterValue\" ]" + NEW_LINE +
                    "        }," + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleMultiValuedParameterName\"," + NEW_LINE +
                    "            \"values\" : [ \"exampleParameterValueOne\", \"exampleParameterValueTwo\" ]" + NEW_LINE +
                    "        }" + NEW_LINE +
                    "    ]");
            } else if (fieldPointer.endsWith("/cookies")) {
                validationErrors.add("for field \"" + fieldPointer + "\" only one of the following example formats is allowed: " + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : {" + NEW_LINE +
                    "        \"exampleCookieNameOne\" : \"exampleCookieValueOne\"" + NEW_LINE +
                    "        \"exampleCookieNameTwo\" : \"exampleCookieValueTwo\"" + NEW_LINE +
                    "    }" + NEW_LINE + NEW_LINE +
                    "   or:" + NEW_LINE + NEW_LINE +
                    "    \"" + fieldPointer + "\" : [" + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleCookieNameOne\"," + NEW_LINE +
                    "            \"values\" : \"exampleCookieValueOne\"" + NEW_LINE +
                    "        }," + NEW_LINE +
                    "        {" + NEW_LINE +
                    "            \"name\" : \"exampleCookieNameTwo\"," + NEW_LINE +
                    "            \"values\" : \"exampleCookieValueTwo\"" + NEW_LINE +
                    "        }" + NEW_LINE +
                    "    ]");
            } else if (fieldPointer.endsWith("/body") && !schemaPointer.contains("bodyWithContentType")) {
                validationErrors.add("for field \"" + fieldPointer + "\" a plain string, JSON object or one of the following example bodies must be specified " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"BINARY\"," + NEW_LINE +
                    "     \"base64Bytes\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }, " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"JSON\"," + NEW_LINE +
                    "     \"json\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"," + NEW_LINE +
                    "     \"matchType\": \"ONLY_MATCHING_FIELDS\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"JSON_SCHEMA\"," + NEW_LINE +
                    "     \"jsonSchema\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"JSON_PATH\"," + NEW_LINE +
                    "     \"jsonPath\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"PARAMETERS\"," + NEW_LINE +
                    "     \"parameters\": {\"name\": \"value\"}" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"REGEX\"," + NEW_LINE +
                    "     \"regex\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"STRING\"," + NEW_LINE +
                    "     \"string\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"XML\"," + NEW_LINE +
                    "     \"xml\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"XML_SCHEMA\"," + NEW_LINE +
                    "     \"xmlSchema\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"not\": false," + NEW_LINE +
                    "     \"type\": \"XPATH\"," + NEW_LINE +
                    "     \"xpath\": \"\"" + NEW_LINE +
                    "   }");
            } else if (fieldPointer.endsWith("/body") && schemaPointer.contains("bodyWithContentType")) {
                validationErrors.add("for field \"" + fieldPointer + "\" a plain string, JSON object or one of the following example bodies must be specified " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"BINARY\"," + NEW_LINE +
                    "     \"base64Bytes\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }, " + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"JSON\"," + NEW_LINE +
                    "     \"json\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"PARAMETERS\"," + NEW_LINE +
                    "     \"parameters\": {\"name\": \"value\"}" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"STRING\"," + NEW_LINE +
                    "     \"string\": \"\"" + NEW_LINE +
                    "   }," + NEW_LINE +
                    "   {" + NEW_LINE +
                    "     \"type\": \"XML\"," + NEW_LINE +
                    "     \"xml\": \"\"," + NEW_LINE +
                    "     \"contentType\": \"\"" + NEW_LINE +
                    "   }");
            } else if (String.valueOf(processingMessage.asJson().get("keyword")).equals("\"oneOf\"")) {
                StringBuilder oneOfErrorMessage = new StringBuilder("oneOf of the following must be specified ");
                if (fieldPointer.isEmpty()) {
                    oneOfErrorMessage.append(Arrays.asList(
                        "\"httpResponse\"",
                        "\"httpResponseTemplate\"",
                        "\"httpResponseObjectCallback\"",
                        "\"httpResponseClassCallback\"",
                        "\"httpForward\"",
                        "\"httpForwardTemplate\"",
                        "\"httpForwardObjectCallback\"",
                        "\"httpForwardClassCallback\"",
                        "\"httpOverrideForwardedRequest\"",
                        "\"httpError\""
                    ));
                } else {
                    for (JsonNode jsonNode : processingMessage.asJson().get("reports")) {
                        if (jsonNode.get(0) != null && jsonNode.get(0).get("required") != null && jsonNode.get(0).get("required").get(0) != null) {
                            oneOfErrorMessage.append(jsonNode.get(0).get("required").get(0)).append(" ");
                        }
                    }
                }
                oneOfErrorMessage.append(" but ").append(processingMessage.asJson().get("matched")).append(" found");
                validationErrors.add(oneOfErrorMessage.toString() + (fieldPointer.isEmpty() ? "" : " for field \"" + fieldPointer + "\""));
            } else if (fieldPointer.endsWith("/times") && processingMessage.toString().contains("has properties which are not allowed by the schema") && String.valueOf(processingMessage.asJson().get("schema")).contains("verificationTimes")) {
                validationErrors.add(processingMessage.getMessage() + " for field \"" + fieldPointer + "\", allowed fields are [\"atLeast\", \"atMost\"]");
            } else {
                validationErrors.add(processingMessage.getMessage() + (fieldPointer.isEmpty() ? "" : " for field \"" + fieldPointer + "\""));
            }
        }
        return validationErrors.size() + " error" + (validationErrors.size() > 1 ? "s" : "") + ":" + NEW_LINE + " - " + Joiner.on(NEW_LINE + " - ").join(validationErrors);
    }

Replace Generic With Diamond ArrayList<String> with ArrayList<> in method private formatProcessingReport(validate ProcessingReport) : String from class org.mockserver.validator.jsonschema.JsonSchemaValidator


    public EchoServer(final boolean secure, final Error error) {
        new Thread(() -> {
            bossGroup = new NioEventLoopGroup(1);
            workerGroup = new NioEventLoopGroup();
            new ServerBootstrap().group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100)
                .handler(new LoggingHandler(EchoServer.class))
                .childHandler(new EchoServerInitializer(mockServerLogger, secure, error))
                .childAttr(LOG_FILTER, logFilter)
                .childAttr(NEXT_RESPONSE, nextResponse)
                .childAttr(ONLY_RESPONSE, onlyResponse)
                .bind(0)
                .addListener((ChannelFutureListener) future -> {
                    if (future.isSuccess()) {
                        boundPort.set(((InetSocketAddress) future.channel().localAddress()).getPort());
                    } else {
                        boundPort.setException(future.cause());
                        eventLoopGroup.shutdownGracefully(0, 1, TimeUnit.MILLISECONDS);
                    }
                });
        }, "MockServer EchoServer Thread").start();

        try {
            // wait for proxy to start all channels
            boundPort.get();
            TimeUnit.MILLISECONDS.sleep(5);
        } catch (Exception e) {
            mockServerLogger.logEvent(
                new LogEntry()
                    .setType(LogEntry.LogMessageType.EXCEPTION)
                    .setLogLevel(Level.ERROR)
                    .setMessageFormat("Exception while waiting for proxy to complete starting up")
                    .setThrowable(e)
            );
        }
    }

    public EchoServer(final boolean secure, final Error error) {
        new Thread(() -> {
            bossGroup = new NioEventLoopGroup(1);
            workerGroup = new NioEventLoopGroup();
            new ServerBootstrap().group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100)
                .handler(new LoggingHandler(EchoServer.class))
                .childHandler(new EchoServerInitializer(mockServerLogger, secure, error))
                .childAttr(LOG_FILTER, logFilter)
                .childAttr(NEXT_RESPONSE, nextResponse)
                .childAttr(ONLY_RESPONSE, onlyResponse)
                .bind(0)
                .addListener(new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) throws Exception {
                        if (future.isSuccess()) {
                            boundPort.set(((InetSocketAddress) future.channel().localAddress()).getPort());
                        } else {
                            boundPort.setException(future.cause());
                            eventLoopGroup.shutdownGracefully(0, 1, TimeUnit.MILLISECONDS);
                        }
                    }
                });
        }, "MockServer EchoServer Thread").start();

        try {
            // wait for proxy to start all channels
            boundPort.get();
            TimeUnit.MILLISECONDS.sleep(5);
        } catch (Exception e) {
            mockServerLogger.logEvent(
                new LogEntry()
                    .setType(LogEntry.LogMessageType.EXCEPTION)
                    .setLogLevel(Level.ERROR)
                    .setMessageFormat("Exception while waiting for proxy to complete starting up")
                    .setThrowable(e)
            );
        }
    }

Replace Anonymous With Lambda org.mockserver.echo.http.EchoServer.EchoServer.start.new Thread.addListener.new ChannelFutureListener with future -> {if(future.isSuccess()){boundPort.set(((InetSocketAddress)future.channel().localAddress()).getPort()); in method public EchoServer(secure boolean, error Error) from class org.mockserver.echo.http.EchoServer


    @Test
    public void shouldRespondByObjectCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("object_callback"))
            )
            .respond(
                httpRequest -> {
                    HttpRequest expectation = request()
                        .withPath(calculatePath("object_callback"))
                        .withMethod("POST")
                        .withHeaders(
                            header("x-test", "test_headers_and_body")
                        )
                        .withBody("an_example_body_http");
                    if (new MatcherBuilder(mock(MockServerLogger.class)).transformsToMatcher(expectation).matches(null, httpRequest)) {
                        return response()
                            .withStatusCode(ACCEPTED_202.code())
                            .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                            .withHeaders(
                                header("x-object-callback", "test_object_callback_header")
                            )
                            .withBody("an_object_callback_response");
                    } else {
                        return notFoundResponse();
                    }
                }
            );

        // then
        // - in http
        assertEquals(
            response()
                .withStatusCode(ACCEPTED_202.code())
                .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                .withHeaders(
                    header("x-object-callback", "test_object_callback_header")
                )
                .withBody("an_object_callback_response"),
            makeRequest(
                request()
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body")
                    )
                    .withBody("an_example_body_http"),
                headersToIgnore
            )
        );

        // - in https
        assertEquals(
            response()
                .withStatusCode(ACCEPTED_202.code())
                .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                .withHeaders(
                    header("x-object-callback", "test_object_callback_header")
                )
                .withBody("an_object_callback_response"),
            makeRequest(
                request()
                    .withSecure(true)
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body")
                    )
                    .withBody("an_example_body_http"),
                headersToIgnore
            )
        );
    }

    @Test
    public void shouldRespondByObjectCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("object_callback"))
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        HttpRequest expectation = request()
                            .withPath(calculatePath("object_callback"))
                            .withMethod("POST")
                            .withHeaders(
                                header("x-test", "test_headers_and_body")
                            )
                            .withBody("an_example_body_http");
                        if (new MatcherBuilder(mock(MockServerLogger.class)).transformsToMatcher(expectation).matches(null, httpRequest)) {
                            return response()
                                .withStatusCode(ACCEPTED_202.code())
                                .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                                .withHeaders(
                                    header("x-object-callback", "test_object_callback_header")
                                )
                                .withBody("an_object_callback_response");
                        } else {
                            return notFoundResponse();
                        }
                    }
                }
            );

        // then
        // - in http
        assertEquals(
            response()
                .withStatusCode(ACCEPTED_202.code())
                .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                .withHeaders(
                    header("x-object-callback", "test_object_callback_header")
                )
                .withBody("an_object_callback_response"),
            makeRequest(
                request()
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body")
                    )
                    .withBody("an_example_body_http"),
                headersToIgnore
            )
        );

        // - in https
        assertEquals(
            response()
                .withStatusCode(ACCEPTED_202.code())
                .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                .withHeaders(
                    header("x-object-callback", "test_object_callback_header")
                )
                .withBody("an_object_callback_response"),
            makeRequest(
                request()
                    .withSecure(true)
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body")
                    )
                    .withBody("an_example_body_http"),
                headersToIgnore
            )
        );
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest.shouldRespondByObjectCallback.respond.new ExpectationResponseCallback with httpRequest -> {HttpRequest expectation=request().withPath(calculatePath("object_callback")).withMethod("POST").withHeaders(header("x-test","test_headers_and_body")).withBody("an_example_body_http"); in method public shouldRespondByObjectCallback() : void from class org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest


    @Test
    public void shouldRespondByObjectCallbackAndVerifyRequests() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("object_callback")),
                exactly(1)
            )
            .respond(
                httpRequest -> response()
                    .withStatusCode(ACCEPTED_202.code())
                    .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                    .withBody("an_object_callback_response")
            );

        // then - return response
        assertEquals(
            response()
                .withStatusCode(ACCEPTED_202.code())
                .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                .withBody("an_object_callback_response"),
            makeRequest(
                request()
                    .withPath(calculatePath("object_callback")),
                headersToIgnore
            )
        );

        // then - verify request
        mockServerClient
            .verify(
                request()
                    .withPath(calculatePath("object_callback")),
                VerificationTimes.once()
            );
        // then - verify no request
        mockServerClient
            .verify(
                request()
                    .withPath(calculatePath("some_other_path")),
                VerificationTimes.exactly(0)
            );
    }

    @Test
    public void shouldRespondByObjectCallbackAndVerifyRequests() throws InterruptedException {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("object_callback")),
                exactly(1)
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        return response()
                            .withStatusCode(ACCEPTED_202.code())
                            .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                            .withBody("an_object_callback_response");
                    }
                }
            );

        // then - return response
        assertEquals(
            response()
                .withStatusCode(ACCEPTED_202.code())
                .withReasonPhrase(ACCEPTED_202.reasonPhrase())
                .withBody("an_object_callback_response"),
            makeRequest(
                request()
                    .withPath(calculatePath("object_callback")),
                headersToIgnore
            )
        );

        // then - verify request
        mockServerClient
            .verify(
                request()
                    .withPath(calculatePath("object_callback")),
                VerificationTimes.once()
            );
        // then - verify no request
        mockServerClient
            .verify(
                request()
                    .withPath(calculatePath("some_other_path")),
                VerificationTimes.exactly(0)
            );
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest.shouldRespondByObjectCallbackAndVerifyRequests.respond.new ExpectationResponseCallback with httpRequest -> response().withStatusCode(ACCEPTED_202.code()).withReasonPhrase(ACCEPTED_202.reasonPhrase()).withBody("an_object_callback_response") in method public shouldRespondByObjectCallbackAndVerifyRequests() : void from class org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest


    @Test
    public void shouldRespondByObjectCallbackForVeryLargeRequestAndResponses() {
        int bytes = 65536 * 10;
        char[] chars = new char[bytes];
        Arrays.fill(chars, 'a');
        final String veryLargeString = new String(chars);

        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("object_callback"))
            )
            .respond(
                httpRequest -> response()
                    .withBody(veryLargeString)
            );

        // then
        // - in http
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody(veryLargeString),
            makeRequest(
                request()
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withBody(veryLargeString),
                headersToIgnore
            )
        );

        // - in https
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody(veryLargeString),
            makeRequest(
                request()
                    .withSecure(true)
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withBody(veryLargeString),
                headersToIgnore
            )
        );
    }

    @Test
    public void shouldRespondByObjectCallbackForVeryLargeRequestAndResponses() {
        int bytes = 65536 * 10;
        char[] chars = new char[bytes];
        Arrays.fill(chars, 'a');
        final String veryLargeString = new String(chars);

        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("object_callback"))
            )
            .respond(
                new ExpectationResponseCallback() {
                    @Override
                    public HttpResponse handle(HttpRequest httpRequest) {
                        return response()
                            .withBody(veryLargeString);
                    }
                }
            );

        // then
        // - in http
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody(veryLargeString),
            makeRequest(
                request()
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withBody(veryLargeString),
                headersToIgnore
            )
        );

        // - in https
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withBody(veryLargeString),
            makeRequest(
                request()
                    .withSecure(true)
                    .withPath(calculatePath("object_callback"))
                    .withMethod("POST")
                    .withBody(veryLargeString),
                headersToIgnore
            )
        );
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest.shouldRespondByObjectCallbackForVeryLargeRequestAndResponses.respond.new ExpectationResponseCallback with httpRequest -> response().withBody(veryLargeString) in method public shouldRespondByObjectCallbackForVeryLargeRequestAndResponses() : void from class org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest


    @Test
    public void shouldForwardByObjectCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("echo"))
            )
            .forward(
                httpRequest -> request()
                    .withHeader("Host", "localhost:" + (httpRequest.isSecure() ? secureEchoServer.getPort() : insecureEchoServer.getPort()))
                    .withHeader("x-test", httpRequest.getFirstHeader("x-test"))
                    .withBody("some_overridden_body")
                    .withSecure(httpRequest.isSecure())
            );

        // then
        // - in http
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withHeaders(
                    header("x-test", "test_headers_and_body")
                )
                .withBody("some_overridden_body"),
            makeRequest(
                request()
                    .withPath(calculatePath("echo"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body")
                    )
                    .withBody("an_example_body_http"),
                headersToIgnore
            )
        );
        // - in https
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withHeaders(
                    header("x-test", "test_headers_and_body_https")
                )
                .withBody("some_overridden_body"),
            makeRequest(
                request()
                    .withSecure(true)
                    .withPath(calculatePath("echo"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body_https")
                    )
                    .withBody("an_example_body_https"),
                headersToIgnore)
        );
    }

    @Test
    public void shouldForwardByObjectCallback() {
        // when
        mockServerClient
            .when(
                request()
                    .withPath(calculatePath("echo"))
            )
            .forward(
                new ExpectationForwardCallback() {
                    @Override
                    public HttpRequest handle(HttpRequest httpRequest) {
                        return request()
                            .withHeader("Host", "localhost:" + (httpRequest.isSecure() ? secureEchoServer.getPort() : insecureEchoServer.getPort()))
                            .withHeader("x-test", httpRequest.getFirstHeader("x-test"))
                            .withBody("some_overridden_body")
                            .withSecure(httpRequest.isSecure());
                    }
                }
            );

        // then
        // - in http
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withHeaders(
                    header("x-test", "test_headers_and_body")
                )
                .withBody("some_overridden_body"),
            makeRequest(
                request()
                    .withPath(calculatePath("echo"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body")
                    )
                    .withBody("an_example_body_http"),
                headersToIgnore
            )
        );
        // - in https
        assertEquals(
            response()
                .withStatusCode(OK_200.code())
                .withReasonPhrase(OK_200.reasonPhrase())
                .withHeaders(
                    header("x-test", "test_headers_and_body_https")
                )
                .withBody("some_overridden_body"),
            makeRequest(
                request()
                    .withSecure(true)
                    .withPath(calculatePath("echo"))
                    .withMethod("POST")
                    .withHeaders(
                        header("x-test", "test_headers_and_body_https")
                    )
                    .withBody("an_example_body_https"),
                headersToIgnore)
        );
    }

Replace Anonymous With Lambda org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest.shouldForwardByObjectCallback.forward.new ExpectationForwardCallback with httpRequest -> request().withHeader("Host","localhost:" + (httpRequest.isSecure() ? secureEchoServer.getPort() : insecureEchoServer.getPort())).withHeader("x-test",httpRequest.getFirstHeader("x-test")).withBody("some_overridden_body").withSecure(httpRequest.isSecure()) in method public shouldForwardByObjectCallback() : void from class org.mockserver.integration.mocking.AbstractExtendedNettyMockingIntegrationTest