Skip to content

Commit 4c1bab9

Browse files
committed
Prepare for JUnit 4.13
It deprecates ExpectedException and Assert.assertThat(T, org.hamcrest.Matcher). Without Java 8 we don't want to migrate away from ExpectedException at this time. We tend to prefer Truth over Hamcrest, so I swapped the one instance of Assert.assertThat() to use Truth. With this change we get a warning-less build with JUnit 4.13. We don't yet upgrade because we still need to support JUnit 4.12 for some use-cases, but will be able to upgrade to 4.13 soon when they upgrade.
1 parent 2adeff5 commit 4c1bab9

34 files changed

+37
-5
lines changed

api/src/test/java/io/grpc/ContextsTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
package io.grpc;
1818

19+
import static com.google.common.truth.Truth.assertThat;
1920
import static io.grpc.Contexts.interceptCall;
2021
import static io.grpc.Contexts.statusFromCancelled;
21-
import static org.hamcrest.core.IsInstanceOf.instanceOf;
2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertFalse;
2424
import static org.junit.Assert.assertNotNull;
2525
import static org.junit.Assert.assertNull;
2626
import static org.junit.Assert.assertSame;
27-
import static org.junit.Assert.assertThat;
2827
import static org.junit.Assert.assertTrue;
2928
import static org.junit.Assert.fail;
3029

@@ -240,7 +239,7 @@ class MockScheduledExecutorService extends ForwardingScheduledExecutorService {
240239
executorService.command.run();
241240

242241
assertTrue(cancellableContext.isCancelled());
243-
assertThat(cancellableContext.cancellationCause(), instanceOf(TimeoutException.class));
242+
assertThat(cancellableContext.cancellationCause()).isInstanceOf(TimeoutException.class);
244243

245244
Status status = statusFromCancelled(cancellableContext);
246245
assertNotNull(status);

api/src/test/java/io/grpc/MetadataTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
@RunWith(JUnit4.class)
5050
public class MetadataTest {
5151

52+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5253
@Rule public final ExpectedException thrown = ExpectedException.none();
5354

5455
private static final Metadata.BinaryMarshaller<Fish> FISH_MARSHALLER =

api/src/test/java/io/grpc/MethodDescriptorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
@RunWith(JUnit4.class)
3939
public class MethodDescriptorTest {
40+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4041
@Rule
4142
public final ExpectedException thrown = ExpectedException.none();
4243

api/src/test/java/io/grpc/ServerInterceptorsTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class ServerInterceptorsTest {
5656
@Rule
5757
public final MockitoRule mocks = MockitoJUnit.rule();
5858

59+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5960
@Rule
6061
public final ExpectedException thrown = ExpectedException.none();
6162

api/src/test/java/io/grpc/ServerServiceDefinitionTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class ServerServiceDefinitionTest {
5252
= ServerMethodDefinition.create(method1, methodHandler1);
5353
private ServerMethodDefinition<String, Integer> methodDef2
5454
= ServerMethodDefinition.create(method2, methodHandler2);
55+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5556
@Rule
5657
public ExpectedException thrown = ExpectedException.none();
5758

api/src/test/java/io/grpc/ServiceDescriptorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@RunWith(JUnit4.class)
3737
public class ServiceDescriptorTest {
3838

39+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
3940
@Rule
4041
public final ExpectedException thrown = ExpectedException.none();
4142

core/src/test/java/io/grpc/internal/AbstractClientStreamTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
public class AbstractClientStreamTest {
7676

7777
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
78+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
7879
@Rule public final ExpectedException thrown = ExpectedException.none();
7980

8081
private final StatsTraceContext statsTraceCtx = StatsTraceContext.NOOP;

core/src/test/java/io/grpc/internal/AbstractServerStreamTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class AbstractServerStreamTest {
5757
private static final int TIMEOUT_MS = 1000;
5858
private static final int MAX_MESSAGE_SIZE = 100;
5959

60+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
6061
@Rule public final ExpectedException thrown = ExpectedException.none();
6162

6263
private final WritableBufferAllocator allocator = new WritableBufferAllocator() {

core/src/test/java/io/grpc/internal/AbstractTransportTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata
224224
}
225225
}));
226226

227+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
227228
@Rule
228229
public ExpectedException thrown = ExpectedException.none();
229230

core/src/test/java/io/grpc/internal/ConnectivityStateManagerTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
@RunWith(JUnit4.class)
4040
public class ConnectivityStateManagerTest {
41+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4142
@Rule
4243
public final ExpectedException thrown = ExpectedException.none();
4344

core/src/test/java/io/grpc/internal/DnsNameResolverTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class DnsNameResolverTest {
9898

9999
@Rule public final TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(10));
100100
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
101+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
101102
@Rule public final ExpectedException thrown = ExpectedException.none();
102103

103104
private final Map<String, ?> serviceConfig = new LinkedHashMap<>();

core/src/test/java/io/grpc/internal/GrpcUtilTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
@RunWith(JUnit4.class)
4545
public class GrpcUtilTest {
4646

47+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4748
@Rule public final ExpectedException thrown = ExpectedException.none();
4849

4950
@Test

core/src/test/java/io/grpc/internal/InternalSubchannelTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
public class InternalSubchannelTest {
7878
@Rule
7979
public final MockitoRule mocks = MockitoJUnit.rule();
80+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
8081
@Rule
8182
public final ExpectedException thrown = ExpectedException.none();
8283

core/src/test/java/io/grpc/internal/JsonParserTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@RunWith(JUnit4.class)
3636
public class JsonParserTest {
3737

38+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
3839
@Rule
3940
public final ExpectedException thrown = ExpectedException.none();
4041

@@ -122,4 +123,4 @@ public void objectStringName() throws IOException {
122123

123124
assertEquals(expected, JsonParser.parse("{\"hi\": 2}"));
124125
}
125-
}
126+
}

core/src/test/java/io/grpc/internal/ManagedChannelImplBuilderTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
8080
};
8181

8282
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
83+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
8384
@Rule public final ExpectedException thrown = ExpectedException.none();
8485
@Rule public final GrpcCleanupRule grpcCleanupRule = new GrpcCleanupRule();
8586

core/src/test/java/io/grpc/internal/ManagedChannelServiceConfigTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
@RunWith(JUnit4.class)
4242
public class ManagedChannelServiceConfigTest {
4343

44+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4445
@Rule
4546
public final ExpectedException thrown = ExpectedException.none();
4647

@@ -224,4 +225,4 @@ public void getDefaultConfigSelectorFromConfig() {
224225
private static Map<String, Object> parseConfig(String json) throws Exception {
225226
return (Map<String, Object>) JsonParser.parse(json);
226227
}
227-
}
228+
}

core/src/test/java/io/grpc/internal/MessageDeframerTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
337337

338338
@RunWith(JUnit4.class)
339339
public static class SizeEnforcingInputStreamTests {
340+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
340341
@Rule
341342
public final ExpectedException thrown = ExpectedException.none();
342343

core/src/test/java/io/grpc/internal/ServerCallImplTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
@RunWith(JUnit4.class)
6161
public class ServerCallImplTest {
62+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
6263
@Rule public final ExpectedException thrown = ExpectedException.none();
6364
@Mock private ServerStream stream;
6465
@Mock private ServerCall.Listener<Long> callListener;

core/src/test/java/io/grpc/internal/ServerImplTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public boolean shouldAccept(Runnable runnable) {
139139
};
140140
private static final String AUTHORITY = "some_authority";
141141

142+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
142143
@Rule public final ExpectedException thrown = ExpectedException.none();
143144

144145
@BeforeClass

core/src/test/java/io/grpc/util/GracefulSwitchLoadBalancerTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
*/
6363
@RunWith(JUnit4.class)
6464
public class GracefulSwitchLoadBalancerTest {
65+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
6566
@Rule
6667
public final ExpectedException thrown = ExpectedException.none();
6768

netty/src/test/java/io/grpc/netty/NettyChannelBuilderTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
@RunWith(JUnit4.class)
4242
public class NettyChannelBuilderTest {
4343

44+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4445
@Rule public final ExpectedException thrown = ExpectedException.none();
4546
private final SslContext noSslContext = null;
4647

netty/src/test/java/io/grpc/netty/NettyServerBuilderTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
@RunWith(JUnit4.class)
4141
public class NettyServerBuilderTest {
4242

43+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4344
@Rule public final ExpectedException thrown = ExpectedException.none();
4445

4546
private NettyServerBuilder builder = NettyServerBuilder.forPort(8080);

netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class ProtocolNegotiatorsTest {
122122

123123
private static final int TIMEOUT_SECONDS = 60;
124124
@Rule public final TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(TIMEOUT_SECONDS));
125+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
125126
@Rule public final ExpectedException thrown = ExpectedException.none();
126127

127128
private final EventLoopGroup group = new DefaultEventLoop();

okhttp/src/test/java/io/grpc/okhttp/OkHttpChannelBuilderTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
@RunWith(JUnit4.class)
4848
public class OkHttpChannelBuilderTest {
4949

50+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5051
@Rule public final ExpectedException thrown = ExpectedException.none();
5152
@Rule public final GrpcCleanupRule grpcCleanupRule = new GrpcCleanupRule();
5253

okhttp/src/test/java/io/grpc/okhttp/OkHttpProtocolNegotiatorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
*/
5050
@RunWith(JUnit4.class)
5151
public class OkHttpProtocolNegotiatorTest {
52+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5253
@Rule public final ExpectedException thrown = ExpectedException.none();
5354

5455
private final SSLSocket sock = mock(SSLSocket.class);

okhttp/src/test/java/io/grpc/okhttp/UtilsTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
@RunWith(JUnit4.class)
3838
public class UtilsTest {
3939

40+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4041
@Rule
4142
public final ExpectedException thrown = ExpectedException.none();
4243

protobuf-lite/src/test/java/io/grpc/protobuf/lite/ProtoLiteUtilsTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
@RunWith(JUnit4.class)
5252
public class ProtoLiteUtilsTest {
5353

54+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5455
@Rule public final ExpectedException thrown = ExpectedException.none();
5556

5657
private Marshaller<Type> marshaller = ProtoLiteUtils.marshaller(Type.getDefaultInstance());

testing/src/test/java/io/grpc/testing/GrpcCleanupRuleTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
public class GrpcCleanupRuleTest {
5252
public static final FakeClock fakeClock = new FakeClock();
5353

54+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5455
@Rule
5556
public ExpectedException thrown = ExpectedException.none();
5657

xds/src/test/java/io/grpc/xds/BootstrapperTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
@RunWith(JUnit4.class)
4141
public class BootstrapperTest {
4242

43+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4344
@Rule public ExpectedException thrown = ExpectedException.none();
4445

4546
@Test

xds/src/test/java/io/grpc/xds/PriorityLoadBalancerProviderTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
/** Tests for {@link PriorityLoadBalancerProvider}. */
3535
@RunWith(JUnit4.class)
3636
public class PriorityLoadBalancerProviderTest {
37+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
3738
@Rule public final ExpectedException thrown = ExpectedException.none();
3839

3940
@SuppressWarnings("ExpectedExceptionChecker")

xds/src/test/java/io/grpc/xds/WeightedRandomPickerTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
*/
4343
@RunWith(JUnit4.class)
4444
public class WeightedRandomPickerTest {
45+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4546
@Rule
4647
public final ExpectedException thrown = ExpectedException.none();
4748

xds/src/test/java/io/grpc/xds/XdsClientImplTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public boolean shouldAccept(Runnable command) {
176176

177177
@Rule
178178
public final GrpcCleanupRule cleanupRule = new GrpcCleanupRule();
179+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
179180
@Rule
180181
public ExpectedException thrown = ExpectedException.none();
181182

xds/src/test/java/io/grpc/xds/XdsClientTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*/
3535
@RunWith(JUnit4.class)
3636
public class XdsClientTest {
37+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
3738
@Rule
3839
public final ExpectedException thrown = ExpectedException.none();
3940

xds/src/test/java/io/grpc/xds/internal/rbac/engine/AuthzEngineTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
/** Unit tests for constructor of CEL-based Authorization Engine. */
4545
@RunWith(JUnit4.class)
4646
public class AuthzEngineTest {
47+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4748
@Rule
4849
public final ExpectedException thrown = ExpectedException.none();
4950

0 commit comments

Comments
 (0)