1616
1717package io .grpc ;
1818
19+ import static com .google .common .truth .Truth .assertThat ;
20+ import static org .junit .Assert .assertThrows ;
1921import static org .junit .Assert .assertTrue ;
2022
23+ import com .google .common .truth .StringSubject ;
2124import io .grpc .MethodDescriptor .MethodType ;
2225import io .grpc .testing .TestMethodDescriptors ;
2326import java .util .Arrays ;
2427import java .util .Collection ;
2528import java .util .Collections ;
2629import java .util .List ;
27- import org .junit .Rule ;
2830import org .junit .Test ;
29- import org .junit .rules .ExpectedException ;
3031import org .junit .runner .RunWith ;
3132import org .junit .runners .JUnit4 ;
3233
3637@ RunWith (JUnit4 .class )
3738public class ServiceDescriptorTest {
3839
39- @ SuppressWarnings ("deprecation" ) // https://github.com/grpc/grpc-java/issues/7467
40- @ Rule
41- public final ExpectedException thrown = ExpectedException .none ();
42-
4340 @ Test
4441 public void failsOnNullName () {
45- thrown . expect ( NullPointerException . class );
46- thrown . expectMessage ( "name" );
47-
48- new ServiceDescriptor ( null , Collections .< MethodDescriptor <?, ?>> emptyList () );
42+ List < MethodDescriptor <?, ?>> methods = Collections . emptyList ( );
43+ NullPointerException e = assertThrows ( NullPointerException . class ,
44+ () -> new ServiceDescriptor ( null , methods ));
45+ assertThat ( e ). hasMessageThat (). isEqualTo ( "name" );
4946 }
5047
5148 @ Test
5249 public void failsOnNullMethods () {
53- thrown .expect (NullPointerException .class );
54- thrown .expectMessage ("methods" );
55-
56- new ServiceDescriptor ("name" , (Collection <MethodDescriptor <?, ?>>) null );
50+ NullPointerException e = assertThrows (NullPointerException .class ,
51+ () -> new ServiceDescriptor ("name" , (Collection <MethodDescriptor <?, ?>>) null ));
52+ assertThat (e ).hasMessageThat ().isEqualTo ("methods" );
5753 }
5854
5955 @ Test
6056 public void failsOnNullMethod () {
61- thrown . expect ( NullPointerException . class );
62- thrown . expectMessage ( "method" );
63-
64- new ServiceDescriptor ( "name" , Collections .< MethodDescriptor <?, ?>> singletonList ( null ) );
57+ List < MethodDescriptor <?, ?>> methods = Collections . singletonList ( null );
58+ NullPointerException e = assertThrows ( NullPointerException . class ,
59+ () -> new ServiceDescriptor ( "name" , methods ));
60+ assertThat ( e ). hasMessageThat (). isEqualTo ( "method" );
6561 }
6662
6763 @ Test
6864 public void failsOnNonMatchingNames () {
6965 List <MethodDescriptor <?, ?>> descriptors = Collections .<MethodDescriptor <?, ?>>singletonList (
7066 MethodDescriptor .<Void , Void >newBuilder ()
7167 .setType (MethodType .UNARY )
72- .setFullMethodName (MethodDescriptor .generateFullMethodName ("wrongservice " , "method" ))
68+ .setFullMethodName (MethodDescriptor .generateFullMethodName ("wrongService " , "method" ))
7369 .setRequestMarshaller (TestMethodDescriptors .voidMarshaller ())
7470 .setResponseMarshaller (TestMethodDescriptors .voidMarshaller ())
7571 .build ());
7672
77- thrown .expect (IllegalArgumentException .class );
78- thrown .expectMessage ("service names" );
79-
80- new ServiceDescriptor ("name" , descriptors );
73+ IllegalArgumentException e = assertThrows (IllegalArgumentException .class ,
74+ () -> new ServiceDescriptor ("fooService" , descriptors ));
75+ StringSubject error = assertThat (e ).hasMessageThat ();
76+ error .contains ("service names" );
77+ error .contains ("fooService" );
78+ error .contains ("wrongService" );
8179 }
8280
8381 @ Test
@@ -96,10 +94,9 @@ public void failsOnNonDuplicateNames() {
9694 .setResponseMarshaller (TestMethodDescriptors .voidMarshaller ())
9795 .build ());
9896
99- thrown .expect (IllegalArgumentException .class );
100- thrown .expectMessage ("duplicate" );
101-
102- new ServiceDescriptor ("name" , descriptors );
97+ IllegalArgumentException e = assertThrows (IllegalArgumentException .class ,
98+ () -> new ServiceDescriptor ("name" , descriptors ));
99+ assertThat (e ).hasMessageThat ().isEqualTo ("duplicate name name/method" );
103100 }
104101
105102 @ Test
0 commit comments