From 96e39f443865f9ba475a8ac8c45b0a510a77eaeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20R=C3=BCtter?= Date: Fri, 3 Jan 2025 14:11:03 +0100 Subject: [PATCH] Remove assertions, replace with awaitility --- .../jetty/it/MissingWebsocketDependenciesIT.java | 15 +++++++-------- .../jetty/it/MissingWebsocketDependenciesIT.java | 13 ++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/http/jetty/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java b/http/jetty/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java index 23dae17dec..c71873009c 100644 --- a/http/jetty/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java +++ b/http/jetty/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java @@ -65,22 +65,21 @@ public void testMissingDepencencyWarningLogs() throws Exception { Awaitility.await("waitForLogs") .atMost(Duration.ofSeconds(50)) .pollDelay(Duration.ofMillis(200)) - .until(() -> containsString(logFile, "org.apache.felix.http.jetty[org.apache.felix.http]")); - - assertTrue(containsString(logFile, "Failed to initialize jetty specific websocket support")); - assertTrue(containsString(logFile, "Failed to initialize jakarta standard websocket support")); + .until(() -> containsString(logFile, "Failed to initialize jetty specific websocket support") + && containsString(logFile, "Failed to initialize jakarta standard websocket support")); } /** * Checks if the text is present in the file - * - * @param file the file to check + * + * @param file the file to check * @param expected the text to look for * @return true if the text was found, false otherwise */ private boolean containsString(File file, String expected) throws IOException { - String content = new String(Files.readAllBytes(file.toPath())); - return content.contains(expected); + try (Stream stream = Files.lines(file.toPath())) { + return stream.anyMatch(line -> line.contains(expected)); + } } } diff --git a/http/jetty12/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java b/http/jetty12/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java index d6051161ae..604fd8f093 100644 --- a/http/jetty12/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java +++ b/http/jetty12/src/test/java/org/apache/felix/http/jetty/it/MissingWebsocketDependenciesIT.java @@ -65,22 +65,21 @@ public void testMissingDepencencyWarningLogs() throws Exception { Awaitility.await("waitForLogs") .atMost(Duration.ofSeconds(50)) .pollDelay(Duration.ofMillis(200)) - .until(() -> containsString(logFile, "org.apache.felix.http.jetty12[org.apache.felix.http]")); - - assertTrue(containsString(logFile, "Failed to initialize jetty EE10 specific websocket support")); - assertTrue(containsString(logFile, "Failed to initialize jakarta EE10 standard websocket support")); + .until(() -> containsString(logFile, "Failed to initialize jetty EE10 specific websocket support") + && containsString(logFile, "Failed to initialize jakarta EE10 standard websocket support")); } /** * Checks if the text is present in the file * - * @param file the file to check + * @param file the file to check * @param expected the text to look for * @return true if the text was found, false otherwise */ private boolean containsString(File file, String expected) throws IOException { - String content = new String(Files.readAllBytes(file.toPath())); - return content.contains(expected); + try (Stream stream = Files.lines(file.toPath())) { + return stream.anyMatch(line -> line.contains(expected)); + } } } \ No newline at end of file