Skip to content

Commit e9f3639

Browse files
committed
bug: privatize StreamState
1 parent 873abee commit e9f3639

4 files changed

Lines changed: 14 additions & 32 deletions

File tree

slack-api-client/src/main/java/com/slack/api/methods/AsyncChatStreamHelper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@Builder
2929
public class AsyncChatStreamHelper {
3030

31-
public enum State {
31+
private enum StreamState {
3232
STARTING,
3333
IN_PROGRESS,
3434
COMPLETED
@@ -46,7 +46,7 @@ public enum State {
4646
@Builder.Default
4747
private StringBuilder buffer = new StringBuilder();
4848
@Builder.Default
49-
private State state = State.STARTING;
49+
private StreamState state = StreamState.STARTING;
5050
private String streamTs;
5151

5252
/**
@@ -56,7 +56,7 @@ public enum State {
5656
* @return a future that completes with a response if the buffer was flushed; completes with null if buffering
5757
*/
5858
public CompletableFuture<ChatAppendStreamResponse> append(String markdownText) {
59-
if (state == State.COMPLETED) {
59+
if (state == StreamState.COMPLETED) {
6060
CompletableFuture<ChatAppendStreamResponse> f = new CompletableFuture<>();
6161
f.completeExceptionally(new SlackChatStreamException("Cannot append to stream: stream state is " + state));
6262
return f;
@@ -89,7 +89,7 @@ public CompletableFuture<ChatStopStreamResponse> stop(
8989
List<LayoutBlock> blocks,
9090
Message.Metadata metadata
9191
) {
92-
if (state == State.COMPLETED) {
92+
if (state == StreamState.COMPLETED) {
9393
CompletableFuture<ChatStopStreamResponse> f = new CompletableFuture<>();
9494
f.completeExceptionally(new SlackChatStreamException("Cannot stop stream: stream state is " + state));
9595
return f;
@@ -115,7 +115,7 @@ public CompletableFuture<ChatStopStreamResponse> stop(
115115
throw ex;
116116
}
117117
streamTs = startResponse.getTs();
118-
state = State.IN_PROGRESS;
118+
state = StreamState.IN_PROGRESS;
119119
return null;
120120
});
121121
} else {
@@ -130,7 +130,7 @@ public CompletableFuture<ChatStopStreamResponse> stop(
130130
.metadata(metadata)
131131
.build())
132132
.thenApply(resp -> {
133-
state = State.COMPLETED;
133+
state = StreamState.COMPLETED;
134134
return resp;
135135
}));
136136
}
@@ -152,7 +152,7 @@ private CompletableFuture<ChatAppendStreamResponse> flushBuffer() {
152152
throw ex;
153153
}
154154
streamTs = startResponse.getTs();
155-
state = State.IN_PROGRESS;
155+
state = StreamState.IN_PROGRESS;
156156
ChatAppendStreamResponse synth = new ChatAppendStreamResponse();
157157
synth.setOk(startResponse.isOk());
158158
synth.setChannel(startResponse.getChannel());

slack-api-client/src/main/java/com/slack/api/methods/ChatStreamHelper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class ChatStreamHelper {
4747
/**
4848
* The state of the chat stream.
4949
*/
50-
public enum State {
50+
private enum StreamState {
5151
STARTING,
5252
IN_PROGRESS,
5353
COMPLETED
@@ -72,7 +72,7 @@ public enum State {
7272
@Builder.Default
7373
private StringBuilder buffer = new StringBuilder();
7474
@Builder.Default
75-
private State state = State.STARTING;
75+
private StreamState state = StreamState.STARTING;
7676
private String streamTs;
7777

7878
/**
@@ -88,7 +88,7 @@ public enum State {
8888
* @throws SlackApiException if a Slack API error occurs
8989
*/
9090
public ChatAppendStreamResponse append(String markdownText) throws IOException, SlackApiException {
91-
if (state == State.COMPLETED) {
91+
if (state == StreamState.COMPLETED) {
9292
throw new SlackChatStreamException("Cannot append to stream: stream state is " + state);
9393
}
9494

@@ -148,7 +148,7 @@ public ChatStopStreamResponse stop(
148148
List<LayoutBlock> blocks,
149149
Message.Metadata metadata
150150
) throws IOException, SlackApiException {
151-
if (state == State.COMPLETED) {
151+
if (state == StreamState.COMPLETED) {
152152
throw new SlackChatStreamException("Cannot stop stream: stream state is " + state);
153153
}
154154

@@ -173,7 +173,7 @@ public ChatStopStreamResponse stop(
173173
}
174174

175175
streamTs = startResponse.getTs();
176-
state = State.IN_PROGRESS;
176+
state = StreamState.IN_PROGRESS;
177177
}
178178

179179
ChatStopStreamResponse response = client.chatStopStream(ChatStopStreamRequest.builder()
@@ -184,7 +184,7 @@ public ChatStopStreamResponse stop(
184184
.metadata(metadata)
185185
.build());
186186

187-
state = State.COMPLETED;
187+
state = StreamState.COMPLETED;
188188
return response;
189189
}
190190

@@ -216,7 +216,7 @@ private ChatAppendStreamResponse flushBuffer() throws IOException, SlackApiExcep
216216
}
217217

218218
streamTs = startResponse.getTs();
219-
state = State.IN_PROGRESS;
219+
state = StreamState.IN_PROGRESS;
220220

221221
// Create a response object to return (mimicking the append response structure)
222222
response = new ChatAppendStreamResponse();

slack-api-client/src/test/java/test_locally/api/methods/AsyncChatStreamHelperTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public void append_buffers_when_under_bufferSize() throws Exception {
4949

5050
ChatAppendStreamResponse resp = stream.append("hello").get();
5151
assertThat(resp, is(nullValue()));
52-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.STARTING));
5352
assertThat(stream.getStreamTs(), is(nullValue()));
5453
assertThat(stream.getBuffer().toString(), is("hello"));
5554
}
@@ -63,7 +62,6 @@ public void append_flushes_and_starts_stream_on_first_flush() throws Exception {
6362

6463
ChatAppendStreamResponse resp = stream.append("hey").get(); // triggers flush
6564
assertThat(resp.isOk(), is(true));
66-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.IN_PROGRESS));
6765
assertThat(stream.getStreamTs(), is("0000000000.000000"));
6866
assertThat(stream.getBuffer().toString(), is(""));
6967
}
@@ -78,7 +76,6 @@ public void stop_completes() throws Exception {
7876
stream.append("hello").get(); // buffered only
7977
ChatStopStreamResponse stop = stream.stop().get();
8078
assertThat(stop.isOk(), is(true));
81-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.COMPLETED));
8279
assertThat(stream.getStreamTs(), is("0000000000.000000"));
8380
}
8481

@@ -124,7 +121,6 @@ public void stop_with_additional_markdown_text() throws Exception {
124121
stream.append("hello ").get();
125122
ChatStopStreamResponse stop = stream.stop("world!").get();
126123
assertThat(stop.isOk(), is(true));
127-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.COMPLETED));
128124
assertThat(stream.getBuffer().toString(), is("hello world!"));
129125
}
130126

@@ -145,7 +141,6 @@ public void stop_with_blocks_and_metadata() throws Exception {
145141
metadata
146142
).get();
147143
assertThat(stop.isOk(), is(true));
148-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.COMPLETED));
149144
}
150145

151146
@Test
@@ -158,13 +153,11 @@ public void stop_after_stream_already_started() throws Exception {
158153
// Start the stream via append
159154
ChatAppendStreamResponse appendResp = stream.append("a").get();
160155
assertThat(appendResp.isOk(), is(true));
161-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.IN_PROGRESS));
162156
assertThat(stream.getStreamTs(), is(notNullValue()));
163157

164158
// Now stop - should not call startStream again
165159
ChatStopStreamResponse stop = stream.stop().get();
166160
assertThat(stop.isOk(), is(true));
167-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.COMPLETED));
168161
}
169162

170163
@Test
@@ -186,7 +179,6 @@ public void multiple_appends_accumulate_in_buffer() throws Exception {
186179
stream.append("world").get();
187180

188181
assertThat(stream.getBuffer().toString(), is("hello world"));
189-
assertThat(stream.getState(), is(AsyncChatStreamHelper.State.STARTING));
190182
}
191183
}
192184

slack-api-client/src/test/java/test_locally/api/methods/ChatStreamHelperTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public void append_buffers_when_under_bufferSize() throws Exception {
4848

4949
ChatAppendStreamResponse resp = stream.append("hello");
5050
assertThat(resp, is(nullValue()));
51-
assertThat(stream.getState(), is(ChatStreamHelper.State.STARTING));
5251
assertThat(stream.getStreamTs(), is(nullValue()));
5352
assertThat(stream.getBuffer().toString(), is("hello"));
5453
}
@@ -62,7 +61,6 @@ public void append_flushes_and_starts_stream_on_first_flush() throws Exception {
6261

6362
ChatAppendStreamResponse resp = stream.append("hey"); // triggers flush
6463
assertThat(resp.isOk(), is(true));
65-
assertThat(stream.getState(), is(ChatStreamHelper.State.IN_PROGRESS));
6664
assertThat(stream.getStreamTs(), is("0000000000.000000"));
6765
assertThat(stream.getBuffer().toString(), is(""));
6866
}
@@ -78,13 +76,11 @@ public void append_flushes_with_appendStream_after_started() throws Exception {
7876
ChatAppendStreamResponse first = stream.append("a");
7977
assertThat(first.isOk(), is(true));
8078
assertThat(stream.getStreamTs(), is("0000000000.000000"));
81-
assertThat(stream.getState(), is(ChatStreamHelper.State.IN_PROGRESS));
8279

8380
// second flush uses chat.appendStream
8481
ChatAppendStreamResponse second = stream.append("b");
8582
assertThat(second.isOk(), is(true));
8683
assertThat(stream.getStreamTs(), is("0000000000.000000"));
87-
assertThat(stream.getState(), is(ChatStreamHelper.State.IN_PROGRESS));
8884
}
8985

9086
@Test
@@ -97,7 +93,6 @@ public void stop_starts_stream_if_needed_and_completes() throws Exception {
9793
stream.append("hello"); // buffered only
9894
ChatStopStreamResponse stop = stream.stop();
9995
assertThat(stop.isOk(), is(true));
100-
assertThat(stream.getState(), is(ChatStreamHelper.State.COMPLETED));
10196
assertThat(stream.getStreamTs(), is("0000000000.000000"));
10297
}
10398

@@ -133,7 +128,6 @@ public void stop_with_additional_markdown_text() throws Exception {
133128
stream.append("hello ");
134129
ChatStopStreamResponse stop = stream.stop("world!");
135130
assertThat(stop.isOk(), is(true));
136-
assertThat(stream.getState(), is(ChatStreamHelper.State.COMPLETED));
137131
assertThat(stream.getBuffer().toString(), is("hello world!"));
138132
}
139133

@@ -154,7 +148,6 @@ public void stop_with_blocks_and_metadata() throws Exception {
154148
metadata
155149
);
156150
assertThat(stop.isOk(), is(true));
157-
assertThat(stream.getState(), is(ChatStreamHelper.State.COMPLETED));
158151
}
159152

160153
@Test
@@ -167,13 +160,11 @@ public void stop_after_stream_already_started() throws Exception {
167160
// Start the stream via append
168161
ChatAppendStreamResponse appendResp = stream.append("a");
169162
assertThat(appendResp.isOk(), is(true));
170-
assertThat(stream.getState(), is(ChatStreamHelper.State.IN_PROGRESS));
171163
assertThat(stream.getStreamTs(), is(notNullValue()));
172164

173165
// Now stop - should not call startStream again
174166
ChatStopStreamResponse stop = stream.stop();
175167
assertThat(stop.isOk(), is(true));
176-
assertThat(stream.getState(), is(ChatStreamHelper.State.COMPLETED));
177168
}
178169

179170
@Test
@@ -195,7 +186,6 @@ public void multiple_appends_accumulate_in_buffer() throws Exception {
195186
stream.append("world");
196187

197188
assertThat(stream.getBuffer().toString(), is("hello world"));
198-
assertThat(stream.getState(), is(ChatStreamHelper.State.STARTING));
199189
}
200190
}
201191

0 commit comments

Comments
 (0)