1616
1717package io .grpc ;
1818
19+ import static com .google .common .truth .Truth .assertThat ;
1920import static java .nio .charset .StandardCharsets .US_ASCII ;
2021import static java .nio .charset .StandardCharsets .UTF_8 ;
2122import static org .junit .Assert .assertArrayEquals ;
2425import static org .junit .Assert .assertNotSame ;
2526import static org .junit .Assert .assertNull ;
2627import static org .junit .Assert .assertSame ;
28+ import static org .junit .Assert .assertThrows ;
2729import static org .junit .Assert .assertTrue ;
2830import static org .junit .Assert .fail ;
2931
3739import java .util .Arrays ;
3840import java .util .Iterator ;
3941import java .util .Locale ;
40- import org .junit .Rule ;
4142import org .junit .Test ;
42- import org .junit .rules .ExpectedException ;
4343import org .junit .runner .RunWith ;
4444import org .junit .runners .JUnit4 ;
4545
4949@ RunWith (JUnit4 .class )
5050public class MetadataTest {
5151
52- @ SuppressWarnings ("deprecation" ) // https://github.com/grpc/grpc-java/issues/7467
53- @ Rule public final ExpectedException thrown = ExpectedException .none ();
54-
5552 private static final Metadata .BinaryMarshaller <Fish > FISH_MARSHALLER =
5653 new Metadata .BinaryMarshaller <Fish >() {
5754 @ Override
@@ -65,7 +62,7 @@ public Fish parseBytes(byte[] serialized) {
6562 }
6663 };
6764
68- private static class FishStreamMarsaller implements Metadata .BinaryStreamMarshaller <Fish > {
65+ private static class FishStreamMarshaller implements Metadata .BinaryStreamMarshaller <Fish > {
6966 @ Override
7067 public InputStream toStream (Fish fish ) {
7168 return new ByteArrayInputStream (FISH_MARSHALLER .toBytes (fish ));
@@ -82,7 +79,7 @@ public Fish parseStream(InputStream stream) {
8279 }
8380
8481 private static final Metadata .BinaryStreamMarshaller <Fish > FISH_STREAM_MARSHALLER =
85- new FishStreamMarsaller ();
82+ new FishStreamMarshaller ();
8683
8784 /** A pattern commonly used to avoid unnecessary serialization of immutable objects. */
8885 private static final class FakeFishStream extends InputStream {
@@ -121,10 +118,9 @@ public Fish parseStream(InputStream stream) {
121118
122119 @ Test
123120 public void noPseudoHeaders () {
124- thrown .expect (IllegalArgumentException .class );
125- thrown .expectMessage ("Invalid character" );
126-
127- Metadata .Key .of (":test-bin" , FISH_MARSHALLER );
121+ IllegalArgumentException e = assertThrows (IllegalArgumentException .class ,
122+ () -> Metadata .Key .of (":test-bin" , FISH_MARSHALLER ));
123+ assertThat (e .getMessage ()).contains ("Invalid character" );
128124 }
129125
130126 @ Test
@@ -186,8 +182,7 @@ public void testGetAllNoRemove() {
186182 Iterator <Fish > i = metadata .getAll (KEY ).iterator ();
187183 assertEquals (lance , i .next ());
188184
189- thrown .expect (UnsupportedOperationException .class );
190- i .remove ();
185+ assertThrows (UnsupportedOperationException .class , i ::remove );
191186 }
192187
193188 @ Test
@@ -271,17 +266,14 @@ public void mergeExpands() {
271266
272267 @ Test
273268 public void shortBinaryKeyName () {
274- thrown .expect (IllegalArgumentException .class );
275-
276- Metadata .Key .of ("-bin" , FISH_MARSHALLER );
269+ assertThrows (IllegalArgumentException .class , () -> Metadata .Key .of ("-bin" , FISH_MARSHALLER ));
277270 }
278271
279272 @ Test
280273 public void invalidSuffixBinaryKeyName () {
281- thrown .expect (IllegalArgumentException .class );
282- thrown .expectMessage ("Binary header is named" );
283-
284- Metadata .Key .of ("nonbinary" , FISH_MARSHALLER );
274+ IllegalArgumentException e = assertThrows (IllegalArgumentException .class ,
275+ () -> Metadata .Key .of ("nonbinary" , FISH_MARSHALLER ));
276+ assertThat (e .getMessage ()).contains ("Binary header is named" );
285277 }
286278
287279 @ Test
@@ -415,7 +407,7 @@ public void streamedValueDifferentMarshaller() {
415407 h .put (KEY_STREAMED , salmon );
416408
417409 // Get using a different marshaller instance.
418- Fish fish = h .get (copyKey (KEY_STREAMED , new FishStreamMarsaller ()));
410+ Fish fish = h .get (copyKey (KEY_STREAMED , new FishStreamMarshaller ()));
419411 assertEquals (salmon , fish );
420412 }
421413
0 commit comments