From ebb31435a9a824eb7683a1af00318e26bd874fd5 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Mon, 25 Sep 2023 17:20:01 +0200 Subject: [PATCH] refactor: minor refinements to the MockWebServer Signed-off-by: Marc Nuri --- .../fabric8/mockwebserver/dsl/Function.java | 21 ----------- .../InlineWebSocketSessionBuilder.java | 7 +--- .../internal/MockServerExpectationImpl.java | 6 +-- .../mockwebserver/utils/Closeables.java | 37 ------------------- 4 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/dsl/Function.java delete mode 100644 junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/Closeables.java diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/dsl/Function.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/dsl/Function.java deleted file mode 100644 index 990910a61de..00000000000 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/dsl/Function.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fabric8.mockwebserver.dsl; - -public interface Function { - O apply(I input); -} diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/InlineWebSocketSessionBuilder.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/InlineWebSocketSessionBuilder.java index 6c72e92e477..c018e295464 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/InlineWebSocketSessionBuilder.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/InlineWebSocketSessionBuilder.java @@ -18,11 +18,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import io.fabric8.mockwebserver.Context; import io.fabric8.mockwebserver.MockServerException; import io.fabric8.mockwebserver.dsl.Emitable; import io.fabric8.mockwebserver.dsl.EventDoneable; -import io.fabric8.mockwebserver.dsl.Function; import io.fabric8.mockwebserver.dsl.TimesOrOnceable; import io.fabric8.mockwebserver.dsl.WebSocketSessionBuilder; @@ -31,17 +29,16 @@ import java.util.Collections; import java.util.List; import java.util.Queue; +import java.util.function.Function; public class InlineWebSocketSessionBuilder implements WebSocketSessionBuilder, EventDoneable { private static final ObjectMapper MAPPER = new ObjectMapper(); - private final Context context; private final Function function; private WebSocketSession session; - public InlineWebSocketSessionBuilder(Context context, Function function) { - this.context = context; + public InlineWebSocketSessionBuilder(Function function) { this.function = function; } diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java index 9ce3490853b..2e30817cf20 100644 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java +++ b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/internal/MockServerExpectationImpl.java @@ -22,7 +22,6 @@ import io.fabric8.mockwebserver.ServerRequest; import io.fabric8.mockwebserver.ServerResponse; import io.fabric8.mockwebserver.dsl.DelayPathable; -import io.fabric8.mockwebserver.dsl.Function; import io.fabric8.mockwebserver.dsl.HttpMethod; import io.fabric8.mockwebserver.dsl.MockServerExpectation; import io.fabric8.mockwebserver.dsl.Pathable; @@ -43,6 +42,7 @@ import java.util.Queue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -193,7 +193,7 @@ public Pathable>> dela @Override public WebSocketSessionBuilder> andUpgradeToWebSocket() { - return new InlineWebSocketSessionBuilder<>(context, new WebSocketSessionConverter(this)); + return new InlineWebSocketSessionBuilder<>(new WebSocketSessionConverter(this)); } /** @@ -201,7 +201,7 @@ public WebSocketSessionBuilder> andUpgradeTo */ @Override public WebSocketSessionBuilder> andUpgradeToWebSocket(ScheduledExecutorService executor) { - return new InlineWebSocketSessionBuilder<>(context, new WebSocketSessionConverter(this)); + return new InlineWebSocketSessionBuilder<>(new WebSocketSessionConverter(this)); } @Override diff --git a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/Closeables.java b/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/Closeables.java deleted file mode 100644 index a5a43ff54c3..00000000000 --- a/junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/utils/Closeables.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.mockwebserver.utils; - -import java.io.Closeable; -import java.io.IOException; -import java.util.logging.Logger; - -public final class Closeables { - - private static final Logger LOGGER = Logger.getLogger(Closeables.class.getName()); - - private Closeables() { - //Utility class - } - - public static void closeQuietly(Closeable closeable) { - try { - closeable.close(); - } catch (IOException e) { - LOGGER.warning("Error while closing object:" + closeable + ". Ignoring."); - } - } -}