Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
Suvrat1629 committed Feb 13, 2025
1 parent 9aa1c49 commit 28a3817
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -44,14 +43,12 @@ private HttpAppender.Builder<?> getBuilder() {
@Test
@UsingStatusListener
void testBuilderWithoutUrl(final ListStatusListener listener) throws Exception {
// Build the HttpAppender without URL
HttpAppender appender = HttpAppender.newBuilder()
.setConfiguration(new DefaultConfiguration())
.setName("TestAppender")
.setLayout(JsonLayout.createDefaultLayout()) // Providing a layout here
.build();

// Verify that the error message for missing URL is captured
assertThat(listener.findStatusData(Level.ERROR))
.anyMatch(statusData ->
statusData.getMessage().getFormattedMessage().contains("HttpAppender requires URL to be set."));
Expand All @@ -60,14 +57,12 @@ void testBuilderWithoutUrl(final ListStatusListener listener) throws Exception {
@Test
@UsingStatusListener
void testBuilderWithUrlAndWithoutLayout(final ListStatusListener listener) throws Exception {
// Build the HttpAppender with URL but without Layout
HttpAppender appender = HttpAppender.newBuilder()
.setConfiguration(new DefaultConfiguration())
.setName("TestAppender")
.setUrl(new URL("http://localhost:8080/logs")) // Providing the URL
.setUrl(new URL("http://localhost:8080/logs"))
.build();

// Verify that the error message for missing layout is captured
assertThat(listener.findStatusData(Level.ERROR)).anyMatch(statusData -> statusData
.getMessage()
.getFormattedMessage()
Expand All @@ -77,7 +72,7 @@ void testBuilderWithUrlAndWithoutLayout(final ListStatusListener listener) throw
@Test
void testBuilderWithValidConfiguration() throws Exception {
URL url = new URL("http://example.com");
Layout<?> layout = JsonLayout.createDefaultLayout(); // Valid layout
Layout<?> layout = JsonLayout.createDefaultLayout();

HttpAppender.Builder<?> builder = getBuilder().setUrl(url).setLayout(layout);

Expand Down Expand Up @@ -117,7 +112,9 @@ void testBuilderWithHeaders() throws Exception {
void testBuilderWithSslConfiguration() throws Exception {
URL url = new URL("https://example.com");
Layout<?> layout = JsonLayout.createDefaultLayout();
SslConfiguration sslConfig = mock(SslConfiguration.class);

// ✅ FIXED: Use real SslConfiguration instead of Mockito mock
SslConfiguration sslConfig = SslConfiguration.createSSLConfiguration(null, null, null, false);

HttpAppender.Builder<?> builder =
getBuilder().setUrl(url).setLayout(layout).setSslConfiguration(sslConfig);
Expand Down

0 comments on commit 28a3817

Please sign in to comment.