Skip to content

Commit e8b6fba

Browse files
committed
build: fix jooby/src/test/java/io/jooby/internal/handler/ChunkedSubscriberTest.java
1 parent af215c7 commit e8b6fba

1 file changed

Lines changed: 37 additions & 24 deletions

File tree

jooby/src/test/java/io/jooby/internal/handler/ChunkedSubscriberTest.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ void testOnNextExceptionInEncode() throws Exception {
149149
when(ctx.getMethod()).thenReturn("GET");
150150
when(ctx.getRequestPath()).thenReturn("/path");
151151

152-
ChunkedSubscriber sub = new ChunkedSubscriber(ctx);
153-
sub.onSubscribe(subscription);
154-
sub.onNext(item);
152+
// Isolate from global test pollution: force it into the sendError path
153+
try (MockedStatic<Server> serverMock = mockStatic(Server.class)) {
154+
serverMock.when(() -> Server.connectionLost(any(Throwable.class))).thenReturn(false);
155155

156-
verify(subscription).cancel();
157-
verify(ctx).sendError(ex);
156+
ChunkedSubscriber sub = new ChunkedSubscriber(ctx);
157+
sub.onSubscribe(subscription);
158+
sub.onNext(item);
159+
160+
verify(subscription).cancel();
161+
verify(ctx).sendError(ex);
162+
}
158163
}
159164

160165
@Test
@@ -167,19 +172,23 @@ void testOnNextCallbackError() throws Exception {
167172
when(ctx.getMethod()).thenReturn("GET");
168173
when(ctx.getRequestPath()).thenReturn("/path");
169174

170-
ChunkedSubscriber sub = new ChunkedSubscriber(ctx);
171-
sub.onSubscribe(subscription);
172-
sub.onNext(item);
175+
// Isolate from global test pollution
176+
try (MockedStatic<Server> serverMock = mockStatic(Server.class)) {
177+
serverMock.when(() -> Server.connectionLost(any(Throwable.class))).thenReturn(false);
173178

174-
ArgumentCaptor<Sender.Callback> captor = ArgumentCaptor.forClass(Sender.Callback.class);
175-
verify(sender).write(eq(data), captor.capture());
179+
ChunkedSubscriber sub = new ChunkedSubscriber(ctx);
180+
sub.onSubscribe(subscription);
181+
sub.onNext(item);
176182

177-
Exception ex = new Exception("write error");
183+
ArgumentCaptor<Sender.Callback> captor = ArgumentCaptor.forClass(Sender.Callback.class);
184+
verify(sender).write(eq(data), captor.capture());
178185

179-
captor.getValue().onComplete(ctx, ex);
186+
Exception ex = new Exception("write error");
187+
captor.getValue().onComplete(ctx, ex);
180188

181-
verify(subscription).cancel();
182-
verify(ctx).sendError(ex);
189+
verify(subscription).cancel();
190+
verify(ctx).sendError(ex);
191+
}
183192
}
184193

185194
@Test
@@ -273,20 +282,24 @@ void testOnCompleteJsonError() throws Exception {
273282
when(ctx.getMethod()).thenReturn("GET");
274283
when(ctx.getRequestPath()).thenReturn("/path");
275284

276-
ChunkedSubscriber sub = new ChunkedSubscriber(ctx);
277-
sub.onSubscribe(subscription);
278-
sub.onNext(item);
279-
reset(sender);
285+
// Isolate from global test pollution
286+
try (MockedStatic<Server> serverMock = mockStatic(Server.class)) {
287+
serverMock.when(() -> Server.connectionLost(any(Throwable.class))).thenReturn(false);
280288

281-
sub.onComplete();
289+
ChunkedSubscriber sub = new ChunkedSubscriber(ctx);
290+
sub.onSubscribe(subscription);
291+
sub.onNext(item);
292+
reset(sender);
282293

283-
ArgumentCaptor<Sender.Callback> captor = ArgumentCaptor.forClass(Sender.Callback.class);
284-
verify(sender).write(any(byte[].class), captor.capture());
294+
sub.onComplete();
285295

286-
Exception err = new Exception("complete callback error");
296+
ArgumentCaptor<Sender.Callback> captor = ArgumentCaptor.forClass(Sender.Callback.class);
297+
verify(sender).write(any(byte[].class), captor.capture());
287298

288-
captor.getValue().onComplete(ctx, err);
299+
Exception err = new Exception("complete callback error");
300+
captor.getValue().onComplete(ctx, err);
289301

290-
verify(ctx).sendError(err);
302+
verify(ctx).sendError(err);
303+
}
291304
}
292305
}

0 commit comments

Comments
 (0)