1818
1919import static org .junit .Assert .assertEquals ;
2020import static org .junit .Assert .assertNull ;
21+ import static org .junit .Assert .assertThrows ;
2122import static org .junit .Assert .assertTrue ;
2223import static org .mockito .AdditionalAnswers .delegatesTo ;
2324import static org .mockito .ArgumentMatchers .any ;
4546import java .util .Queue ;
4647import java .util .concurrent .TimeUnit ;
4748import org .junit .Before ;
48- import org .junit .Rule ;
4949import org .junit .Test ;
50- import org .junit .rules .ExpectedException ;
5150import org .junit .runner .RunWith ;
5251import org .junit .runners .JUnit4 ;
5352import org .mockito .ArgumentCaptor ;
@@ -60,9 +59,6 @@ public class AbstractServerStreamTest {
6059 private static final int TIMEOUT_MS = 1000 ;
6160 private static final int MAX_MESSAGE_SIZE = 100 ;
6261
63- @ SuppressWarnings ("deprecation" ) // https://github.com/grpc/grpc-java/issues/7467
64- @ Rule public final ExpectedException thrown = ExpectedException .none ();
65-
6662 private final WritableBufferAllocator allocator = new WritableBufferAllocator () {
6763 @ Override
6864 public WritableBuffer allocate (int capacityHint ) {
@@ -226,9 +222,9 @@ public void completeWithoutClose() {
226222 public void setListener_setOnlyOnce () {
227223 TransportState state = stream .transportState ();
228224 state .setListener (new ServerStreamListenerBase ());
229- thrown .expect (IllegalStateException .class );
230225
231- state .setListener (new ServerStreamListenerBase ());
226+ ServerStreamListenerBase listener2 = new ServerStreamListenerBase ();
227+ assertThrows (IllegalStateException .class , () -> state .setListener (listener2 ));
232228 }
233229
234230 @ Test
@@ -238,8 +234,7 @@ public void listenerReady_onlyOnce() {
238234
239235 TransportState state = stream .transportState ();
240236
241- thrown .expect (IllegalStateException .class );
242- state .onStreamAllocated ();
237+ assertThrows (IllegalStateException .class , state ::onStreamAllocated );
243238 }
244239
245240 @ Test
@@ -255,8 +250,7 @@ public void listenerReady_readyCalled() {
255250 public void setListener_failsOnNull () {
256251 TransportState state = stream .transportState ();
257252
258- thrown .expect (NullPointerException .class );
259- state .setListener (null );
253+ assertThrows (NullPointerException .class , () -> state .setListener (null ));
260254 }
261255
262256 // TODO(ericgribkoff) This test is only valid if deframeInTransportThread=true, as otherwise the
@@ -284,9 +278,7 @@ public void messagesAvailable(MessageProducer producer) {
284278
285279 @ Test
286280 public void writeHeaders_failsOnNullHeaders () {
287- thrown .expect (NullPointerException .class );
288-
289- stream .writeHeaders (null , true );
281+ assertThrows (NullPointerException .class , () -> stream .writeHeaders (null , true ));
290282 }
291283
292284 @ Test
@@ -336,16 +328,13 @@ public void writeMessage_closesStream() throws Exception {
336328
337329 @ Test
338330 public void close_failsOnNullStatus () {
339- thrown .expect (NullPointerException .class );
340-
341- stream .close (null , new Metadata ());
331+ Metadata trailers = new Metadata ();
332+ assertThrows (NullPointerException .class , () -> stream .close (null , trailers ));
342333 }
343334
344335 @ Test
345336 public void close_failsOnNullMetadata () {
346- thrown .expect (NullPointerException .class );
347-
348- stream .close (Status .INTERNAL , null );
337+ assertThrows (NullPointerException .class , () -> stream .close (Status .INTERNAL , null ));
349338 }
350339
351340 @ Test
@@ -451,4 +440,3 @@ public int streamId() {
451440 }
452441 }
453442}
454-
0 commit comments