1717package io .grpc .xds ;
1818
1919import static com .google .common .truth .Truth .assertThat ;
20+ import static org .junit .Assert .assertThrows ;
2021import static org .mockito .Mockito .mock ;
2122
2223import io .grpc .LoadBalancer .PickResult ;
3031import java .util .List ;
3132import org .junit .Rule ;
3233import org .junit .Test ;
33- import org .junit .rules .ExpectedException ;
3434import org .junit .runner .RunWith ;
3535import org .junit .runners .JUnit4 ;
3636import org .mockito .Mock ;
4242 */
4343@ RunWith (JUnit4 .class )
4444public class WeightedRandomPickerTest {
45- @ SuppressWarnings ("deprecation" ) // https://github.com/grpc/grpc-java/issues/7467
46- @ Rule
47- public final ExpectedException thrown = ExpectedException .none ();
4845
4946 @ Rule
5047 public final MockitoRule mockitoRule = MockitoJUnit .rule ();
@@ -128,20 +125,18 @@ public long nextLong(long bound) {
128125 public void emptyList () {
129126 List <WeightedChildPicker > emptyList = new ArrayList <>();
130127
131- thrown .expect (IllegalArgumentException .class );
132- new WeightedRandomPicker (emptyList );
128+ assertThrows (IllegalArgumentException .class , () -> new WeightedRandomPicker (emptyList ));
133129 }
134130
135131 @ Test
136132 public void negativeWeight () {
137- thrown .expect (IllegalArgumentException .class );
138- new WeightedChildPicker (-1 , childPicker0 );
133+ assertThrows (IllegalArgumentException .class , () -> new WeightedChildPicker (-1 , childPicker0 ));
139134 }
140135
141136 @ Test
142137 public void overWeightSingle () {
143- thrown . expect (IllegalArgumentException .class );
144- new WeightedChildPicker (Integer .MAX_VALUE * 3L , childPicker0 );
138+ assertThrows (IllegalArgumentException .class ,
139+ () -> new WeightedChildPicker (Integer .MAX_VALUE * 3L , childPicker0 ) );
145140 }
146141
147142 @ Test
@@ -152,8 +147,8 @@ public void overWeightAggregate() {
152147 new WeightedChildPicker (Integer .MAX_VALUE , childPicker1 ),
153148 new WeightedChildPicker (10 , childPicker2 ));
154149
155- thrown . expect (IllegalArgumentException .class );
156- new WeightedRandomPicker (weightedChildPickers , fakeRandom );
150+ assertThrows (IllegalArgumentException .class ,
151+ () -> new WeightedRandomPicker (weightedChildPickers , fakeRandom ) );
157152 }
158153
159154 @ Test
0 commit comments