From 237e3f8b6886f7ec132403396efd766bf1d77dc2 Mon Sep 17 00:00:00 2001 From: Manfred Riem Date: Thu, 7 Sep 2023 17:16:49 -0500 Subject: [PATCH] Fixes #3532 - Fix SonarCloud issue (#3533) --- .../DefaultWebApplicationOutputStreamTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/impl/src/test/java/cloud/piranha/core/impl/DefaultWebApplicationOutputStreamTest.java b/core/impl/src/test/java/cloud/piranha/core/impl/DefaultWebApplicationOutputStreamTest.java index b95dc8ee3c..cb80e65bf0 100644 --- a/core/impl/src/test/java/cloud/piranha/core/impl/DefaultWebApplicationOutputStreamTest.java +++ b/core/impl/src/test/java/cloud/piranha/core/impl/DefaultWebApplicationOutputStreamTest.java @@ -29,9 +29,11 @@ import jakarta.servlet.ServletOutputStream; import jakarta.servlet.WriteListener; +import static jakarta.servlet.http.HttpServletResponse.SC_SWITCHING_PROTOCOLS; import java.io.IOException; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; /** * The JUnit tests for the DefaultWebApplicationResponse class. @@ -45,17 +47,26 @@ class DefaultWebApplicationOutputStreamTest { * * @throws Exception when a serious error occurs. */ + @Test void testIsReady() throws Exception { DefaultWebApplicationResponse response = new DefaultWebApplicationResponse(); ServletOutputStream outputStream = response.getOutputStream(); - assertFalse(outputStream.isReady()); + assertTrue(outputStream.isReady()); } /** * Test setWriteListener method. */ + @Test void testWriteListener() throws Exception { + DefaultWebApplication webApplication = new DefaultWebApplication(); + DefaultWebApplicationRequest request = new DefaultWebApplicationRequest(); + request.setWebApplication(webApplication); + request.setUpgraded(true); DefaultWebApplicationResponse response = new DefaultWebApplicationResponse(); + response.setStatus(SC_SWITCHING_PROTOCOLS); + webApplication.linkRequestAndResponse(request, response); + response.setWebApplication(webApplication); ServletOutputStream outputStream = response.getOutputStream(); outputStream.setWriteListener(new WriteListener() { @Override