Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 4485325

Browse files
committed
Declare BodySource a sealed interface
1 parent b36074c commit 4485325

File tree

8 files changed

+22
-12
lines changed

8 files changed

+22
-12
lines changed

http-client/src/main/java/com/proofpoint/http/client/BodySource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package com.proofpoint.http.client;
1717

18-
public interface BodySource
18+
public sealed interface BodySource
19+
permits DynamicBodySource, InputStreamBodySource, StaticBodyGenerator
1920
{
2021
/**
2122
* @return the content length, if known, or -1 if the content length is unknown

http-client/src/main/java/com/proofpoint/http/client/DynamicBodySource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import java.io.OutputStream;
1919

20-
public interface DynamicBodySource extends BodySource
20+
public non-sealed interface DynamicBodySource
21+
extends BodySource
2122
{
2223
/**
2324
* Start writing the request body.

http-client/src/main/java/com/proofpoint/http/client/InputStreamBodySource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import static com.google.common.base.Preconditions.checkState;
2323

24-
public class InputStreamBodySource
24+
public non-sealed class InputStreamBodySource
2525
implements BodySource, LimitedRetryable
2626
{
2727
private final InputStream inputStream;

http-client/src/main/java/com/proofpoint/http/client/StaticBodyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.nio.charset.Charset;
2121

22-
public class StaticBodyGenerator implements BodySource
22+
public non-sealed class StaticBodyGenerator implements BodySource
2323
{
2424
public static StaticBodyGenerator createStaticBodyGenerator(String body, Charset charset)
2525
{

http-client/src/test/java/com/proofpoint/http/client/TestRequest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.common.collect.ListMultimap;
2020
import org.testng.annotations.Test;
2121

22+
import java.io.OutputStream;
2223
import java.net.URI;
2324

2425
import static com.proofpoint.http.client.Request.Builder.prepareGet;
@@ -115,8 +116,13 @@ private static ListMultimap<String, String> createHeadersB()
115116

116117
public static BodySource createBodySource()
117118
{
118-
return new BodySource()
119+
return new DynamicBodySource()
119120
{
121+
@Override
122+
public Writer start(OutputStream out) throws Exception
123+
{
124+
throw new UnsupportedOperationException();
125+
}
120126
};
121127
}
122128
}

http-client/src/test/java/com/proofpoint/http/client/TestRequestBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.common.collect.ImmutableListMultimap;
1919
import org.testng.annotations.Test;
2020

21+
import java.io.OutputStream;
2122
import java.net.URI;
2223

2324
import static com.proofpoint.http.client.Request.Builder.fromRequest;
@@ -30,8 +31,8 @@
3031

3132
public class TestRequestBuilder
3233
{
33-
public static final BodySource NULL_BODY_SOURCE = new BodySource()
34-
{
34+
public static final BodySource NULL_BODY_SOURCE = (DynamicBodySource) out -> {
35+
throw new UnsupportedOperationException();
3536
};
3637

3738
@Test

http-client/src/test/java/com/proofpoint/http/client/balancing/AbstractTestBalancingHttpClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.proofpoint.http.client.balancing;
1717

1818
import com.proofpoint.http.client.BodySource;
19+
import com.proofpoint.http.client.DynamicBodySource;
1920
import com.proofpoint.http.client.HttpClient;
2021
import com.proofpoint.http.client.LimitedRetryable;
2122
import com.proofpoint.http.client.Request;
@@ -108,7 +109,7 @@ protected void setUp()
108109
.setMinBackoff(new Duration(1, TimeUnit.MILLISECONDS))
109110
.setMaxBackoff(new Duration(2, TimeUnit.MILLISECONDS));
110111
balancingHttpClient = createBalancingHttpClient();
111-
bodySource = mock(BodySource.class);
112+
bodySource = mock(DynamicBodySource.class);
112113
request = preparePut().setUri(URI.create("v1/service")).setBodySource(bodySource).build();
113114
requestArgumentCaptor = ArgumentCaptor.forClass(Request.class);
114115
response = mock(Response.class);

http-client/src/test/java/com/proofpoint/http/client/balancing/TestBalancingHttpClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class TestingHttpClient
100100
private String method;
101101
private List<URI> uris = new ArrayList<>();
102102
private List<Object> responses = new ArrayList<>();
103-
private boolean skipBodyGenerator = false;
103+
private boolean skipBodySource = false;
104104

105105
TestingHttpClient(String method)
106106
{
@@ -130,7 +130,7 @@ private TestingHttpClient expectCall(URI uri, Object response)
130130
@Override
131131
public TestingClient firstCallNoBodyGenerator()
132132
{
133-
skipBodyGenerator = true;
133+
skipBodySource = true;
134134
return this;
135135
}
136136

@@ -155,8 +155,8 @@ public <T, E extends Exception> T execute(Request request, ResponseHandler<T, E>
155155
assertEquals(request.getUri(), uris.remove(0), "request uri");
156156
assertEquals(request.getBodySource(), bodySource, "request body generator");
157157

158-
if (skipBodyGenerator) {
159-
skipBodyGenerator = false;
158+
if (skipBodySource) {
159+
skipBodySource = false;
160160
}
161161
else if (bodySource instanceof LimitedRetryable) {
162162
try {

0 commit comments

Comments
 (0)