Skip to content

Commit 0f0448e

Browse files
committed
formatting
1 parent 46387d8 commit 0f0448e

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderBuilderTest.java

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,33 @@
1616
*/
1717
package org.apache.logging.log4j.core.appender;
1818

19+
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
20+
import static org.junit.jupiter.api.Assertions.*;
21+
import static org.mockito.Mockito.*;
22+
23+
import java.net.MalformedURLException;
24+
import java.net.URL;
1925
import org.apache.logging.log4j.Level;
2026
import org.apache.logging.log4j.core.Layout;
2127
import org.apache.logging.log4j.core.config.Configuration;
2228
import org.apache.logging.log4j.core.config.DefaultConfiguration;
2329
import org.apache.logging.log4j.core.config.Property;
24-
import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
2530
import org.apache.logging.log4j.core.layout.JsonLayout;
31+
import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
2632
import org.apache.logging.log4j.status.StatusLogger;
2733
import org.apache.logging.log4j.test.ListStatusListener;
2834
import org.apache.logging.log4j.test.junit.UsingStatusListener;
2935
import org.junit.jupiter.api.Test;
3036
import org.mockito.Mockito;
3137

32-
import java.net.MalformedURLException;
33-
import java.net.URL;
34-
35-
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
36-
import static org.junit.jupiter.api.Assertions.*;
37-
import static org.mockito.Mockito.*;
38-
3938
class HttpAppenderBuilderTest {
4039

4140
// Mock the LOGGER to verify error logs
4241
private final StatusLogger mockStatusLogger = Mockito.mock(StatusLogger.class);
4342

4443
private HttpAppender.Builder<?> getBuilder() {
4544
Configuration mockConfig = new DefaultConfiguration();
46-
return HttpAppender.newBuilder()
47-
.setConfiguration(mockConfig)
48-
.setName("TestHttpAppender"); // Name is required
45+
return HttpAppender.newBuilder().setConfiguration(mockConfig).setName("TestHttpAppender"); // Name is required
4946
}
5047

5148
@Test
@@ -55,12 +52,13 @@ void testBuilderWithoutUrl(final ListStatusListener listener) throws Exception {
5552
HttpAppender appender = HttpAppender.newBuilder()
5653
.setConfiguration(new DefaultConfiguration())
5754
.setName("TestAppender")
58-
.setLayout(JsonLayout.createDefaultLayout()) // Providing a layout here
55+
.setLayout(JsonLayout.createDefaultLayout()) // Providing a layout here
5956
.build();
6057

6158
// Verify that the error message for missing URL is captured
6259
assertThat(listener.findStatusData(Level.ERROR))
63-
.anyMatch(statusData -> statusData.getMessage().getFormattedMessage().contains("HttpAppender requires URL to be set."));
60+
.anyMatch(statusData ->
61+
statusData.getMessage().getFormattedMessage().contains("HttpAppender requires URL to be set."));
6462
}
6563

6664
@Test
@@ -70,23 +68,22 @@ void testBuilderWithUrlAndWithoutLayout(final ListStatusListener listener) throw
7068
HttpAppender appender = HttpAppender.newBuilder()
7169
.setConfiguration(new DefaultConfiguration())
7270
.setName("TestAppender")
73-
.setUrl(new URL("http://localhost:8080/logs")) // Providing the URL
71+
.setUrl(new URL("http://localhost:8080/logs")) // Providing the URL
7472
.build();
7573

7674
// Verify that the error message for missing layout is captured
77-
assertThat(listener.findStatusData(Level.ERROR))
78-
.anyMatch(statusData -> statusData.getMessage().getFormattedMessage().contains("HttpAppender requires a layout to be set."));
75+
assertThat(listener.findStatusData(Level.ERROR)).anyMatch(statusData -> statusData
76+
.getMessage()
77+
.getFormattedMessage()
78+
.contains("HttpAppender requires a layout to be set."));
7979
}
8080

81-
8281
@Test
8382
void testBuilderWithValidConfiguration() throws Exception {
8483
URL url = new URL("http://example.com");
8584
Layout<?> layout = JsonLayout.createDefaultLayout(); // Valid layout
8685

87-
HttpAppender.Builder<?> builder = getBuilder()
88-
.setUrl(url)
89-
.setLayout(layout);
86+
HttpAppender.Builder<?> builder = getBuilder().setUrl(url).setLayout(layout);
9087

9188
HttpAppender appender = builder.build();
9289
assertNotNull(appender, "HttpAppender should be created with valid configuration.");
@@ -98,10 +95,8 @@ void testBuilderWithCustomMethod() throws Exception {
9895
Layout<?> layout = JsonLayout.createDefaultLayout();
9996
String customMethod = "PUT";
10097

101-
HttpAppender.Builder<?> builder = getBuilder()
102-
.setUrl(url)
103-
.setLayout(layout)
104-
.setMethod(customMethod);
98+
HttpAppender.Builder<?> builder =
99+
getBuilder().setUrl(url).setLayout(layout).setMethod(customMethod);
105100

106101
HttpAppender appender = builder.build();
107102
assertNotNull(appender, "HttpAppender should be created with a custom HTTP method.");
@@ -111,15 +106,12 @@ void testBuilderWithCustomMethod() throws Exception {
111106
void testBuilderWithHeaders() throws Exception {
112107
URL url = new URL("http://example.com");
113108
Layout<?> layout = JsonLayout.createDefaultLayout();
114-
Property[] headers = new Property[]{
115-
Property.createProperty("Header1", "Value1"),
116-
Property.createProperty("Header2", "Value2")
109+
Property[] headers = new Property[] {
110+
Property.createProperty("Header1", "Value1"), Property.createProperty("Header2", "Value2")
117111
};
118112

119-
HttpAppender.Builder<?> builder = getBuilder()
120-
.setUrl(url)
121-
.setLayout(layout)
122-
.setHeaders(headers);
113+
HttpAppender.Builder<?> builder =
114+
getBuilder().setUrl(url).setLayout(layout).setHeaders(headers);
123115

124116
HttpAppender appender = builder.build();
125117
assertNotNull(appender, "HttpAppender should be created with headers.");
@@ -131,10 +123,8 @@ void testBuilderWithSslConfiguration() throws Exception {
131123
Layout<?> layout = JsonLayout.createDefaultLayout();
132124
SslConfiguration sslConfig = mock(SslConfiguration.class);
133125

134-
HttpAppender.Builder<?> builder = getBuilder()
135-
.setUrl(url)
136-
.setLayout(layout)
137-
.setSslConfiguration(sslConfig);
126+
HttpAppender.Builder<?> builder =
127+
getBuilder().setUrl(url).setLayout(layout).setSslConfiguration(sslConfig);
138128

139129
HttpAppender appender = builder.build();
140130
assertNotNull(appender, "HttpAppender should be created with SSL configuration.");
@@ -144,4 +134,4 @@ void testBuilderWithSslConfiguration() throws Exception {
144134
void testBuilderWithInvalidUrl() {
145135
assertThrows(MalformedURLException.class, () -> new URL("invalid-url"));
146136
}
147-
}
137+
}

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,4 @@ public boolean stop(final long timeout, final TimeUnit timeUnit) {
209209
public String toString() {
210210
return "HttpAppender{" + "name=" + getName() + ", state=" + getState() + '}';
211211
}
212-
}
212+
}

0 commit comments

Comments
 (0)